From 2fd4e817a7e6afd2f5ff14f82bec977c46452196 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 9 Mar 2021 13:24:44 +0100 Subject: [PATCH] WIP Validation for Grids --- app/DD_PM_WINDREAM/ClassControlCreator.vb | 86 ++++++++++++----------- app/DD_PM_WINDREAM/DD_PM_WINDREAM.vbproj | 3 + app/DD_PM_WINDREAM/frmValidator.vb | 54 +++++++++----- 3 files changed, 84 insertions(+), 59 deletions(-) diff --git a/app/DD_PM_WINDREAM/ClassControlCreator.vb b/app/DD_PM_WINDREAM/ClassControlCreator.vb index 3802867..941d48e 100644 --- a/app/DD_PM_WINDREAM/ClassControlCreator.vb +++ b/app/DD_PM_WINDREAM/ClassControlCreator.vb @@ -37,7 +37,7 @@ Public Class ClassControlCreator Public Const PREFIX_LINE = "LINE" Public Const PREFIX_BUTTON = "BTN" - Public Shared GridTables As New Dictionary(Of String, DataTable) + Public Shared GridTables As New Dictionary(Of String, Dictionary(Of String, DataTable)) ''' ''' Standard Eigenschaften für alle Controls @@ -106,6 +106,7 @@ Public Class ClassControlCreator Return ctrl Catch ex As Exception LOGGER.Error(ex) + Return Nothing End Try End Function @@ -449,7 +450,11 @@ Public Class ClassControlCreator End With - GridTables.Clear() + If GridTables.ContainsKey(oControl.Name) Then + GridTables.Item(oControl.Name).Clear() + Else + GridTables.Add(oControl.Name, New Dictionary(Of String, DataTable)()) + End If For Each oRow As DataRow In DT_MY_COLUMNS.Rows ' Create Columns in Datatable @@ -471,7 +476,9 @@ Public Class ClassControlCreator If oConnectionId > 0 And oSqlCommand <> "" Then Try Dim oComboboxDataTable As DataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId) - GridTables.Add(oRow.Item("SPALTENNAME"), oComboboxDataTable) + + GridTables.Item(oControl.Name).Add(oRow.Item("SPALTENNAME"), oComboboxDataTable) + 'GridTables.Add(oRow.Item("SPALTENNAME"), oComboboxDataTable) Catch ex As Exception LOGGER.Warn("Could not load data for column {0} in control {1}", oRow.Item("SPALTENNAME"), oControl.Name) LOGGER.Error(ex) @@ -488,20 +495,18 @@ Public Class ClassControlCreator oControl.RefreshDataSource() oControl.ForceInitialize() - - AddHandler oView.CellValueChanged, AddressOf HandleCellValueChanged AddHandler oView.CustomRowCellEdit, Sub(sender As Object, e As CustomRowCellEditEventArgs) For Each oRow As DataRow In DT_MY_COLUMNS.Rows If oRow.Item("SPALTENNAME") = e.Column.FieldName Then - If GridTables.ContainsKey(e.Column.FieldName) Then - Dim oComboboxDataTable As DataTable = GridTables.Item(e.Column.FieldName) + If GridTables.Item(oControl.Name).ContainsKey(e.Column.FieldName) Then + Dim oComboboxDataTable As DataTable = GridTables.Item(oControl.Name).Item(e.Column.FieldName) If oRow.Item("ADVANCED_LOOKUP") Then - Dim oEditor = New RepositoryItemLookupControl3() - - oEditor.DataSource = oComboboxDataTable - oEditor.DisplayMember = oComboboxDataTable.Columns.Item(0).ColumnName - oEditor.ValueMember = oComboboxDataTable.Columns.Item(0).ColumnName + Dim oEditor = New RepositoryItemLookupControl3 With { + .DataSource = oComboboxDataTable, + .DisplayMember = oComboboxDataTable.Columns.Item(0).ColumnName, + .ValueMember = oComboboxDataTable.Columns.Item(0).ColumnName + } e.RepositoryItem = oEditor Else @@ -534,41 +539,40 @@ Public Class ClassControlCreator End If Next End Sub + + AddHandler oView.CellValueChanged, Sub(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) + Console.WriteLine("") + End Sub + AddHandler oView.ValidateRow, Sub(sender As Object, e As ValidateRowEventArgs) - Dim oRow As DataRowView = DirectCast(e.Row, DataRowView) - For Each oCol As DataColumn In oRow.DataView.Table.Columns - Dim oColumn As DataRow = (From r As DataRow In DT_MY_COLUMNS.Rows - Where r.Item("SPALTENNAME") = oCol.ColumnName - Select r).FirstOrDefault() - - Dim oIsRequired = oColumn.Item("VALIDATION") - Dim oValue = oRow.Item(oCol.ColumnName) - - If oIsRequired And (oValue Is Nothing OrElse oValue.ToString = "") Then - e.Valid = False - e.ErrorText = $"Spalte {oColumn.Item("SPALTEN_HEADER")} muss ausgefüllt werden!" - Exit For - End If - Next + Console.WriteLine("") End Sub - Return oControl - End Function + AddHandler oView.ValidatingEditor, Sub(sender As Object, e As BaseContainerValidateEditorEventArgs) + Dim oRow As DataRowView = oView.GetRow(oView.FocusedRowHandle) - Public Shared Function HandleCellValueChanged(sender As Object, e As CellValueChangedEventArgs) - ' TODO: Do the validation - Dim oCurrentView As GridView = DirectCast(sender, GridView) - Dim oCurrentControl As GridControl = oCurrentView.GridControl - Dim oCurrentDatasource As DataTable = oCurrentControl.DataSource - Dim oColumn = oCurrentDatasource.Columns.Item(e.Column.FieldName) + For Each oCol As DataColumn In oRow.DataView.Table.Columns + Dim oColumn As DataRow = (From r As DataRow In DT_MY_COLUMNS.Rows + Where r.Item("SPALTENNAME") = oCol.ColumnName + Select r).FirstOrDefault() - Dim oValue = e.Value.ToString() - Dim oView2 As GridView = TryCast(sender, GridView) + Dim oIsRequired = oColumn.Item("VALIDATION") + Dim oValue As String = NotNull(e.Value, "") - If oValue.Contains(" | ") Then - oValue = oValue.Split(" | ").ToList().Item(0) - oView2.SetRowCellValue(e.RowHandle, e.Column, oValue) - End If + If oValue.contains(" | ") Then + oValue = oValue.Split(" | ").ToList().First() + e.Value = oValue + End If + + If oIsRequired And oValue = "" Then + e.Valid = False + e.ErrorText = $"Spalte {oColumn.Item("SPALTEN_HEADER")} muss ausgefüllt werden!" + Exit For + End If + Next + End Sub + + Return oControl End Function Public Shared Function CreateExistingLine(row As DataRow, designMode As Boolean) As LineLabel diff --git a/app/DD_PM_WINDREAM/DD_PM_WINDREAM.vbproj b/app/DD_PM_WINDREAM/DD_PM_WINDREAM.vbproj index 19204fb..29ce459 100644 --- a/app/DD_PM_WINDREAM/DD_PM_WINDREAM.vbproj +++ b/app/DD_PM_WINDREAM/DD_PM_WINDREAM.vbproj @@ -165,6 +165,9 @@ ..\..\..\DDMonorepo\Modules.EDMIAPI\bin\Debug\DigitalData.Modules.EDMI.API.dll + + ..\..\..\DDMonorepo\Modules.Language\bin\Debug\DigitalData.Modules.Language.dll + ..\..\..\DDMonorepo\Modules.Logging\bin\Debug\DigitalData.Modules.Logging.dll diff --git a/app/DD_PM_WINDREAM/frmValidator.vb b/app/DD_PM_WINDREAM/frmValidator.vb index a64e078..4e427f3 100644 --- a/app/DD_PM_WINDREAM/frmValidator.vb +++ b/app/DD_PM_WINDREAM/frmValidator.vb @@ -13,6 +13,7 @@ Imports DigitalData.Controls.ChatControl Imports DevExpress.XtraEditors.Repository Imports DigitalData.Modules.EDMI.API Imports DigitalData.Modules.EDMI.API.EDMIServiceReference +Imports DevExpress.XtraGrid.Views.Grid Public Class frmValidator Dim strFileList() @@ -358,9 +359,9 @@ Public Class frmValidator RibbonPageGroupConv_Change.Visible = False End If RepositoryItemComboBox3.Items.Clear() - Dim oActiveConv As Boolean = False - RibbonPageGroupConv_Change.Visible = True - For Each oconv As String In oConversations + Dim oActiveConv As Boolean = False + RibbonPageGroupConv_Change.Visible = True + For Each oconv As String In oConversations If Not oconv.Contains("Started") Then RepositoryItemComboBox3.Items.Add(oconv) End If @@ -369,16 +370,16 @@ Public Class frmValidator End If Next - If oActiveConv = False Then - btnitemConversationEnd.Enabled = False - btnitemConversation_reload.Enabled = False - SplitContainer2_DV_Chat.Collapsed = True - Else - If SplitContainer2_DV_Chat.Panel2.Visible = False Then - SplitContainer2_DV_Chat.Panel2.Visible = True - End If - SplitContainer2_DV_Chat.Collapsed = False + If oActiveConv = False Then + btnitemConversationEnd.Enabled = False + btnitemConversation_reload.Enabled = False + SplitContainer2_DV_Chat.Collapsed = True + Else + If SplitContainer2_DV_Chat.Panel2.Visible = False Then + SplitContainer2_DV_Chat.Panel2.Visible = True End If + SplitContainer2_DV_Chat.Collapsed = False + End If End Sub Private Sub frmValidation_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing @@ -398,7 +399,7 @@ Public Class frmValidator If INACTIVITY_DURATION <> 0 Then frmMain.Check_Timer_Inactivity() Try - _frmValidatorSearch.Close() + _frmValidatorSearch.Close() Catch ex As Exception End Try @@ -1969,7 +1970,7 @@ Public Class frmValidator LOGGER.Debug($"Trying to fill the DropDown (DC) for ControlID [{oDEPENDING_CONTROL_ID}]..RowCount: [{oDTDEPENDING_RESULT.Rows.Count}] ") For Each oControl As Control In pnldesigner.Controls If DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).Guid = oDEPENDING_CONTROL_ID Then - ClassControlCreator.GridTables.Add(oDEPENDING_COLUMN, oDTDEPENDING_RESULT) + ClassControlCreator.GridTables.Item(oControl.Name).Add(oDEPENDING_COLUMN, oDTDEPENDING_RESULT) _dependingColumn_in_action = False Exit For End If @@ -2006,7 +2007,7 @@ Public Class frmValidator LOGGER.Debug($"Trying to fill the DropDown (DC) for ControlID [{oDEPENDING_CONTROL_ID}]..RowCount: [{oDTDEPENDING_RESULT.Rows.Count}] ") For Each oControl As Control In pnldesigner.Controls If DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).Guid = oDEPENDING_CONTROL_ID Then - ClassControlCreator.GridTables.Add(oDEPENDING_COLUMN, oDTDEPENDING_RESULT) + ClassControlCreator.GridTables.Item(oControl.Name).Add(oDEPENDING_COLUMN, oDTDEPENDING_RESULT) _dependingColumn_in_action = False Exit For End If @@ -3546,7 +3547,7 @@ Public Class frmValidator LOGGER.Debug($"Trying to create a DropDown(FIV) for oDEPENDING_CTRL_ID [{oDEPENDING_CTRL_ID}]..RowCount: [{oDTRESULT_FOR_COLUMN.Rows.Count}] ") For Each oControl As Control In pnldesigner.Controls If DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).Guid = oDEPENDING_CTRL_ID Then - ClassControlCreator.GridTables.Add(oDEPENDING_COLUMN, oDTRESULT_FOR_COLUMN) + ClassControlCreator.GridTables.Item(oControl.Name).Add(oDEPENDING_COLUMN, oDTRESULT_FOR_COLUMN) Exit For End If Next @@ -3671,6 +3672,23 @@ Public Class frmValidator End Sub Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click btnSave.Enabled = False + + Dim oGrids = (From oControl In pnldesigner.Controls + Where TypeOf oControl Is GridControl + Select oControl).ToList() + + For Each oGrid As GridControl In oGrids + Dim oView As GridView = oGrid.MainView + + For index = 0 To oView.RowCount - 1 + oView.FocusedRowHandle = index + oView.UpdateCurrentRow() + Next + + Next + + Return + Finish_WFStep() btnSave.Enabled = True End Sub @@ -5467,10 +5485,10 @@ Public Class frmValidator End If Conversations_Init_Rights() Conversations_load() - End If - End If + End If + End Sub