WIP Validation for Grids
This commit is contained in:
@@ -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 = "------------------------------"
|
||||
|
||||
Reference in New Issue
Block a user