From 32fe339d84fd33022672420c7641f0a1599f6b51 Mon Sep 17 00:00:00 2001 From: Developer01 Date: Mon, 10 Aug 2026 16:09:59 +0200 Subject: [PATCH] Erweiterung der Validierungslogik und Code-Optimierung MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Die Änderungen umfassen: - Hinzufügen der Variablen `CURRENT_DOC_ID` in `frmMain.vb`. - Erweiterung der SQL-Löschlogik um zusätzliche Tabellen. - Verbesserung der Nullprüfung (`Nothing` und `DBNull`). - Einführung des optionalen Parameters `pRegularComplete` in `Check_UpdateIndexe`. - Überspringen spezifischer Steuerelemente (`BTNDYN_GRID`) in Schleifen. - Anpassung der Pflichtfeldvalidierung für mehrere Steuerelementtypen. - Vereinheitlichung der Fehlermeldungsanzeige mit `OpenfrmError`. - Verarbeitung von separaten Grids aus `_separateGridControlCache`. - Refactoring der `ControlSettings`-Initialisierung für bessere Lesbarkeit. - Sicherstellung der Batch-Verarbeitung bei Änderungen. - Verbesserte Debug- und Warnmeldungen für bessere Nachvollziehbarkeit. - Allgemeine Code-Optimierungen zur Steigerung der Wartbarkeit. --- app/TaskFlow/frmMain.vb | 1 + app/TaskFlow/frmValidator.vb | 216 +++++++++++++++++++++++++---------- 2 files changed, 159 insertions(+), 58 deletions(-) diff --git a/app/TaskFlow/frmMain.vb b/app/TaskFlow/frmMain.vb index 298b76a..e5fea63 100644 --- a/app/TaskFlow/frmMain.vb +++ b/app/TaskFlow/frmMain.vb @@ -2750,6 +2750,7 @@ Public Class frmMain ' GRUPPE: Workflow ohne spezifisches Dokument CURRENT_JUMP_DOC_GUID = 0 CURRENT_DOC_GUID = 0 + CURRENT_DOC_ID = 0 CURRENT_ProfilGUID = CURRENT_CLICKED_PROFILE_ID LOGGER.Debug($"Item_Scope: hitInfo.InGroupRow...CURRENT_CLICKED_PROFILE_ID [{CURRENT_CLICKED_PROFILE_ID}]") Load_Profil_from_Grid(CURRENT_CLICKED_PROFILE_ID) diff --git a/app/TaskFlow/frmValidator.vb b/app/TaskFlow/frmValidator.vb index 92c9a99..61af4b4 100644 --- a/app/TaskFlow/frmValidator.vb +++ b/app/TaskFlow/frmValidator.vb @@ -813,7 +813,8 @@ Public Class frmValidator Try Dim oSQL As String - oSQL = $"DELETE FROM TBPM_DOCWALKOVER WHERE UserID = {USER_ID};" + oSQL = $"DELETE FROM TBPM_DOCWALKOVER WHERE UserID = {USER_ID};" & vbCrLf & + $"DELETE FROM TBPM_VALIDATION_PROFILE_GROUP_USER WHERE UserID = {USER_ID};" DatabaseFallback.ExecuteNonQueryECM(oSQL) Catch ex As Exception MyValidationLogger.Error(ex) @@ -5198,8 +5199,8 @@ Public Class frmValidator oValueFromSource = GetVariableValuefromSource(oSourceIndexName, oIDBTyp, oIDBOverride) End If - If oValueFromSource Is Nothing Then - MyValidationLogger.Debug($"oMyComboBox {oMyCombobox.Name} - Indexvalue from index {oSourceIndexName}: Nothing") + If oValueFromSource Is Nothing Or IsDBNull(oValueFromSource) Then + MyValidationLogger.Debug($"oMyComboBox {oMyCombobox.Name} - Indexvalue from index {oSourceIndexName} is Nothing or DBNull") If oDefaultValue = String.Empty Then MyValidationLogger.Debug($"oMyComboBox {oMyCombobox.Name}-defaultValue wurde nicht gefunden") oMyCombobox.SelectedIndex = -1 @@ -6852,7 +6853,7 @@ Public Class frmValidator Next Return odt End Function - Function Check_UpdateIndexe() As Boolean + Function Check_UpdateIndexe(Optional ByVal pRegularComplete As Boolean = True) As Boolean Dim oControlName Dim oControlId As String Try @@ -6864,6 +6865,9 @@ Public Class frmValidator ' ========== ENDE BATCH START ========== ' ========== OPTIMIERUNG: Nur geänderte Controls durchlaufen ========== For Each oControl As Control In Me.PanelValidatorControl.Controls + If oControl.Name.StartsWith("BTNDYN_GRID") Then + Continue For + End If Dim oMeta As ClassControlCreator.ControlMetadata = Nothing Try oMeta = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata) @@ -6940,12 +6944,17 @@ Public Class frmValidator Try Dim lookup As LookupControl3 = oControl If lookup.Properties.SelectedValues.Count = 0 And oIsRequired = True Then - oMissing = True - oErrMsgMissingInput = $"Kein Auswahl getroffen in LookupGrid '{oControl.Name}'" - MyValidationLogger.Warn($"⚠️ Kein Auswahl getroffen in LookupGrid '{oControl.Name}'") - oControl.BackColor = Color.Red - frmError.ShowDialog() - Exit For + If pRegularComplete = False Then + MyValidationLogger.Debug($"[CHECK_UPDATE] LookupGrid '{oControl.Name}' is required but has no selection. Skipping due to pRegularComplete=False.") + Continue For + Else + oMissing = True + oErrMsgMissingInput = $"Pflichtfeld: Keine Auswahl getroffen in LookupGrid '{oControl.Name}'" + MyValidationLogger.Warn($"⚠️ {oErrMsgMissingInput}") + oControl.BackColor = Color.Red + OpenfrmError(oErrMsgMissingInput) + Exit For + End If Else If lookup.Properties.MultiSelect = True Then Dim oLookupRows As Integer = lookup.Properties.SelectedValues.Count @@ -6997,13 +7006,20 @@ Public Class frmValidator End If End If Else + ' Single-Select Lookup oMyInput = lookup.Properties.SelectedValues.FirstOrDefault() If IsNothing(oMyInput) And oIsRequired = True Then - oMissing = True - oErrMsgMissingInput = $"Could not get FirstOrDefault-Value of LookUpGrid! - LookUPGridName: {lookup.Name}" - MyValidationLogger.Warn(oErrMsgMissingInput) - Exit For + If pRegularComplete = False Then + MyValidationLogger.Debug($"[CHECK_UPDATE] LookupGrid(SingleSelect) '{lookup.Name}' is required but has no selection. Skipping due to pRegularComplete=False.") + Continue For + Else + oMissing = True + oErrMsgMissingInput = $"Could not get FirstOrDefault-Value of LookUpGrid! - LookUPGridName: {lookup.Name}" + MyValidationLogger.Warn(oErrMsgMissingInput) + OpenfrmError(oErrMsgMissingInput) + Exit For + End If ElseIf IsNothing(oMyInput) And oIsRequired = False Then For Each ochangedLookub In listChangedLookup If lookup.Name = ochangedLookub Then @@ -7135,12 +7151,17 @@ Public Class frmValidator End If If Check_Missing_Control_Value(oControl, "txt") = True And oIsRequired = True Then - oMissing = True - oErrMsgMissingInput = oWrongInputMessage & " textbox '" & oControl.Name & "'" - MyValidationLogger.Warn(oErrMsgMissingInput) - oControl.BackColor = Color.Red - frmError.ShowDialog() - Exit For + If pRegularComplete = False Then + MyValidationLogger.Debug($"[CHECK_UPDATE] TextEdit '{oControl.Name}' is required but has no selection. Skipping due to pRegularComplete=False.") + Continue For + Else + oMissing = True + oErrMsgMissingInput = oWrongInputMessage & " textbox '" & oControl.Name & "'" + MyValidationLogger.Warn(oErrMsgMissingInput) + oControl.BackColor = Color.Red + frmError.ShowDialog() + Exit For + End If Else MyValidationLogger.Debug("Reading current value from Textbox") Dim oTextEdit As BaseEdit = DirectCast(oControl, BaseEdit) @@ -7265,15 +7286,20 @@ Public Class frmValidator MyValidationLogger.Debug($"Working on Combobox...") Dim cmb As Windows.Forms.ComboBox = oControl If cmb.SelectedIndex = -1 And oIsRequired = True Then - oMissing = True - oErrMsgMissingInput = "Please Choose an entry out of ComboBox '" & cmb.Name & "'" - MyValidationLogger.Warn(oErrMsgMissingInput) - If _FormClosing Then - MyValidationLogger.Warn("Form closing - skip error dialog") - Return False + If pRegularComplete = False Then + MyValidationLogger.Debug($"[CHECK_UPDATE] ComboBox '{cmb.Name}' is required but has no selection. Skipping due to pRegularComplete=False.") + Continue For + Else + oMissing = True + oErrMsgMissingInput = "Please Choose an entry out of ComboBox '" & cmb.Name & "'" + MyValidationLogger.Warn(oErrMsgMissingInput) + If _FormClosing Then + MyValidationLogger.Warn("Form closing - skip error dialog") + Return False + End If + OpenfrmError(oErrMsgMissingInput) + Exit For End If - OpenfrmError(oErrMsgMissingInput) - Exit For Else oMyInput = cmb.Text MyValidationLogger.Debug($"inputvalue Combobox: {cmb.Text}") @@ -7400,15 +7426,20 @@ Public Class frmValidator Try Dim dtp As DateTimePicker = oControl If oIsRequired = True And dtp.Value.ToString = String.Empty Then - oMissing = True - oErrMsgMissingInput = "Please Choose DateValue for field'" & dtp.Name & "'" - MyValidationLogger.Warn(oErrMsgMissingInput) - If _FormClosing Then - MyValidationLogger.Warn("Form closing - skip error dialog") - Return False + If pRegularComplete = False Then + MyValidationLogger.Debug($"[CHECK_UPDATE] DateTimePicker '{dtp.Name}' is required but has no selection. Skipping due to pRegularComplete=False.") + Continue For + Else + oMissing = True + oErrMsgMissingInput = "Please Choose DateValue for field'" & dtp.Name & "'" + MyValidationLogger.Warn(oErrMsgMissingInput) + If _FormClosing Then + MyValidationLogger.Warn("Form closing - skip error dialog") + Return False + End If + OpenfrmError(oErrMsgMissingInput) + Exit For End If - OpenfrmError(oErrMsgMissingInput) - Exit For ElseIf dtp.Value.ToString <> "01.01.0001 00:00:00" Then oMyInput = CDate(dtp.Value) Dim oObjectValue @@ -7496,15 +7527,20 @@ Public Class frmValidator oMyInput = chk.Checked.ToString If chk.CheckState = CheckState.Indeterminate And oIsRequired = True Then - oMissing = True - oErrMsgMissingInput = "Please set Checkbox value for field '" & chk.Name & "'" - MyValidationLogger.Warn(oErrMsgMissingInput) - If _FormClosing Then - MyValidationLogger.Warn("Form closing - skip error dialog") - Return False + If pRegularComplete = False Then + MyValidationLogger.Debug($"[CHECK_UPDATE] CheckBox '{chk.Name}' is required but has no selection. Skipping due to pRegularComplete=False.") + Continue For + Else + oMissing = True + oErrMsgMissingInput = "Please set Checkbox value for field '" & chk.Name & "'" + MyValidationLogger.Warn(oErrMsgMissingInput) + If _FormClosing Then + MyValidationLogger.Warn("Form closing - skip error dialog") + Return False + End If + OpenfrmError(oErrMsgMissingInput) + Exit For End If - OpenfrmError(oErrMsgMissingInput) - Exit For End If Dim WertWD As String @@ -7614,15 +7650,20 @@ Public Class frmValidator End If Next If oIsRequired = True And Zeilen = 0 Then - oMissing = True - oErrMsgMissingInput = "Fehlende Eingabe in Vektorfeld '" & dgv.Name & "'" - MyValidationLogger.Warn(oErrMsgMissingInput) - If _FormClosing Then - MyValidationLogger.Warn("Form closing - skip error dialog") - Return False + If pRegularComplete = False Then + MyValidationLogger.Debug($"[CHECK_UPDATE] DataGridView '{dgv.Name}' is required but has no selection. Skipping due to pRegularComplete=False.") + Continue For + Else + oMissing = True + oErrMsgMissingInput = "Fehlende Eingabe in Vektorfeld '" & dgv.Name & "'" + MyValidationLogger.Warn(oErrMsgMissingInput) + If _FormClosing Then + MyValidationLogger.Warn("Form closing - skip error dialog") + Return False + End If + OpenfrmError(oErrMsgMissingInput) + Exit For End If - OpenfrmError(oErrMsgMissingInput) - Exit For ElseIf Zeilen > 0 Then Dim ZeilenGrid As Integer = 0 Dim myVektorArr As String() @@ -7694,12 +7735,12 @@ Public Class frmValidator CleanupDeletedRows(oGrid) Dim oSettings = New ControlSettings() With { - .IndexName = oIndexName, - .ControlType = GetType(GridControl).ToString, - .Name = oControlName, - .IsRequired = oIsRequired, - .IDBAttributeType = oIDBTyp - } + .IndexName = oIndexName, + .ControlType = GetType(GridControl).ToString, + .Name = oControlName, + .IsRequired = oIsRequired, + .IDBAttributeType = oIDBTyp + } Dim oGridColumnDefinition As DataTable = DT_COLUMNS_GRID.Clone() Dim oExpression = $"CONTROL_ID = {oControlRow.Item("GUID")}" DT_COLUMNS_GRID.Select(oExpression, "SEQUENCE").CopyToDataTable(oGridColumnDefinition, LoadOption.PreserveChanges) @@ -7717,6 +7758,65 @@ Public Class frmValidator Next ' End For Each oControl + ' ========== TEIL 2: Separate Grids aus Cache verarbeiten ========== + ' Nach dem Ende der "For Each oControl As Control In Me.PanelValidatorControl.Controls" Schleife + + If _separateGridControlCache.Count > 0 Then + MyValidationLogger?.Debug($"Verarbeite {_separateGridControlCache.Count} separate Grid(s) aus Cache") + + For Each kvp As KeyValuePair(Of String, GridControl) In _separateGridControlCache + Dim controlName As String = kvp.Key + Dim oGrid As GridControl = kvp.Value + + ' Nur verarbeiten, wenn Control als "dirty" markiert ist + If Not listofControls.Contains(controlName) Then + MyValidationLogger?.Debug($"Separate Grid '{controlName}' wurde nicht geändert - überspringe") + Continue For + End If + + MyValidationLogger?.Debug($"[4] Separates GridControl verarbeiten: [{controlName}]") + + ' Control-Metadaten holen (EXAKT wie bei normalem Grid) + Dim oControlRow As DataRow = GetControlMetaBySql($"NAME='{controlName}'").Rows(0) + Dim oGUID = oControlRow("GUID") + Dim oControlRow1 = (From form In DTVWCONTROL_INDEX.AsEnumerable() + Where form.Item("GUID") = oGUID).SingleOrDefault() + Dim oIndexName As String = If(IsDBNull(oControlRow1("INDEX_NAME")), "", oControlRow1("INDEX_NAME").ToString()) + Dim oIsRequired As Boolean = True + Dim oIDBTyp As Integer = If(IsDBNull(oControlRow1("IDB_TYP")), 0, CInt(oControlRow1("IDB_TYP"))) + + ' Cleanup (wie bei normalem Grid) + CleanupDeletedRows(oGrid) + + ' Settings erstellen (EXAKT wie bei normalem Grid) + Dim oSettings = New ControlSettings() With { + .IndexName = oIndexName, + .ControlType = GetType(GridControl).ToString, + .Name = controlName, + .IsRequired = oIsRequired, + .IDBAttributeType = oIDBTyp + } + + ' Spalten-Definition holen (EXAKT wie bei normalem Grid) + Dim oGridColumnDefinition As DataTable = DT_COLUMNS_GRID.Clone() + Dim oExpression = $"CONTROL_ID = {oGUID}" + Dim selectedRows() As DataRow = DT_COLUMNS_GRID.Select(oExpression, "SEQUENCE") + + If selectedRows.Length > 0 Then + selectedRows.CopyToDataTable(oGridColumnDefinition, LoadOption.PreserveChanges) + End If + + ' WICHTIG: DEINE BESTEHENDE ValidateGridControl Funktion verwenden! + Dim oResult = ValidateGridControl(oGrid, oSettings, oGridColumnDefinition, oMissing, oErrMsgMissingInput) + + If oResult = False Then + MyValidationLogger?.Warn($"⚠️ Validierung fehlgeschlagen für separates Grid [{controlName}] → Exit For") + Exit For + End If + Next + End If + + ' ========== BATCH: Gesammelte Statements abfeuern ========== If IDB_ACTIVE Then If oMissing = False Then