216 lines
9.5 KiB
VB.net
216 lines
9.5 KiB
VB.net
Imports DevExpress.Utils
|
|
Imports DevExpress.XtraEditors
|
|
Imports DevExpress.XtraEditors.Repository
|
|
Imports DevExpress.XtraGrid.Columns
|
|
Imports DevExpress.XtraGrid.Views.Grid
|
|
Imports DigitalData.Controls.LookupGrid
|
|
Imports DigitalData.Modules.EDMI.API.Constants
|
|
Imports DigitalData.Modules.EDMI.API.DatabaseWithFallback
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Base
|
|
Imports System.ComponentModel
|
|
|
|
Namespace ControlCreator
|
|
Public Class GridControl
|
|
Private ReadOnly _LogConfig As LogConfig
|
|
Private ReadOnly _GridTables As Dictionary(Of Integer, Dictionary(Of String, RepositoryItem))
|
|
|
|
Public Sub New(pLogConfig As LogConfig, pGridTables As Dictionary(Of Integer, Dictionary(Of String, RepositoryItem)))
|
|
_LogConfig = pLogConfig
|
|
_GridTables = pGridTables
|
|
End Sub
|
|
|
|
Public Function CreateGridColumns(pColumnTable As DataTable) As DataTable
|
|
Dim oDataTable As New DataTable
|
|
|
|
For Each oRow As DataRow In pColumnTable.Rows
|
|
' Create Columns in Datatable
|
|
|
|
Dim oColumn = New DataColumn() With {
|
|
.ColumnName = oRow.Item("SPALTENNAME"),
|
|
.Caption = oRow.Item("SPALTEN_HEADER_LANG"),
|
|
.ReadOnly = False
|
|
}
|
|
Select Case oRow.Item("TYPE_COLUMN")
|
|
Case Constants.CONTROL_TYPE_TEXT
|
|
oColumn.DataType = GetType(String)
|
|
Case Constants.CONTROL_TYPE_INTEGER
|
|
oColumn.DataType = GetType(Integer)
|
|
Case Constants.CONTROL_TYPE_DOUBLE
|
|
oColumn.DataType = GetType(Double)
|
|
Case Constants.CONTROL_TYPE_CURRENCY
|
|
oColumn.DataType = GetType(Double)
|
|
Case Constants.CONTROL_TYPE_BOOLEAN
|
|
oColumn.DataType = GetType(Boolean)
|
|
Case Else
|
|
oColumn.DataType = GetType(String)
|
|
End Select
|
|
|
|
oDataTable.Columns.Add(oColumn)
|
|
Next
|
|
|
|
Return oDataTable
|
|
End Function
|
|
|
|
Public Function FillGridTables(pColumnTable As DataTable, pControlId As Integer, pControlName As String) As Dictionary(Of Integer, Dictionary(Of String, RepositoryItem))
|
|
For Each oRow As DataRow In pColumnTable.Rows
|
|
' Fetch and cache Combobox results
|
|
Dim oConnectionId As Integer = oRow.ItemEx("CONNECTION_ID", 0)
|
|
Dim oSqlCommand As String = oRow.ItemEx("SQL_COMMAND", "")
|
|
|
|
If oConnectionId > 0 And oSqlCommand <> "" Then
|
|
Try
|
|
Dim oComboboxDataTable As DataTable = Nothing
|
|
Dim oColumnName As String = oRow.Item("SPALTENNAME")
|
|
LOGGER.Debug("Working on SQL for Column[{0}]...", oColumnName)
|
|
If Not clsPatterns.HasComplexPatterns(oSqlCommand) Then
|
|
LOGGER.Debug("SQL has no complex patterns!")
|
|
'oComboboxDataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
|
|
oComboboxDataTable = DatabaseFallback.GetDatatable(New GetDatatableOptions(oSqlCommand, DatabaseType.ECM) With {
|
|
.ConnectionId = oConnectionId
|
|
})
|
|
Else
|
|
LOGGER.Debug("...has complex patterns!!")
|
|
End If
|
|
|
|
Dim oRepositoryItem = GridTables_GetRepositoryItemForColumn(oColumnName, oComboboxDataTable, oRow.Item("ADVANCED_LOOKUP"))
|
|
|
|
If _GridTables.Item(pControlId).ContainsKey(oColumnName) Then
|
|
_GridTables.Item(pControlId).Item(oColumnName) = oRepositoryItem
|
|
Else
|
|
_GridTables.Item(pControlId).Add(oColumnName, oRepositoryItem)
|
|
End If
|
|
Catch ex As Exception
|
|
LOGGER.Warn("Could not load data for column {0} in control {1}", oRow.Item("SPALTENNAME"), pControlName)
|
|
LOGGER.Error(ex)
|
|
End Try
|
|
End If
|
|
Next
|
|
|
|
Return _GridTables
|
|
End Function
|
|
|
|
Private Function GridTables_GetRepositoryItemForColumn(pColumnName As String, pDataTable As DataTable, pIsAdvancedLookup As Boolean) As RepositoryItem
|
|
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
|
|
|
|
If pDataTable IsNot Nothing Then
|
|
For Each oRow2 As DataRow In pDataTable.Rows
|
|
Dim oValue = oRow2.Item(0)
|
|
|
|
Try
|
|
If oRow2.ItemArray.Length > 1 Then
|
|
oValue &= $" | {oRow2.Item(1)}"
|
|
End If
|
|
Catch ex As Exception
|
|
End Try
|
|
|
|
oEditor.Items.Add(oValue)
|
|
oItems.Add(oValue)
|
|
Next
|
|
End If
|
|
|
|
Return oEditor
|
|
End If
|
|
End Function
|
|
|
|
Public Sub ConfigureViewColumns(pColumnTable As DataTable, pGridView As GridView)
|
|
Dim oShouldDisplayFooter As Boolean = False
|
|
|
|
For Each oCol As GridColumn In pGridView.Columns
|
|
Dim oColumnData As DataRow = pColumnTable.
|
|
Select($"SPALTENNAME = '{oCol.FieldName}'").
|
|
FirstOrDefault()
|
|
|
|
If oColumnData Is Nothing Then
|
|
Continue For
|
|
End If
|
|
|
|
Dim oSequence As Integer = oColumnData.Item("SEQUENCE")
|
|
oCol.VisibleIndex = oSequence
|
|
|
|
Dim oColumnType As String = oColumnData.Item("TYPE_COLUMN")
|
|
|
|
Select Case oColumnType
|
|
Case "INTEGER"
|
|
oCol.DisplayFormat.FormatType = FormatType.Custom
|
|
oCol.DisplayFormat.FormatString = "N0"
|
|
|
|
Case "DOUBLE"
|
|
oCol.DisplayFormat.FormatType = FormatType.Custom
|
|
oCol.DisplayFormat.FormatString = "N2"
|
|
|
|
Case "CURRENCY"
|
|
oCol.DisplayFormat.FormatType = FormatType.Custom
|
|
oCol.DisplayFormat.FormatString = "C2"
|
|
End Select
|
|
|
|
Dim oSummaryFunction As String = oColumnData.Item("SUMMARY_FUNCTION")
|
|
|
|
Select Case oSummaryFunction
|
|
Case Constants.AGGREGATE_TOTAL_INTEGER
|
|
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum
|
|
oCol.SummaryItem.DisplayFormat = "SUM: {0:N0}"
|
|
oShouldDisplayFooter = True
|
|
|
|
Case Constants.AGGREGATE_TOTAL_FLOAT
|
|
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum
|
|
oCol.SummaryItem.DisplayFormat = "SUM: {0:N2}"
|
|
oShouldDisplayFooter = True
|
|
|
|
Case Constants.AGGREGATE_TOTAL_CURRENCY
|
|
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum
|
|
oCol.SummaryItem.DisplayFormat = "SUM: {0:C2}"
|
|
oShouldDisplayFooter = True
|
|
|
|
Case Constants.AGGREGATE_TOTAL_AVG
|
|
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Average
|
|
oCol.SummaryItem.DisplayFormat = "AVG: {0}"
|
|
oShouldDisplayFooter = True
|
|
|
|
Case Constants.AGGREGATE_TOTAL_MAX
|
|
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Max
|
|
oCol.SummaryItem.DisplayFormat = "MAX: {0}"
|
|
oShouldDisplayFooter = True
|
|
|
|
Case Constants.AGGREGATE_TOTAL_MIN
|
|
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Min
|
|
oCol.SummaryItem.DisplayFormat = "MIN: {0}"
|
|
oShouldDisplayFooter = True
|
|
|
|
Case Constants.AGGREGATE_TOTAL_COUNT
|
|
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count
|
|
oCol.SummaryItem.DisplayFormat = "NUM: {0}"
|
|
oShouldDisplayFooter = True
|
|
|
|
End Select
|
|
Next
|
|
|
|
pGridView.OptionsView.ShowFooter = oShouldDisplayFooter
|
|
End Sub
|
|
End Class
|
|
|
|
|
|
End Namespace
|