Add Footer aggregate functions for grid columns in validator

This commit is contained in:
Jonathan Jenne
2021-10-08 13:45:06 +02:00
parent 07975ace07
commit b7255d1bd7
8 changed files with 332 additions and 124 deletions

View File

@@ -40,6 +40,14 @@ Public Class ClassControlCreator
Public Const PREFIX_LINE = "LINE"
Public Const PREFIX_BUTTON = "BTN"
Public Const AGGREGATE_NONE = "NONE"
Public Const AGGREGATE_TOTAL_INTEGER = "TOTAL_INTEGER"
Public Const AGGREGATE_TOTAL_FLOAT = "TOTAL_FLOAT"
Public Const AGGREGATE_TOTAL_MIN = "TOTAL_MIN"
Public Const AGGREGATE_TOTAL_MAX = "TOTAL_MAX"
Public Const AGGREGATE_TOTAL_AVG = "TOTAL_AVG"
Public Const AGGREGATE_TOTAL_COUNT = "TOTAL_COUNT"
''' <summary>
''' Saves the column data for each grid and each column in that grid
''' </summary>
@@ -520,54 +528,117 @@ Public Class ClassControlCreator
oControl.RefreshDataSource()
oControl.ForceInitialize()
Dim oShouldDisplayFooter As Boolean = False
For Each oCol As GridColumn In oView.Columns
Dim oColumnData As DataRow = DT_MY_COLUMNS.Select($"SPALTENNAME = '{oCol.FieldName}'").FirstOrDefault()
Dim oColumnData As DataRow = DT_MY_COLUMNS.
Select($"SPALTENNAME = '{oCol.FieldName}'").
FirstOrDefault()
If oColumnData Is Nothing Then
Dim oSequence As Integer = oColumnData.Item("SEQUENCE")
oCol.VisibleIndex = oSequence
Continue For
End If
Dim oSequence As Integer = oColumnData.Item("SEQUENCE")
oCol.VisibleIndex = oSequence
Dim oSummaryFunction As String = oColumnData.Item("SUMMARY_FUNCTION")
Select Case oSummaryFunction
Case AGGREGATE_TOTAL_INTEGER
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum
oCol.SummaryItem.DisplayFormat = "{0:0}"
oShouldDisplayFooter = True
Case AGGREGATE_TOTAL_FLOAT
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum
oCol.SummaryItem.DisplayFormat = "{0:n2}"
oShouldDisplayFooter = True
Case AGGREGATE_TOTAL_AVG
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Average
oShouldDisplayFooter = True
Case AGGREGATE_TOTAL_MAX
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Max
oShouldDisplayFooter = True
Case AGGREGATE_TOTAL_MIN
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Min
oShouldDisplayFooter = True
Case AGGREGATE_TOTAL_COUNT
oCol.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count
oShouldDisplayFooter = True
End Select
Next
oView.OptionsView.ShowFooter = oShouldDisplayFooter
AddHandler oView.InitNewRow, Sub(sender As Object, e As InitNewRowEventArgs)
' TODO: Remove when this works and is properly implemented.
Exit Sub
Try
For Each oColumnData As DataRow In DT_MY_COLUMNS.Rows
For Each oGridColumn As GridColumn In oView.Columns
If oGridColumn.FieldName <> oColumnData.Item("SPALTENNAME") Then
Continue For
End If
Dim oDefaultValue = NotNull(oColumnData.Item("DEFAULT_VALUE"), String.Empty)
If oDefaultValue <> String.Empty Then
oView.SetRowCellValue(e.RowHandle, oGridColumn.FieldName, oDefaultValue)
End If
Next
Next
Catch ex As Exception
LOGGER.Error(ex)
End Try
End Sub
AddHandler oView.CustomRowCellEdit, Sub(sender As Object, e As CustomRowCellEditEventArgs)
Try
For Each oRow As DataRow In DT_MY_COLUMNS.Rows
Dim oColumnName = oRow.Item("SPALTENNAME")
Dim oEditorExists = GridTables_TestEditorExistsByControlAndColumn(oControlId, oColumnName)
Try
For Each oRow As DataRow In DT_MY_COLUMNS.Rows
Dim oColumnName = oRow.Item("SPALTENNAME")
Dim oEditorExists = GridTables_TestEditorExistsByControlAndColumn(oControlId, oColumnName)
If oColumnName = e.Column.FieldName And oEditorExists Then
Dim oEditor = GridTables.Item(oControlId).Item(oColumnName)
If oColumnName = e.Column.FieldName And oEditorExists Then
Dim oEditor = GridTables.Item(oControlId).Item(oColumnName)
e.RepositoryItem = oEditor
End If
Next
Catch ex As Exception
LOGGER.Warn("Error in CustomRowCellEdit for [{0}]", e.CellValue)
LOGGER.Error(ex)
End Try
End Sub
e.RepositoryItem = oEditor
End If
Next
Catch ex As Exception
LOGGER.Warn("Error in CustomRowCellEdit for [{0}]", e.CellValue)
LOGGER.Error(ex)
End Try
End Sub
AddHandler oView.ValidatingEditor, Sub(sender As Object, e As BaseContainerValidateEditorEventArgs)
Dim oRow As DataRowView = oView.GetRow(oView.FocusedRowHandle)
Dim oColumnName = oView.FocusedColumn.FieldName
AddHandler oView.ValidatingEditor, Sub(sender As Object, e As BaseContainerValidateEditorEventArgs)
Dim oRow As DataRowView = oView.GetRow(oView.FocusedRowHandle)
Dim oColumnName = oView.FocusedColumn.FieldName
GridTables_ValidateColumn(oView, DT_MY_COLUMNS, oColumnName, e.Value, e.Valid, e.ErrorText)
End Sub
GridTables_ValidateColumn(oView, DT_MY_COLUMNS, oColumnName, e.Value, e.Valid, e.ErrorText)
End Sub
AddHandler oView.InvalidRowException, Sub(sender As Object, e As InvalidRowExceptionEventArgs)
e.ExceptionMode = ExceptionMode.NoAction
End Sub
AddHandler oView.InvalidRowException, Sub(sender As Object, e As InvalidRowExceptionEventArgs)
e.ExceptionMode = ExceptionMode.NoAction
End Sub
AddHandler oView.ValidatingEditor, Sub(sender As Object, e As BaseContainerValidateEditorEventArgs)
Dim oValue As String = NotNull(e.Value, "")
AddHandler oView.ValidatingEditor, Sub(sender As Object, e As BaseContainerValidateEditorEventArgs)
Dim oValue As String = NotNull(e.Value, "")
If oValue.Contains(" | ") Then
oValue = oValue.Split(" | ").ToList().First()
e.Value = oValue
End If
End Sub
If oValue.Contains(" | ") Then
oValue = oValue.Split(" | ").ToList().First()
e.Value = oValue
End If
End Sub
Return oControl
Return oControl
End Function
Public Shared Function CreateExistingLine(row As DataRow, designMode As Boolean) As LineLabel