Erweiterung der Validierungslogik und Code-Optimierung

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.
This commit is contained in:
Developer01
2026-08-10 16:09:59 +02:00
parent 46d2a9109b
commit 32fe339d84
2 changed files with 159 additions and 58 deletions

View File

@@ -2750,6 +2750,7 @@ Public Class frmMain
' GRUPPE: Workflow ohne spezifisches Dokument ' GRUPPE: Workflow ohne spezifisches Dokument
CURRENT_JUMP_DOC_GUID = 0 CURRENT_JUMP_DOC_GUID = 0
CURRENT_DOC_GUID = 0 CURRENT_DOC_GUID = 0
CURRENT_DOC_ID = 0
CURRENT_ProfilGUID = CURRENT_CLICKED_PROFILE_ID CURRENT_ProfilGUID = CURRENT_CLICKED_PROFILE_ID
LOGGER.Debug($"Item_Scope: hitInfo.InGroupRow...CURRENT_CLICKED_PROFILE_ID [{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) Load_Profil_from_Grid(CURRENT_CLICKED_PROFILE_ID)

View File

@@ -813,7 +813,8 @@ Public Class frmValidator
Try Try
Dim oSQL As String 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) DatabaseFallback.ExecuteNonQueryECM(oSQL)
Catch ex As Exception Catch ex As Exception
MyValidationLogger.Error(ex) MyValidationLogger.Error(ex)
@@ -5198,8 +5199,8 @@ Public Class frmValidator
oValueFromSource = GetVariableValuefromSource(oSourceIndexName, oIDBTyp, oIDBOverride) oValueFromSource = GetVariableValuefromSource(oSourceIndexName, oIDBTyp, oIDBOverride)
End If End If
If oValueFromSource Is Nothing Then If oValueFromSource Is Nothing Or IsDBNull(oValueFromSource) Then
MyValidationLogger.Debug($"oMyComboBox {oMyCombobox.Name} - Indexvalue from index {oSourceIndexName}: Nothing") MyValidationLogger.Debug($"oMyComboBox {oMyCombobox.Name} - Indexvalue from index {oSourceIndexName} is Nothing or DBNull")
If oDefaultValue = String.Empty Then If oDefaultValue = String.Empty Then
MyValidationLogger.Debug($"oMyComboBox {oMyCombobox.Name}-defaultValue wurde nicht gefunden") MyValidationLogger.Debug($"oMyComboBox {oMyCombobox.Name}-defaultValue wurde nicht gefunden")
oMyCombobox.SelectedIndex = -1 oMyCombobox.SelectedIndex = -1
@@ -6852,7 +6853,7 @@ Public Class frmValidator
Next Next
Return odt Return odt
End Function End Function
Function Check_UpdateIndexe() As Boolean Function Check_UpdateIndexe(Optional ByVal pRegularComplete As Boolean = True) As Boolean
Dim oControlName Dim oControlName
Dim oControlId As String Dim oControlId As String
Try Try
@@ -6864,6 +6865,9 @@ Public Class frmValidator
' ========== ENDE BATCH START ========== ' ========== ENDE BATCH START ==========
' ========== OPTIMIERUNG: Nur geänderte Controls durchlaufen ========== ' ========== OPTIMIERUNG: Nur geänderte Controls durchlaufen ==========
For Each oControl As Control In Me.PanelValidatorControl.Controls 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 Dim oMeta As ClassControlCreator.ControlMetadata = Nothing
Try Try
oMeta = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata) oMeta = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata)
@@ -6940,12 +6944,17 @@ Public Class frmValidator
Try Try
Dim lookup As LookupControl3 = oControl Dim lookup As LookupControl3 = oControl
If lookup.Properties.SelectedValues.Count = 0 And oIsRequired = True Then If lookup.Properties.SelectedValues.Count = 0 And oIsRequired = True Then
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 oMissing = True
oErrMsgMissingInput = $"Kein Auswahl getroffen in LookupGrid '{oControl.Name}'" oErrMsgMissingInput = $"Pflichtfeld: Keine Auswahl getroffen in LookupGrid '{oControl.Name}'"
MyValidationLogger.Warn($"⚠️ Kein Auswahl getroffen in LookupGrid '{oControl.Name}'") MyValidationLogger.Warn($"⚠️ {oErrMsgMissingInput}")
oControl.BackColor = Color.Red oControl.BackColor = Color.Red
frmError.ShowDialog() OpenfrmError(oErrMsgMissingInput)
Exit For Exit For
End If
Else Else
If lookup.Properties.MultiSelect = True Then If lookup.Properties.MultiSelect = True Then
Dim oLookupRows As Integer = lookup.Properties.SelectedValues.Count Dim oLookupRows As Integer = lookup.Properties.SelectedValues.Count
@@ -6997,13 +7006,20 @@ Public Class frmValidator
End If End If
End If End If
Else Else
' Single-Select Lookup ' Single-Select Lookup
oMyInput = lookup.Properties.SelectedValues.FirstOrDefault() oMyInput = lookup.Properties.SelectedValues.FirstOrDefault()
If IsNothing(oMyInput) And oIsRequired = True Then If IsNothing(oMyInput) And oIsRequired = True Then
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 oMissing = True
oErrMsgMissingInput = $"Could not get FirstOrDefault-Value of LookUpGrid! - LookUPGridName: {lookup.Name}" oErrMsgMissingInput = $"Could not get FirstOrDefault-Value of LookUpGrid! - LookUPGridName: {lookup.Name}"
MyValidationLogger.Warn(oErrMsgMissingInput) MyValidationLogger.Warn(oErrMsgMissingInput)
OpenfrmError(oErrMsgMissingInput)
Exit For Exit For
End If
ElseIf IsNothing(oMyInput) And oIsRequired = False Then ElseIf IsNothing(oMyInput) And oIsRequired = False Then
For Each ochangedLookub In listChangedLookup For Each ochangedLookub In listChangedLookup
If lookup.Name = ochangedLookub Then If lookup.Name = ochangedLookub Then
@@ -7135,12 +7151,17 @@ Public Class frmValidator
End If End If
If Check_Missing_Control_Value(oControl, "txt") = True And oIsRequired = True Then If Check_Missing_Control_Value(oControl, "txt") = True And oIsRequired = True Then
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 oMissing = True
oErrMsgMissingInput = oWrongInputMessage & " textbox '" & oControl.Name & "'" oErrMsgMissingInput = oWrongInputMessage & " textbox '" & oControl.Name & "'"
MyValidationLogger.Warn(oErrMsgMissingInput) MyValidationLogger.Warn(oErrMsgMissingInput)
oControl.BackColor = Color.Red oControl.BackColor = Color.Red
frmError.ShowDialog() frmError.ShowDialog()
Exit For Exit For
End If
Else Else
MyValidationLogger.Debug("Reading current value from Textbox") MyValidationLogger.Debug("Reading current value from Textbox")
Dim oTextEdit As BaseEdit = DirectCast(oControl, BaseEdit) Dim oTextEdit As BaseEdit = DirectCast(oControl, BaseEdit)
@@ -7265,6 +7286,10 @@ Public Class frmValidator
MyValidationLogger.Debug($"Working on Combobox...") MyValidationLogger.Debug($"Working on Combobox...")
Dim cmb As Windows.Forms.ComboBox = oControl Dim cmb As Windows.Forms.ComboBox = oControl
If cmb.SelectedIndex = -1 And oIsRequired = True Then If cmb.SelectedIndex = -1 And oIsRequired = True Then
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 oMissing = True
oErrMsgMissingInput = "Please Choose an entry out of ComboBox '" & cmb.Name & "'" oErrMsgMissingInput = "Please Choose an entry out of ComboBox '" & cmb.Name & "'"
MyValidationLogger.Warn(oErrMsgMissingInput) MyValidationLogger.Warn(oErrMsgMissingInput)
@@ -7274,6 +7299,7 @@ Public Class frmValidator
End If End If
OpenfrmError(oErrMsgMissingInput) OpenfrmError(oErrMsgMissingInput)
Exit For Exit For
End If
Else Else
oMyInput = cmb.Text oMyInput = cmb.Text
MyValidationLogger.Debug($"inputvalue Combobox: {cmb.Text}") MyValidationLogger.Debug($"inputvalue Combobox: {cmb.Text}")
@@ -7400,6 +7426,10 @@ Public Class frmValidator
Try Try
Dim dtp As DateTimePicker = oControl Dim dtp As DateTimePicker = oControl
If oIsRequired = True And dtp.Value.ToString = String.Empty Then If oIsRequired = True And dtp.Value.ToString = String.Empty Then
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 oMissing = True
oErrMsgMissingInput = "Please Choose DateValue for field'" & dtp.Name & "'" oErrMsgMissingInput = "Please Choose DateValue for field'" & dtp.Name & "'"
MyValidationLogger.Warn(oErrMsgMissingInput) MyValidationLogger.Warn(oErrMsgMissingInput)
@@ -7409,6 +7439,7 @@ Public Class frmValidator
End If End If
OpenfrmError(oErrMsgMissingInput) OpenfrmError(oErrMsgMissingInput)
Exit For Exit For
End If
ElseIf dtp.Value.ToString <> "01.01.0001 00:00:00" Then ElseIf dtp.Value.ToString <> "01.01.0001 00:00:00" Then
oMyInput = CDate(dtp.Value) oMyInput = CDate(dtp.Value)
Dim oObjectValue Dim oObjectValue
@@ -7496,6 +7527,10 @@ Public Class frmValidator
oMyInput = chk.Checked.ToString oMyInput = chk.Checked.ToString
If chk.CheckState = CheckState.Indeterminate And oIsRequired = True Then If chk.CheckState = CheckState.Indeterminate And oIsRequired = True Then
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 oMissing = True
oErrMsgMissingInput = "Please set Checkbox value for field '" & chk.Name & "'" oErrMsgMissingInput = "Please set Checkbox value for field '" & chk.Name & "'"
MyValidationLogger.Warn(oErrMsgMissingInput) MyValidationLogger.Warn(oErrMsgMissingInput)
@@ -7506,6 +7541,7 @@ Public Class frmValidator
OpenfrmError(oErrMsgMissingInput) OpenfrmError(oErrMsgMissingInput)
Exit For Exit For
End If End If
End If
Dim WertWD As String Dim WertWD As String
Dim oBoolValue As Boolean Dim oBoolValue As Boolean
@@ -7614,6 +7650,10 @@ Public Class frmValidator
End If End If
Next Next
If oIsRequired = True And Zeilen = 0 Then If oIsRequired = True And Zeilen = 0 Then
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 oMissing = True
oErrMsgMissingInput = "Fehlende Eingabe in Vektorfeld '" & dgv.Name & "'" oErrMsgMissingInput = "Fehlende Eingabe in Vektorfeld '" & dgv.Name & "'"
MyValidationLogger.Warn(oErrMsgMissingInput) MyValidationLogger.Warn(oErrMsgMissingInput)
@@ -7623,6 +7663,7 @@ Public Class frmValidator
End If End If
OpenfrmError(oErrMsgMissingInput) OpenfrmError(oErrMsgMissingInput)
Exit For Exit For
End If
ElseIf Zeilen > 0 Then ElseIf Zeilen > 0 Then
Dim ZeilenGrid As Integer = 0 Dim ZeilenGrid As Integer = 0
Dim myVektorArr As String() Dim myVektorArr As String()
@@ -7717,6 +7758,65 @@ Public Class frmValidator
Next ' End For Each oControl 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 ========== ' ========== BATCH: Gesammelte Statements abfeuern ==========
If IDB_ACTIVE Then If IDB_ACTIVE Then
If oMissing = False Then If oMissing = False Then