From f4e382d93ae3c07412755d180ab1e81a8c64ca4d Mon Sep 17 00:00:00 2001 From: Demetrio Cassarino Date: Wed, 30 Jul 2025 16:56:29 +0200 Subject: [PATCH] -Gestione chiusura form setconfig --- ...harpLibrary.csproj.AssemblyReference.cache | Bin 1047 -> 3968 bytes ...harpLibrary.csproj.CoreCompileInputs.cache | 2 +- CameraMng/SetConfigForm.vb | 184 ++++++++++++++++-- .../CameraMng.vbproj.AssemblyReference.cache | Bin 7768 -> 7744 bytes .../CameraMng.vbproj.CoreCompileInputs.cache | 2 +- .../CameraMng.vbproj.FileListAbsolute.txt | 2 +- .../CameraMng.vbproj.GenerateResource.cache | Bin 1488 -> 1488 bytes 7 files changed, 169 insertions(+), 21 deletions(-) diff --git a/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.AssemblyReference.cache b/CSharpLibrary/obj/x64/Debug/CSharpLibrary.csproj.AssemblyReference.cache index 386888dd793ec3782eeda56639791f4559702a78..c48813de03c9c967221fef74dfefab5ec5348c94 100644 GIT binary patch literal 3968 zcmd5;O>fgc5cTj8l^{T+Tzbn9BxDt}LeN7|l{PmjR96KdqiW+$!m8`tuxmG@m!7%v zL%8uLxN`4L!RxMzT>E0}t`r|4*|FY^-@G^Tdax1%0h|oC;}23yB}oS(%1{lSe}D7( zMSO@8l*kht>?(!nm{C;mdzwh0#3YMH#rrrH@+=My_K*JGoo|I3ajFs_86AhGi~$s< z1Zz8=uYUe15A5q#!p)7%S8oIO;^FjYp)yRHXTx3ny#Om!d2mmc)^fq6d05sSltlf$ zh>zE|u6~sN6e!QkF+;&8bec<&QNcSQ{(5(Ex%#)iT_N@j;-{2#!l_rL(V)ih*dNDx zBqJ?EKhQO}BD!}?iv=YBt2e?8kEzND8$!RNz4_DDdq155STh|zl7uUgXay;&?|fna z5AqZxP3*wd4cI=JT!$4g+vSbv=-{l`RdU*IAdawBF|d< z)6ngCuJ z?;qwoqbY{PuA_v}i!#@h1CM0I9#ml@$jo9g6k(*AGB+#00 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 aed544b6ef4bc24a252af5afeeafed2ff8c14a80..b128c11ac83c47d565eb0daa2225b66a22d42803 100644 GIT binary patch delta 243 zcmca%bHGNLjggOmfq~K9*(%00y~HK8EXFx8H?=6yH!ppnydm4fqTZT<^Ap1?WZcs- zb5gDJ_4S>t^dTzs;VL(-3t$#8$6~}}c@Al@@cg2j6up$397aZ@edjILs6r2pBiHpGA7}QjXc802Rqvu>b%7 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 99b945fb5d064edb05efba5cf64f56edac8932e1..393834d1393baf0c273b06ae09575296a2f237a9 100644 GIT binary patch delta 72 zcmcb>eSv#|Hv88Dx~n&AzdOeSv#|HakOv{Cz3*D-(?_vxemb*Wj9AN>aegf ZodQYru$uCJt=_Tc$ho^5jEoE*005IF7)SsB