Support for SetControlData for LookupGrids

This commit is contained in:
Jonathan Jenne 2021-10-06 13:01:30 +02:00
parent d92a640bce
commit 153d5a6128

View File

@ -1406,17 +1406,7 @@ Public Class frmValidator
LOGGER.Debug("onLookUpselectedValue_Control2Set") LOGGER.Debug("onLookUpselectedValue_Control2Set")
Dim oRepositoryItem As RepositoryItemLookupControl3 = sender Dim oRepositoryItem As RepositoryItemLookupControl3 = sender
Dim oLookup As LookupControl3 = oRepositoryItem.OwnerEdit Dim oLookup As LookupControl3 = oRepositoryItem.OwnerEdit
Try
If Not IsNothing(SelectedValues) Then
If SelectedValues.Count = 1 Then
SetControlValues(oLookup, SelectedValues) SetControlValues(oLookup, SelectedValues)
Else
LOGGER.Debug("Attention - onLookUpselectedValue_Control2Set: SelectedValues.Count <> 1 - Not implemented multiple selections!")
End If
End If
Catch ex As Exception
LOGGER.Error(ex)
End Try
End Sub End Sub
Private Sub Dynamic_SetControlData(pControl As Control, oDataRow As DataRow) Private Sub Dynamic_SetControlData(pControl As Control, oDataRow As DataRow)
@ -1541,116 +1531,165 @@ Public Class frmValidator
LOGGER.Debug($"Error Dynamic_SetControlData: Check ConnID and SQL on NULL VALUES!") LOGGER.Debug($"Error Dynamic_SetControlData: Check ConnID and SQL on NULL VALUES!")
End If End If
End Sub End Sub
Private Sub SetControlValues(LookupControl As LookupControl3, SelectedValues As List(Of String)) Private Sub SetControlValues(pLookupControl As LookupControl3, pSelectedValues As List(Of String))
Dim oLOOKUPValue = SelectedValues.Item(0) Dim oControlName = pLookupControl.Name
Dim oLOOKUPName = LookupControl.Name Dim oControlMeta = DirectCast(pLookupControl.Tag, ClassControlCreator.ControlMetadata)
LOGGER.Debug($"oLOOKUPValue is [{oLOOKUPValue}]!") Dim oControlID = oControlMeta.Guid
Dim oControlID = DirectCast(LookupControl.Tag, ClassControlCreator.ControlMetadata).Guid
Dim oFilteredDatatable As DataTable = DT_CONTROLS.Clone()
Dim oExpression = $"GUID = {oControlID} and LEN(SET_CONTROL_DATA) > 0"
DT_CONTROLS.Select(oExpression).CopyToDataTable(oFilteredDatatable, LoadOption.PreserveChanges)
If oFilteredDatatable.Rows.Count = 1 Then
LOGGER.Debug($"We got a definition for SetControlValues!!")
Else
Exit Sub
End If
Dim oControl2Set
Dim oControlGUID2Set = oControlID
Dim oControlname2Set = oFilteredDatatable.Rows(0).Item("NAME")
LOGGER.Debug($"Workin on SetControLValue for {oControlname2Set} ...")
If _SetControlValue_in_action = True Then If _SetControlValue_in_action = True Then
LOGGER.Debug($"..but _SetControlValue_in_action = True ==> Exit Sub!") LOGGER.Debug("SetControlValue in action. Exiting.")
Exit Sub Exit Sub
End If End If
If Not IsDBNull(oFilteredDatatable.Rows(0).Item("CONNECTION_ID")) And Not IsDBNull(oFilteredDatatable.Rows(0).Item("SET_CONTROL_DATA")) Then
Dim oSqlCommand = IIf(IsDBNull(oFilteredDatatable.Rows(0).Item("SET_CONTROL_DATA")), "", oFilteredDatatable.Rows(0).Item("SET_CONTROL_DATA")) If pSelectedValues Is Nothing Then
LOGGER.Warn("Cannot set Control Values from Lookup [{0}], selected values are empty.", oControlName)
Exit Sub
End If
If pSelectedValues.Count > 1 Then
LOGGER.Warn("Cannot set Control Values from Lookup [{0}], selected values more than one.", oControlName)
Exit Sub
End If
Dim oControlValue = pSelectedValues.First()
LOGGER.Debug("Control Value is [{0}]!", oControlValue)
Dim oFilteredDatatable As DataTable = DT_CONTROLS.Clone()
DT_CONTROLS.
Select($"GUID = {oControlID} and LEN(SET_CONTROL_DATA) > 0").
CopyToDataTable(oFilteredDatatable, LoadOption.PreserveChanges)
If oFilteredDatatable.Rows.Count < 1 Then
LOGGER.Debug("SET_CONTROL_DATA is empty for control [{0}]. Exiting.", oControlName)
Exit Sub
End If
Dim oRow As DataRow = oFilteredDatatable.Rows.Item(0)
Dim oControlGUID2Set = oControlID
Dim oControlname2Set = oRow.Item("NAME")
LOGGER.Debug($"Workin on SetControLValue for {oControlname2Set} ...")
Dim oConnectionId = NotNull(oRow.Item("CONNECTION_ID"), 0)
Dim oControlDataSql = NotNull(oRow.Item("SET_CONTROL_DATA"), String.Empty)
If oConnectionId = 0 Or oControlDataSql = String.Empty Then
LOGGER.Debug($"Error: Check CoNN ID and SQL on NULL VALUES!")
Exit Sub
End If
Dim oSqlCommand = NotNull(oRow.Item("SET_CONTROL_DATA"), String.Empty)
oSqlCommand = clsPatterns.ReplaceAllValues(oSqlCommand, PanelValidatorControl, True) oSqlCommand = clsPatterns.ReplaceAllValues(oSqlCommand, PanelValidatorControl, True)
_SetControlValue_in_action = True
Dim oDTDEPENDING_RESULT As DataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oFilteredDatatable.Rows(0).Item("CONNECTION_ID"), $"SetControlValues - CTRLID {oControlID}") Dim oControlDataResult As DataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId, $"SetControlValues - CTRLID {oControlID}")
For Each oRowControl2Set As DataRow In oDTDEPENDING_RESULT.Rows
If oControlDataResult Is Nothing Then
Exit Sub
End If
For Each oResultRow As DataRow In oControlDataResult.Rows
Try Try
oControl2Set = oRowControl2Set.Item("Control2Set") _SetControlValue_in_action = True
Dim oControl2Set = oResultRow.Item("Control2Set")
If oControl2Set.ToString.ToUpper = "BTN_FINISH".ToUpper Then If oControl2Set.ToString.ToUpper = "BTN_FINISH".ToUpper Then
Try Try
Try Dim btntext = oResultRow.Item("Caption")
Dim btntext = oRowControl2Set.Item("Caption")
btnSave.Text = btntext & " (F2)" btnSave.Text = btntext & " (F2)"
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex)
End Try End Try
Try Try
Dim oColor1 = System.Drawing.Color.FromName(oRowControl2Set.Item("BackgroundColor")) Dim oColor1 = Color.FromName(oResultRow.Item("BackgroundColor"))
btnSave.BackColor = oColor1 btnSave.BackColor = oColor1
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex)
btnSave.BackColor = Color.Transparent btnSave.BackColor = Color.Transparent
End Try End Try
Try Try
Dim oColor2 = System.Drawing.Color.FromName(oRowControl2Set.Item("FontColor")) Dim oColor2 = Color.FromName(oResultRow.Item("FontColor"))
btnSave.ForeColor = oColor2 btnSave.ForeColor = oColor2
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex)
btnSave.ForeColor = Color.Black btnSave.ForeColor = Color.Black
End Try End Try
Catch ex As Exception
End Try
_SetControlValue_in_action = False _SetControlValue_in_action = False
Continue For Continue For
End If End If
Dim oFound As Boolean = False Dim oFound As Boolean = False
If IsNumeric(oControl2Set) = False Then Dim oControlId2Set As Integer
If Not Integer.TryParse(oControl2Set, oControlId2Set) Then
LOGGER.Warn("Careful: the oControl2Set contains no CONTROL_GUID") LOGGER.Warn("Careful: the oControl2Set contains no CONTROL_GUID")
Exit Sub Exit Sub
End If End If
'Dim oDependingLookup As LookupControl3 = pnldesigner.Controls.Find(oDEPENDING_CtrlName, False).FirstOrDefault()
For Each oControl As Control In PanelValidatorControl.Controls For Each oControl As Control In PanelValidatorControl.Controls
If DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata).Guid = oControl2Set Then Dim oMeta As ClassControlCreator.ControlMetadata = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata)
oFound = True
LOGGER.Debug($"Got the Control22Set: {oControl2Set}..Setting the values..") If oMeta.Guid = oControlId2Set Then
Select Case oControl.GetType.ToString
Case GetType(TextBox).ToString LOGGER.Debug($"Got the Control22Set: {oControlId2Set}..Setting the values..")
Dim oTextOption = "Replace" Dim oCaption As Object = oResultRow.Item("Caption")
Dim oTextOption = Nothing
Try Try
oTextOption = oRowControl2Set.Item("TextOption") oTextOption = oResultRow.Item("TextOption")
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex)
oTextOption = "Replace" oTextOption = "Replace"
End Try End Try
Select Case oControl.GetType()
Case GetType(TextBox)
Try Try
Dim oTEXT = oRowControl2Set.Item("Caption")
If oTextOption = "Replace" Then If oTextOption = "Replace" Then
oControl.Text = oTEXT oControl.Text = oCaption
Else Else
oControl.Text = oControl.Text & oTEXT oControl.Text &= oCaption
End If End If
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex)
End Try End Try
Dim oColor Dim oColor
Try Try
oColor = System.Drawing.Color.FromName(oRowControl2Set.Item("BackgroundColor")) oColor = Color.FromName(oResultRow.Item("BackgroundColor"))
oControl.BackColor = oColor oControl.BackColor = oColor
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex)
oControl.BackColor = Color.White oControl.BackColor = Color.White
End Try End Try
Try Try
oColor = System.Drawing.Color.FromName(oRowControl2Set.Item("FontColor")) oColor = Color.FromName(oResultRow.Item("FontColor"))
oControl.ForeColor = oColor oControl.ForeColor = oColor
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex)
oControl.ForeColor = Color.Black oControl.ForeColor = Color.Black
End Try End Try
Case GetType(LookupControl3).ToString Case GetType(LookupControl3)
Dim oDependingLookup As LookupControl3 = oControl Dim oDependingLookup As LookupControl3 = oControl
oDependingLookup.Properties.DataSource = oDTDEPENDING_RESULT If oDependingLookup.Properties.MultiSelect = True Then
oDependingLookup.Properties.ValueMember = oDTDEPENDING_RESULT.Columns.Item(0).ColumnName If oTextOption = "Replace" Then
oDependingLookup.Properties.DisplayMember = oDTDEPENDING_RESULT.Columns.Item(0).ColumnName oDependingLookup.Properties.SelectedValues = New List(Of String) From {oCaption}
Case GetType(GridControl).ToString Else
'ClassControlCreator.GridTables oDependingLookup.Properties.SelectedValues.Add(oCaption)
End If
Else
oDependingLookup.Properties.SelectedValues = New List(Of String) From {oCaption}
End If
Case Else
LOGGER.Warn("SetControlData used on unsupported control")
End Select End Select
_SetControlValue_in_action = False
oFound = True
Exit For Exit For
End If End If
@ -1660,13 +1699,12 @@ Public Class frmValidator
LOGGER.Debug($"Could not find the Control2Set with ID {oControlGUID2Set} on panel!!!") LOGGER.Debug($"Could not find the Control2Set with ID {oControlGUID2Set} on panel!!!")
End If End If
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex)
LOGGER.Warn($"Error while Control2Set for [{oControlname2Set}]: " & ex.Message) LOGGER.Warn($"Error while Control2Set for [{oControlname2Set}]: " & ex.Message)
Finally
_SetControlValue_in_action = False _SetControlValue_in_action = False
End Try End Try
Next Next
Else
LOGGER.Debug($"Error: Check CoNN ID and SQL on NULL VALUES!")
End If
End Sub End Sub
Private Sub LookupControl_DependingControls(LookupControl As LookupControl3, SelectedValues As List(Of String)) Private Sub LookupControl_DependingControls(LookupControl As LookupControl3, SelectedValues As List(Of String))
Dim oLOOKUPValue = SelectedValues.Item(0) Dim oLOOKUPValue = SelectedValues.Item(0)
@ -5659,14 +5697,4 @@ Public Class frmValidator
End If End If
End Sub End Sub
Private Sub BarButtonItem6_ItemClick_2(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem6.ItemClick
For Each oControl In PanelValidatorControl.Controls
If TypeOf oControl Is GridControl Then
Dim oGrid = DirectCast(oControl, GridControl)
Dim oView = DirectCast(oGrid.FocusedView, GridView)
oView.FocusInvalidRow()
End If
Next
End Sub
End Class End Class