diff --git a/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.AssemblyReference.cache b/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.AssemblyReference.cache index 386888d..c48813d 100644 Binary files a/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.AssemblyReference.cache and b/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.AssemblyReference.cache differ diff --git a/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.CoreCompileInputs.cache b/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.CoreCompileInputs.cache index f8e794a..c13d0ed 100644 --- a/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.CoreCompileInputs.cache +++ b/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -e95e89768799aa70174d795dd6cd51d4394677f14b86bcd305000d17f87ae1d9 +d2b932f18ef2e5c798fd58426e0d24aa6cf31e94f0a9380c5153e4ca9c7312e0 diff --git a/CameraMng/SetConfigForm.vb b/CameraMng/SetConfigForm.vb index 6468385..be7fefe 100644 --- a/CameraMng/SetConfigForm.vb +++ b/CameraMng/SetConfigForm.vb @@ -7,7 +7,11 @@ Public Class SetConfigForm Private myImage As Image Private CurrIndexRow As Integer = 0 - Private CurrAppliedConfig As String = String.Empty + Private CurrAppliedConfig As String = 0 + Private bIsSavedAll As Boolean = True + Private IDConfig As String = String.Empty + Private IDCamera As String = String.Empty + Private IndexCurrentRow As Integer = 0 Sub New() @@ -20,7 +24,16 @@ Public Class SetConfigForm Private Sub LoadWindows() Handles Me.Load PopolateDataGrid() - CurrAppliedConfig = FrmMain.ComboBoxCameraCfg.SelectedItem + CurrAppliedConfig = If(FrmMain.ComboBoxCameraCfg.SelectedItem.Equals("Default"), "0", FrmMain.ComboBoxCameraCfg.SelectedItem) + + ' Deseleziona tutte le righe attualmente selezionate (opzionale ma consigliato) + DataGridView1.ClearSelection() + ' Verifica che la griglia non sia vuota + If DataGridView1.Rows.Count > 0 Then + ' Imposta la cella corrente alla prima cella della prima riga + DataGridView1.CurrentCell = DataGridView1.Rows(CurrAppliedConfig).Cells(0) + DataGridView1.Rows(CurrAppliedConfig).Selected = True + End If End Sub Private Sub PopolateDataGrid() @@ -69,6 +82,19 @@ Public Class SetConfigForm ' Mantengo la selezione sulla riga corrente DataGridView1.Rows(DataGridView1.Rows.Count - 1).Selected = True ' Indico in grassetto il comando Apply + ' Mi assicuro che la cella sia del tipo corretto + If TypeOf riga.Cells(5) Is DataGridViewButtonCell Then + ' Ottiengo la cella specifica + Dim cellaBottone As DataGridViewButtonCell = CType(riga.Cells(5), DataGridViewButtonCell) + ' Recupero il font attuale della cella per non perdere le altre proprietà (come la dimensione) + Dim fontAttuale As Font = cellaBottone.Style.Font + ' Se non è stato impostato un font, usane uno di default per sicurezza + If fontAttuale Is Nothing Then + fontAttuale = Me.DataGridView1.Font ' Usa il font del DataGridView come base + End If + ' Assegno un NUOVO oggetto Font con lo stile Bold + cellaBottone.Style.Font = New Font(fontAttuale, FontStyle.Bold) + End If End If Next End Sub @@ -82,9 +108,8 @@ Public Class SetConfigForm Dim DirToReadCfg As String = FrmMain.sDataRoot Dim NomeFileCfg As String = DirToReadCfg & If(CfgItem = "Default", String.Empty, CfgItem) & "\CameraMng.cfg" ' Creo la nuova riga che sostituirà quella precedente - Dim riga As New DataGridViewRow() + Dim riga As DataGridViewRow = DataGridView1.Rows(IndexRawDataGrid) ' Crea le celle corrispondenti alle colonne - riga.CreateCells(DataGridView1) riga.Cells(0).Value = CfgItem Dim id As String = ReadIdCameraFromCfg(NomeFileCfg) If Not String.IsNullOrEmpty(id) Then @@ -112,7 +137,74 @@ Public Class SetConfigForm DataGridView1.Rows.RemoveAt(IndexRawDataGrid) DataGridView1.Rows.Insert(IndexRawDataGrid, riga) ' Mantengo la selezione sulla riga corrente - DataGridView1.CurrentCell = DataGridView1.Rows(IndexRawDataGrid).Cells(4) + DataGridView1.CurrentCell = riga.Cells(0) + DataGridView1.Rows(IndexRawDataGrid).Selected = True + End Sub + + Private Sub RefreshSelectedItemCfg(IndexRawDataGrid As Integer) + ' 1. RIPRISTINA IL FONT DELLA RIGA PRECEDENTE + ' Controlla se c'era una riga precedente valida e se non è la stessa che stiamo per modificare + If CurrAppliedConfig > -1 AndAlso CurrAppliedConfig <> IndexRawDataGrid Then + ' Assicurati che l'indice sia ancora nel range del DataGridView + If CurrAppliedConfig < DataGridView1.Rows.Count Then + Dim lastRow As DataGridViewRow = DataGridView1.Rows(CurrAppliedConfig) + Dim lastCellButton As DataGridViewButtonCell = CType(lastRow.Cells(5), DataGridViewButtonCell) + Dim lastFont As Font = lastCellButton.Style.Font + ' Crea un nuovo font basato su quello esistente, ma con stile Regular + If lastFont IsNot Nothing Then + lastCellButton.Style.Font = New Font(lastFont, FontStyle.Regular) + End If + End If + End If + + DataGridView1.ClearSelection() + + ' 2. AGGIORNA I DATI DELLA RIGA ESISTENTE + Dim CfgItem As String = DataGridView1.Rows(IndexRawDataGrid).Cells("Config").Value.ToString() + ' Aggiorno lo stato delle icone della lista + Dim DirToReadCfg As String = FrmMain.sDataRoot + Dim NomeFileCfg As String = DirToReadCfg & If(CfgItem = "Default", String.Empty, CfgItem) & "\CameraMng.cfg" + ' Creo la nuova riga che sostituirà quella precedente + Dim riga As DataGridViewRow = DataGridView1.Rows(IndexRawDataGrid) + ' Crea le celle corrispondenti alle colonne + riga.Cells(0).Value = CfgItem + Dim id As String = ReadIdCameraFromCfg(NomeFileCfg) + If Not String.IsNullOrEmpty(id) Then + ' Icone CFG + If CameraListCfg.IndexOf(id) < 0 Then + riga.Cells(1).Value = GetCurrIco(2) + Else + riga.Cells(1).Value = GetCurrIco(0) + End If + ' Icone CAMERA + If ComboCamera.Items.IndexOf(id) > -1 Then + riga.Cells(3).Value = GetCurrIco(2) + riga.Cells(2).Value = id + Else + riga.Cells(3).Value = GetCurrIco(0) + End If + Else + riga.Cells(1).Value = GetCurrIco(-1) + riga.Cells(3).Value = GetCurrIco(-1) + End If + riga.Cells(4).Value = "Save" + riga.Cells(5).Value = "Apply" + + ' 3. APPLICA IL GRASSETTO ALLA RIGA CORRENTE + Dim currentCellButton As DataGridViewButtonCell = CType(riga.Cells(5), DataGridViewButtonCell) + Dim currentFont As Font = currentCellButton.Style.Font + If currentFont Is Nothing Then + currentFont = Me.DataGridView1.Font ' Usa il font del DataGridView come base + End If + ' Assegna un NUOVO oggetto Font con lo stile Bold + currentCellButton.Style.Font = New Font(currentFont, FontStyle.Bold) + + ' 4. AGGIORNA L'INDICE DA RICORDARE + CurrAppliedConfig = IndexRawDataGrid + + ' Mantengo la selezione sulla riga corrente + DataGridView1.CurrentCell = riga.Cells(0) + DataGridView1.Rows(IndexRawDataGrid).Selected = True End Sub Private Function ReadIdCameraFromCfg(NomeFileCfg As String) As String @@ -190,16 +282,47 @@ Public Class SetConfigForm End Try End Sub + Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing + ' Controlla se la cella corrente è nella colonna della ComboBox e se il controllo è una ComboBox + If DataGridView1.CurrentCell.ColumnIndex = DataGridView1.Columns("ComboCamera").Index AndAlso TypeOf e.Control Is ComboBox Then + Dim comboBox As ComboBox = TryCast(e.Control, ComboBox) + If comboBox IsNot Nothing Then + ' Rimuovi eventuali gestori eventi precedenti per evitare eventi duplicati + ' Questo è importante se l'utente modifica più volte la stessa cella + RemoveHandler comboBox.SelectedIndexChanged, AddressOf DataGridViewComboBox_SelectedIndexChanged + ' Aggiungi il gestore eventi per l'evento SelectedIndexChanged della ComboBox + AddHandler comboBox.SelectedIndexChanged, AddressOf DataGridViewComboBox_SelectedIndexChanged + End If + End If + End Sub + + ' Questo è il gestore eventi che si attiverà quando l'utente seleziona un elemento nella ComboBox + Private Sub DataGridViewComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim comboBox As ComboBox = TryCast(sender, ComboBox) + If comboBox IsNot Nothing Then + Dim selectedValue As String = comboBox.SelectedItem.ToString() + Dim currentRowIndex As Integer = DataGridView1.CurrentCell.RowIndex + + Dim IDCamera As String = If(Not IsNothing(DataGridView1.Rows(currentRowIndex).Cells("ComboCamera").Value), DataGridView1.Rows(currentRowIndex).Cells("ComboCamera").Value.ToString(), String.Empty) + + If IDCamera <> selectedValue Then + DataGridView1.Rows(currentRowIndex).Cells(4).Value = "Save*" + End If + + End If + End Sub + ' Tutti i click sulla datagrid passono da qui - Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick + Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick ' Controlla che il click non sia sull'intestazione della colonna If e.RowIndex < 0 Then Return DataGridView1.Rows(e.RowIndex).Selected = True If e.ColumnIndex < 0 Then Return - Dim IDConfig As String = DataGridView1.Rows(e.RowIndex).Cells("Config").Value.ToString() - Dim IDCamera As String = If(Not IsNothing(DataGridView1.Rows(e.RowIndex).Cells("ComboCamera").Value), DataGridView1.Rows(e.RowIndex).Cells("ComboCamera").Value.ToString(), String.Empty) + IndexCurrentRow = e.RowIndex + IDConfig = DataGridView1.Rows(e.RowIndex).Cells("Config").Value.ToString() + IDCamera = If(Not IsNothing(DataGridView1.Rows(e.RowIndex).Cells("ComboCamera").Value), DataGridView1.Rows(e.RowIndex).Cells("ComboCamera").Value.ToString(), String.Empty) ' Controlla se il click è avvenuto nella colonna dei bottoni (Usa il nome che hai dato alla colonna) If Me.DataGridView1.Columns(e.ColumnIndex).Name = "SaveConfig" Then @@ -207,6 +330,7 @@ Public Class SetConfigForm SaveIDCamera(IDConfig, IDCamera) DataGridView1.Rows(e.RowIndex).Cells(4).Value = "Save" RefreshDataGrid(e.RowIndex) + bIsSavedAll = True Else MessageBox.Show("Non è possibile salvare l'ID di una camera non connessa.", "Avviso", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) End If @@ -216,23 +340,47 @@ Public Class SetConfigForm ' verifico che non sia stato salvato l'id indicato If DataGridView1.Rows(e.RowIndex).Cells(4).Value.ToString().Contains("*"c) Then MessageBox.Show("Salvare la configurazione prima di applicarla.", "Informazione", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) + Return End If Dim IndCamera As Integer = FrmMain.ComboBoxCameras.Items.IndexOf(IDCamera) FrmMain.ComboBoxCameras.SelectedIndex = IndCamera Dim IndCameraCfg As Integer = FrmMain.ComboBoxCameraCfg.Items.IndexOf(IDConfig) FrmMain.ComboBoxCameraCfg.SelectedIndex = IndCameraCfg - End If - - ElseIf Me.DataGridView1.Columns(e.ColumnIndex).Name = "ComboCamera" Then - Dim comboBox As ComboBox = TryCast(sender, ComboBox) - If comboBox IsNot Nothing Then - Dim selectedValue As String = comboBox.SelectedItem.ToString() - If IDCamera <> selectedValue Then - DataGridView1.Rows(e.RowIndex).Cells(4).Value = "Save*" - End If - + RefreshSelectedItemCfg(e.RowIndex) End If End If End Sub + Private Sub SetConfig_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing + ' 💡 FORZA LA FINE DELLA MODALITÀ DI MODIFICA + Me.Validate() + Dim result As DialogResult + For IndexRow As Integer = 0 To DataGridView1.Rows.Count - 1 + If DataGridView1.Rows(IndexRow).Cells(4).Value = "Save*" Then + ' Ci sono modifiche. Chiedi all'utente cosa fare. + If bIsSavedAll Then + result = MessageBox.Show("Salvare tutte le configurazioni modificate o no?", "Attenzione", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) + End If + Select Case result + Case DialogResult.Yes + ' Salvataggio + If DataGridView1.Rows(IndexRow).Cells(0).Value = "Default" Then DataGridView1.Rows(IndexRow).Cells(0).Value = String.Empty + SaveIDCamera(DataGridView1.Rows(IndexRow).Cells(0).Value, DataGridView1.Rows(IndexRow).Cells(2).Value) + DataGridView1.Rows(IndexRow).Cells(4).Value = "Save" + RefreshDataGrid(IndexRow) + bIsSavedAll = False + Case DialogResult.No + ' La finestra si chiuderà normalmente. Non fare nulla. + bIsSavedAll = True + Return + Case DialogResult.Cancel + ' L'utente ha annullato l'operazione. Annulla la chiusura della finestra. + bIsSavedAll = True + e.Cancel = True + End Select + End If + Next + bIsSavedAll = True + End Sub + End Class \ No newline at end of file diff --git a/CameraMng/obj/x64/Debug/CameraMng.vbproj.AssemblyReference.cache b/CameraMng/obj/x64/Debug/CameraMng.vbproj.AssemblyReference.cache index aed544b..b128c11 100644 Binary files a/CameraMng/obj/x64/Debug/CameraMng.vbproj.AssemblyReference.cache and b/CameraMng/obj/x64/Debug/CameraMng.vbproj.AssemblyReference.cache differ diff --git a/CameraMng/obj/x64/Debug/CameraMng.vbproj.CoreCompileInputs.cache b/CameraMng/obj/x64/Debug/CameraMng.vbproj.CoreCompileInputs.cache index 9c799eb..7b86e50 100644 --- a/CameraMng/obj/x64/Debug/CameraMng.vbproj.CoreCompileInputs.cache +++ b/CameraMng/obj/x64/Debug/CameraMng.vbproj.CoreCompileInputs.cache @@ -1 +1 @@ -69636ff66d10d465f87b29c6b3440534ee373b52aa51b9726c6ce7a90119bc6f +80ba11b124538c7d3079f30cd12468109ae550e631cf8c94dfc5efc15b795614 diff --git a/CameraMng/obj/x64/Debug/CameraMng.vbproj.FileListAbsolute.txt b/CameraMng/obj/x64/Debug/CameraMng.vbproj.FileListAbsolute.txt index 9fe09fe..ffacf1a 100644 --- a/CameraMng/obj/x64/Debug/CameraMng.vbproj.FileListAbsolute.txt +++ b/CameraMng/obj/x64/Debug/CameraMng.vbproj.FileListAbsolute.txt @@ -48,6 +48,7 @@ C:\EgtDev\cameramanager\CameraMng\bin\x64\Debug\IPadLibrary.dll C:\EgtDev\cameramanager\CameraMng\bin\x64\Debug\IPadLibrary.pdb C:\EgtDev\cameramanager\CameraMng\bin\x64\Debug\IPadLibrary.dll.config C:\EgtDev\cameramanager\CameraMng\obj\x64\Debug\CameraMng.vbproj.Up2Date +C:\EgtDev\cameramanager\CameraMng\obj\x64\Debug\SetConfigForm.resources C:\EgtDev\CameraMng\CameraMng\bin\x64\Debug\CameraMng.exe.config C:\EgtDev\CameraMng\CameraMng\bin\x64\Debug\CameraMng.exe C:\EgtDev\CameraMng\CameraMng\bin\x64\Debug\CameraMng.pdb @@ -74,4 +75,3 @@ C:\EgtDev\CameraMng\CameraMng\obj\x64\Debug\CameraMng.vbproj.Up2Date C:\EgtDev\CameraMng\CameraMng\obj\x64\Debug\CameraMng.exe C:\EgtDev\CameraMng\CameraMng\obj\x64\Debug\CameraMng.xml C:\EgtDev\CameraMng\CameraMng\obj\x64\Debug\CameraMng.pdb -C:\EgtDev\cameramanager\CameraMng\obj\x64\Debug\SetConfigForm.resources diff --git a/CameraMng/obj/x64/Debug/CameraMng.vbproj.GenerateResource.cache b/CameraMng/obj/x64/Debug/CameraMng.vbproj.GenerateResource.cache index 99b945f..393834d 100644 Binary files a/CameraMng/obj/x64/Debug/CameraMng.vbproj.GenerateResource.cache and b/CameraMng/obj/x64/Debug/CameraMng.vbproj.GenerateResource.cache differ