WIP lookup grid with depending controls

This commit is contained in:
Jonathan Jenne
2021-09-30 16:35:43 +02:00
parent 33ddd7a28b
commit 9d123727d4
9 changed files with 533 additions and 346 deletions

View File

@@ -37,7 +37,10 @@ Public Class ClassControlCreator
Public Const PREFIX_LINE = "LINE"
Public Const PREFIX_BUTTON = "BTN"
Public Shared GridTables As New Dictionary(Of String, Dictionary(Of String, DataTable))
''' <summary>
''' Saves the column data for each grid and each column in that grid
''' </summary>
Public Shared Property GridTables As New Dictionary(Of Integer, Dictionary(Of String, RepositoryItem))
''' <summary>
''' Standard Eigenschaften für alle Controls
@@ -406,8 +409,9 @@ Public Class ClassControlCreator
Return control
End Function
Public Shared Function CreateExistingGridControl(row As DataRow, DT_MY_COLUMNS As DataTable, designMode As Boolean) As GridControl
Public Shared Function CreateExistingGridControl(row As DataRow, DT_MY_COLUMNS As DataTable, designMode As Boolean, pPanel As Panel) As GridControl
Dim oControl As GridControl = CreateBaseControl(New GridControl(), row, designMode)
Dim oControlId = DirectCast(oControl.Tag, ControlMetadata).Guid
Dim oDatatable As New DataTable
Dim oView As GridView
@@ -420,6 +424,8 @@ Public Class ClassControlCreator
If Not designMode Then
oView.OptionsBehavior.Editable = Not row.Item("READ_ONLY")
oView.OptionsBehavior.ReadOnly = row.Item("READ_ONLY")
'oView.OptionsBehavior.EditorShowMode = EditorShowMode.Click
oControl.UseEmbeddedNavigator = Not row.Item("READ_ONLY")
If row.Item("VKT_ADD_ITEM") = True Then
@@ -450,10 +456,10 @@ Public Class ClassControlCreator
End With
If GridTables.ContainsKey(oControl.Name) Then
GridTables.Item(oControl.Name).Clear()
If GridTables.ContainsKey(oControlId) Then
GridTables.Item(oControlId).Clear()
Else
GridTables.Add(oControl.Name, New Dictionary(Of String, DataTable)())
GridTables.Add(oControlId, New Dictionary(Of String, RepositoryItem)())
End If
For Each oRow As DataRow In DT_MY_COLUMNS.Rows
@@ -472,25 +478,27 @@ Public Class ClassControlCreator
Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), 0)
Dim oSqlCommand As String = NotNull(oRow.Item("SQL_COMMAND"), "")
If Not clsPatterns.HasComplexPatterns(oSqlCommand) Then
If oConnectionId > 0 And oSqlCommand <> "" Then
Try
Dim oComboboxDataTable As DataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
If oConnectionId > 0 And oSqlCommand <> "" Then
Try
Dim oComboboxDataTable As DataTable = Nothing
Dim oColumnName As String = oRow.Item("SPALTENNAME")
If oComboboxDataTable Is Nothing Then
LOGGER.Warn("DataTable for SQL [{0}] is nothing. Possible error on SQL Query.")
End If
If Not clsPatterns.HasComplexPatterns(oSqlCommand) Then
oComboboxDataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
End If
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)
End Try
End If
Dim oRepositoryItem = GridTables_GetRepositoryItemForColumn(oColumnName, oComboboxDataTable, oRow.Item("ADVANCED_LOOKUP"))
If GridTables.Item(oControlId).ContainsKey(oColumnName) Then
GridTables.Item(oControlId).Item(oColumnName) = oRepositoryItem
Else
GridTables.Item(oControlId).Add(oColumnName, oRepositoryItem)
End If
Catch ex As Exception
LOGGER.Warn("Could not load data for column {0} in control {1}", oRow.Item("SPALTENNAME"), oControl.Name)
LOGGER.Error(ex)
End Try
End If
Next
oView.PopulateColumns(oDatatable)
@@ -509,55 +517,132 @@ Public Class ClassControlCreator
AddHandler oView.CustomRowCellEdit, Sub(sender As Object, e As CustomRowCellEditEventArgs)
Try
For Each oRow As DataRow In DT_MY_COLUMNS.Rows
If oRow.Item("SPALTENNAME") = e.Column.FieldName Then
If GridTables.Item(oControl.Name).ContainsKey(e.Column.FieldName) Then
Dim oComboboxDataTable As DataTable = GridTables.Item(oControl.Name).Item(e.Column.FieldName)
If oComboboxDataTable Is Nothing Then
Throw New ApplicationException($"ComboboxTable for Column {e.Column.FieldName} is empty.")
End If
If oRow.Item("ADVANCED_LOOKUP") And oComboboxDataTable IsNot Nothing Then
Dim oEditor = New RepositoryItemLookupControl3 With {
.DataSource = oComboboxDataTable,
.DisplayMember = oComboboxDataTable.Columns.Item(0).ColumnName,
.ValueMember = oComboboxDataTable.Columns.Item(0).ColumnName
}
'AddHandler oEditor.SelectedValuesChanged, Sub(_sender As Object, _e As List(Of String))
' oView.PostEditor()
' End Sub
e.RepositoryItem = oEditor
Else
Dim oEditor = New RepositoryItemComboBox()
Dim oItems As New List(Of String)
AddHandler oEditor.Validating, Sub(_sender As ComboBoxEdit, _e As CancelEventArgs)
If oItems.Contains(_sender.EditValue) Then
_e.Cancel = False
Else
_e.Cancel = True
End If
End Sub
For Each oRow2 As DataRow In oComboboxDataTable.Rows
Dim oValue = oRow2.Item(0)
Try
oValue &= $" | {oRow2.Item(1)}"
Catch ex As Exception
End Try
oEditor.Items.Add(oValue)
oItems.Add(oValue)
Next
e.RepositoryItem = oEditor
End If
End If
If oRow.Item("SPALTENNAME") <> e.Column.FieldName Then
Continue For
End If
If Not GridTables.Item(oControlId).ContainsKey(e.Column.FieldName) Then
Continue For
End If
Dim oEditor = GridTables.Item(oControlId).Item(e.Column.FieldName)
e.RepositoryItem = oEditor
#Region "Old Stuff"
'Dim oComboboxDataTable As DataTable = GridTables.Item(oControlId).Item(e.Column.FieldName)
'If oComboboxDataTable Is Nothing Then
' Throw New ApplicationException($"ComboboxTable for Column {e.Column.FieldName} is empty.")
'End If
'If oRow.Item("ADVANCED_LOOKUP") Then
' Dim oEditor = New RepositoryItemLookupControl3
' If oComboboxDataTable IsNot Nothing Then
' oEditor.DisplayMember = oComboboxDataTable.Columns.Item(0).ColumnName
' oEditor.ValueMember = oComboboxDataTable.Columns.Item(0).ColumnName
' oEditor.DataSource = oComboboxDataTable
' End If
' 'AddHandler oEditor.SelectedValuesChanged, Sub(_sender As Object, _e As List(Of String))
' ' oView.PostEditor()
' ' End Sub
' 'AddHandler oEditor.BeforePopup, Sub(_sender As Object, _e As EventArgs)
' ' MsgBox("oEditor.BeforePopup")
' ' Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), 0)
' ' Dim oSqlCommand As String = NotNull(oRow.Item("SQL_COMMAND"), "")
' ' oSqlCommand = clsPatterns.ReplaceAllValues(oSqlCommand, pPanel, True)
' ' Dim oTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
' ' oEditor.DataSource = oTable
' ' oEditor.DisplayMember = oComboboxDataTable.Columns.Item(0).ColumnName
' ' oEditor.ValueMember = oComboboxDataTable.Columns.Item(0).ColumnName
' ' End Sub
' 'AddHandler oEditor.QueryPopUp, Sub()
' ' MsgBox("oEditor.QueryPopUp")
' ' End Sub
' 'AddHandler oEditor.Popup, Sub()
' ' MsgBox("oEditor.Popup")
' ' End Sub
' 'AddHandler oEditor.ButtonClick, Sub()
' ' MsgBox("oEditor.ButtonClick")
' ' End Sub
' AddHandler oEditor.ButtonPressed, Sub(_sender As Object, _e As EventArgs)
' Dim oEditor2 = DirectCast(_sender, LookupControl3)
' 'MsgBox("oEditor.ButtonPressed")
' Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), 0)
' Dim oSqlCommand As String = NotNull(oRow.Item("SQL_COMMAND"), "")
' oSqlCommand = clsPatterns.ReplaceAllValues(oSqlCommand, pPanel, True)
' Dim oTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
' If oTable IsNot Nothing Then
' oEditor2.Properties.ValueMember = oTable.Columns.Item(0).ColumnName
' oEditor2.Properties.DisplayMember = oTable.Columns.Item(0).ColumnName
' oEditor2.Properties.DataSource = oTable
' oEditor2.DoValidate(PopupCloseMode.Normal)
' End If
' End Sub
' e.RepositoryItem = oEditor
'Else
' If oComboboxDataTable Is Nothing Then
' Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), 0)
' Dim oSqlCommand As String = NotNull(oRow.Item("SQL_COMMAND"), "")
' oSqlCommand = clsPatterns.ReplaceAllValues(oSqlCommand, pPanel, True)
' oComboboxDataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
' End If
' If oComboboxDataTable Is Nothing Then
' Continue For
' End If
' Dim oEditor = New RepositoryItemComboBox()
' Dim oItems As New List(Of String)
' AddHandler oEditor.Validating, Sub(_sender As ComboBoxEdit, _e As CancelEventArgs)
' If oItems.Contains(_sender.EditValue) Then
' _e.Cancel = False
' Else
' _e.Cancel = True
' End If
' End Sub
' For Each oRow2 As DataRow In oComboboxDataTable.Rows
' Dim oValue = oRow2.Item(0)
' Try
' oValue &= $" | {oRow2.Item(1)}"
' Catch ex As Exception
' End Try
' oEditor.Items.Add(oValue)
' oItems.Add(oValue)
' Next
' e.RepositoryItem = oEditor
'End If
#End Region
Next
Catch ex As Exception
LOGGER.Warn("Error in CustomRowCellEdit for [{0}]", e.CellValue)
@@ -565,10 +650,6 @@ Public Class ClassControlCreator
End Try
End Sub
'AddHandler oView.CellValueChanged, Sub(sender As Object, e As CellValueChangedEventArgs)
' Console.WriteLine("")
' End Sub
AddHandler oView.ValidateRow, Sub(sender As Object, e As ValidateRowEventArgs)
Dim oRow As DataRowView = oView.GetRow(oView.FocusedRowHandle)
@@ -599,12 +680,18 @@ Public Class ClassControlCreator
AddHandler oView.ValidatingEditor, Sub(sender As Object, e As BaseContainerValidateEditorEventArgs)
Dim oValue As String = NotNull(e.Value, "")
'MsgBox(oValue)
If oValue.Contains(" | ") Then
oValue = oValue.Split(" | ").ToList().First()
e.Value = oValue
End If
End Sub
'oView.FocusInvalidRow()
Return oControl
End Function
@@ -738,4 +825,70 @@ Public Class ClassControlCreator
End Try
End Function
Public Shared Sub GridTables_CacheDatatableForColumn(pControlId As Object, pColumnName As Object, pSqlStatement As Object, pConnectionId As Integer, pAdvancedLookup As Boolean)
Try
Dim oTable As DataTable = ClassDatabase.Return_Datatable_ConId(pSqlStatement, pConnectionId)
' If no columns for this control have been added, create an empty dict now
If Not GridTables.ContainsKey(pControlId) Then
GridTables.Add(pControlId, New Dictionary(Of String, RepositoryItem))
End If
Dim oRepositoryItem = GridTables_GetRepositoryItemForColumn(pColumnName, oTable, pAdvancedLookup)
Dim oColumnDictionary = GridTables.Item(pControlId)
If oColumnDictionary.ContainsKey(pColumnName) Then
oColumnDictionary.Item(pColumnName) = oRepositoryItem
Else
oColumnDictionary.Add(pColumnName, oRepositoryItem)
End If
Catch ex As Exception
LOGGER.Error(ex)
End Try
End Sub
Public Shared Function GridTables_GetRepositoryItemForColumn(pColumnName As String, pDataTable As DataTable, pIsAdvancedLookup As Boolean) As RepositoryItem
If pDataTable Is Nothing Then
Return Nothing
End If
If pIsAdvancedLookup Then
Dim oEditor = New RepositoryItemLookupControl3
If pDataTable IsNot Nothing Then
oEditor.DisplayMember = pDataTable.Columns.Item(0).ColumnName
oEditor.ValueMember = pDataTable.Columns.Item(0).ColumnName
oEditor.DataSource = pDataTable
End If
Return oEditor
Else
Dim oEditor = New RepositoryItemComboBox()
Dim oItems As New List(Of String)
AddHandler oEditor.Validating, Sub(_sender As ComboBoxEdit, _e As CancelEventArgs)
If oItems.Contains(_sender.EditValue) Then
_e.Cancel = False
Else
_e.Cancel = True
End If
End Sub
For Each oRow2 As DataRow In pDataTable.Rows
Dim oValue = oRow2.Item(0)
Try
oValue &= $" | {oRow2.Item(1)}"
Catch ex As Exception
End Try
oEditor.Items.Add(oValue)
oItems.Add(oValue)
Next
Return oEditor
End If
End Function
End Class