Depending Controls
This commit is contained in:
parent
8c0afa58de
commit
ed5a1233ae
@ -352,6 +352,8 @@ Public Class ClassControls
|
||||
Dim oDatatable As DataTable = ClassDatabase.Return_Datatable(oSQL)
|
||||
|
||||
If Not IsNothing(oDatatable) Then
|
||||
LOGGER.Debug("Found [{0}] depending controls for [{1}]", oDatatable.Rows.Count, Control.Name)
|
||||
|
||||
For Each oRow As DataRow In oDatatable.Rows
|
||||
Dim oControlName As String = NotNull(oRow.Item("NAME"), "")
|
||||
Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), -1)
|
||||
@ -366,9 +368,11 @@ Public Class ClassControls
|
||||
oControlSql = ClassPatterns.ReplaceInternalValues(oControlSql)
|
||||
oControlSql = ClassPatterns.ReplaceControlValues(oControlSql, Panel)
|
||||
|
||||
|
||||
LOGGER.Debug("SQL After Preparing: [{0}]", oControlSql)
|
||||
LOGGER.Debug("Setting new value for [{0}]", oControlName)
|
||||
SetDependingControlResult(oControlName, oControlSql, oConnectionId)
|
||||
Next
|
||||
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
@ -377,6 +381,11 @@ Public Class ClassControls
|
||||
|
||||
Private Sub SetDependingControlResult(IndexName As String, SqlCommand As String, SqlConnectionId As Integer)
|
||||
Try
|
||||
If SqlCommand Is Nothing OrElse SqlCommand = String.Empty Then
|
||||
LOGGER.Warn("New Value for Index [{0}] could not be set. Supplied SQL is empty.")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oConnectionString = ClassFormFunctions.GetConnectionString(SqlConnectionId)
|
||||
Dim oDatatable As DataTable = ClassDatabase.Return_Datatable_CS(SqlCommand, oConnectionString)
|
||||
Dim oFoundControl As Control = Nothing
|
||||
@ -404,10 +413,21 @@ Public Class ClassControls
|
||||
End If
|
||||
|
||||
If TypeOf oFoundControl Is TextBox Then
|
||||
DirectCast(oFoundControl, TextBox).Text = oDatatable.Rows.Item(0).Item(0)
|
||||
If oDatatable.Rows.Count > 0 Then
|
||||
Dim oFirstRow As DataRow = oDatatable.Rows.Item(0)
|
||||
|
||||
If oFirstRow.ItemArray.Length > 0 Then
|
||||
Dim oValue = oFirstRow.Item(0).ToString()
|
||||
|
||||
LOGGER.Debug("Setting Value for control [{0}]: [{1}]", oFoundControl.Name, oValue)
|
||||
DirectCast(oFoundControl, TextBox).Text = oValue
|
||||
End If
|
||||
End If
|
||||
ElseIf TypeOf oFoundControl Is LookupControl2 Then
|
||||
LOGGER.Debug("Setting Value for control [{0}]: [{1}]", oFoundControl.Name, "DATATABLE")
|
||||
DirectCast(oFoundControl, LookupControl2).DataSource = oDatatable
|
||||
ElseIf TypeOf oFoundControl Is ComboBox Then
|
||||
LOGGER.Debug("Setting Value for control [{0}]: [{1}]", oFoundControl.Name, "DATATABLE")
|
||||
DirectCast(oFoundControl, ComboBox).DataSource = oDatatable
|
||||
End If
|
||||
Catch ex As Exception
|
||||
|
||||
@ -19,6 +19,7 @@ Public Class ClassInit
|
||||
Public Sub InitConfig()
|
||||
CONFIG = New ConfigManager(Of ClassConfig)(LOGCONFIG, Application.UserAppDataPath, Application.CommonAppDataPath)
|
||||
LOGCONFIG.Debug = Not CONFIG.Config.LogErrorsOnly
|
||||
LOGGER.Info("Debug log set to: [{0}]", LOGCONFIG.Debug)
|
||||
|
||||
MyConnectionString = DecryptConnectionString(CONFIG.Config.ConnectionString)
|
||||
LogErrorsOnly = CONFIG.Config.LogErrorsOnly
|
||||
|
||||
@ -39,7 +39,7 @@ Public Class ClassPatterns
|
||||
|
||||
Public Const MAX_TRY_COUNT = 500
|
||||
|
||||
Private Shared regex As Regex = New Regex("{#(\w+)#([\w\s_-]+)}+")
|
||||
Private Shared regex As Regex = New Regex("{#(\w+)#([\w\d\s_-]+)}+")
|
||||
Private Shared allPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_IDBA, PATTERN_USER, PATTERN_INT}
|
||||
Private Shared complexPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_IDBA}
|
||||
Private Shared simplePatterns As New List(Of String) From {PATTERN_USER, PATTERN_INT}
|
||||
@ -146,12 +146,28 @@ Public Class ClassPatterns
|
||||
Dim result = input
|
||||
Dim oTryCounter = 0
|
||||
|
||||
LOGGER.Debug("Input String: [{0}]", input)
|
||||
|
||||
While ContainsPattern(result, PATTERN_CTRL)
|
||||
LOGGER.Debug("ReplaceControlValues Try no. [{0}]", oTryCounter)
|
||||
|
||||
If oTryCounter > MAX_TRY_COUNT Then
|
||||
Throw New Exception($"Max tries in ReplaceControlValues exceeded - Result so far [{result}].")
|
||||
End If
|
||||
|
||||
Dim controlName As String = GetNextPattern(result, PATTERN_CTRL).Value
|
||||
LOGGER.Debug("Getting next pattern..")
|
||||
|
||||
Dim oNextPattern = GetNextPattern(result, PATTERN_CTRL)
|
||||
|
||||
If oNextPattern Is Nothing Then
|
||||
LOGGER.Debug("No Next Pattern found. Exiting!")
|
||||
Exit While
|
||||
End If
|
||||
|
||||
LOGGER.Debug("Next Pattern Value: [{0}]", oNextPattern.Value)
|
||||
LOGGER.Debug("Next Pattern Type: [{0}]", oNextPattern.Type)
|
||||
|
||||
Dim controlName As String = oNextPattern.Value
|
||||
Dim oFoundControl As Control = Nothing
|
||||
Dim oFoundType As String = Nothing
|
||||
|
||||
@ -160,9 +176,15 @@ Public Class ClassPatterns
|
||||
Continue For
|
||||
End If
|
||||
|
||||
LOGGER.Debug("Getting control metadata..")
|
||||
|
||||
Dim oMeta = DirectCast(oControl.Tag, ClassControls.ControlMeta)
|
||||
|
||||
LOGGER.Debug("Checking Control Name matches..")
|
||||
|
||||
If oMeta.IndexName = controlName Then
|
||||
LOGGER.Debug("Control Name matches! Matching Control: [{0}]", controlName)
|
||||
|
||||
oFoundControl = oControl
|
||||
oFoundType = oMeta.IndexType
|
||||
Exit For
|
||||
@ -173,28 +195,47 @@ Public Class ClassPatterns
|
||||
Dim oValue As String = String.Empty
|
||||
|
||||
If TypeOf oFoundControl Is TextBox Then
|
||||
oValue = DirectCast(oFoundControl, TextBox).Text
|
||||
Try
|
||||
oValue = DirectCast(oFoundControl, TextBox).Text
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Warn("Control Value for TextBox [{0}] could not be retrieved!", oFoundControl.Name)
|
||||
End Try
|
||||
ElseIf TypeOf oFoundControl Is CheckBox Then
|
||||
oValue = IIf(DirectCast(oFoundControl, CheckBox).Checked, 1, 0)
|
||||
Try
|
||||
oValue = IIf(DirectCast(oFoundControl, CheckBox).Checked, 1, 0)
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Warn("Control Value for CheckBox [{0}] could not be retrieved!", oFoundControl.Name)
|
||||
End Try
|
||||
ElseIf TypeOf oFoundControl Is LookupControl2 Then
|
||||
Dim oLookupControl = DirectCast(oFoundControl, LookupControl2)
|
||||
Try
|
||||
Dim oLookupControl = DirectCast(oFoundControl, LookupControl2)
|
||||
|
||||
If oLookupControl.MultiSelect Then
|
||||
Select Case oFoundType
|
||||
Case "INTEGER"
|
||||
oValue = String.Join(",", oLookupControl.SelectedValues)
|
||||
Case "VARCHAR"
|
||||
Dim oWrapped = oLookupControl.SelectedValues.Select(Function(v) $"'{v}'")
|
||||
oValue = String.Join(",", oWrapped)
|
||||
End Select
|
||||
Else
|
||||
oValue = NotNull(oLookupControl.SelectedValues.Item(0), "")
|
||||
End If
|
||||
If oLookupControl.MultiSelect Then
|
||||
Select Case oFoundType
|
||||
Case "INTEGER"
|
||||
oValue = String.Join(",", oLookupControl.SelectedValues)
|
||||
Case "VARCHAR"
|
||||
Dim oWrapped = oLookupControl.SelectedValues.Select(Function(v) $"'{v}'")
|
||||
oValue = String.Join(",", oWrapped)
|
||||
End Select
|
||||
Else
|
||||
oValue = NotNull(oLookupControl.SelectedValues.Item(0), "")
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Warn("Control Value for LookupControl2 [{0}] could not be retrieved!", oFoundControl.Name)
|
||||
End Try
|
||||
Else
|
||||
oValue = ""
|
||||
End If
|
||||
|
||||
LOGGER.Debug("Retrieved Value from Control [{0}] is: [{1}]", oFoundControl.Name, oValue)
|
||||
|
||||
result = ReplacePattern(result, PATTERN_CTRL, oValue)
|
||||
Else
|
||||
LOGGER.Warn("Control [{0}] not found!", controlName)
|
||||
End If
|
||||
|
||||
oTryCounter += 1
|
||||
@ -204,6 +245,7 @@ Public Class ClassPatterns
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info("Error in ReplaceControlValues:" & ex.Message)
|
||||
Return input
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user