WIP Validation for Grids

This commit is contained in:
Jonathan Jenne 2021-03-09 13:24:44 +01:00
parent b6413711f2
commit 2fd4e817a7
3 changed files with 86 additions and 61 deletions

View File

@ -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))
''' <summary>
''' 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,43 +539,42 @@ 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
AddHandler oView.ValidatingEditor, Sub(sender As Object, e As BaseContainerValidateEditorEventArgs)
Dim oRow As DataRowView = oView.GetRow(oView.FocusedRowHandle)
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 As String = NotNull(e.Value, "")
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 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)
Dim oValue = e.Value.ToString()
Dim oView2 As GridView = TryCast(sender, GridView)
If oValue.Contains(" | ") Then
oValue = oValue.Split(" | ").ToList().Item(0)
oView2.SetRowCellValue(e.RowHandle, e.Column, oValue)
End If
End Function
Public Shared Function CreateExistingLine(row As DataRow, designMode As Boolean) As LineLabel
Dim control As LineLabel = CreateBaseControl(New LineLabel(), row, designMode)
control.Text = "------------------------------"

View File

@ -165,6 +165,9 @@
<Reference Include="DigitalData.Modules.EDMI.API">
<HintPath>..\..\..\DDMonorepo\Modules.EDMIAPI\bin\Debug\DigitalData.Modules.EDMI.API.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Language">
<HintPath>..\..\..\DDMonorepo\Modules.Language\bin\Debug\DigitalData.Modules.Language.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Logging">
<HintPath>..\..\..\DDMonorepo\Modules.Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
</Reference>

View File

@ -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