fix depending controls crashing because of missing tag for datetimepicker

This commit is contained in:
Jonathan Jenne 2020-03-17 11:02:48 +01:00
parent ed5a1233ae
commit 3659055597
3 changed files with 83 additions and 56 deletions

View File

@ -284,14 +284,14 @@ Public Class ClassControls
End Sub End Sub
Public Function AddTextBox(indexname As String, y As Integer, text As String, DataType As String) As TextBox Public Function AddTextBox(indexname As String, y As Integer, text As String, DataType As String) As TextBox
Dim txt As New TextBox Dim txt As New TextBox With {
txt.Name = "txt" & indexname .Name = "txt" & indexname,
.Size = New Size(260, 27),
txt.Size = New Size(260, 27) .Location = New Point(11, y),
txt.Location = New Point(11, y) .Tag = New ControlMeta() With {
txt.Tag = New ControlMeta() With { .IndexName = indexname,
.IndexName = indexname, .IndexType = DataType
.IndexType = DataType }
} }
If text <> "" Then If text <> "" Then
@ -340,6 +340,27 @@ Public Class ClassControls
End If End If
End Sub End Sub
Public Function AddDateTimePicker(indexname As String, y As Integer, DataType As String)
Dim dtp As New DateTimePicker With {
.Name = "dtp" & indexname,
.Format = DateTimePickerFormat.Short,
.Size = New Size(133, 27),
.Location = New Point(11, y),
.Tag = New ControlMeta() With {
.IndexName = indexname,
.IndexType = DataType
}
}
AddHandler dtp.ValueChanged, AddressOf OndtpChanged
Return dtp
End Function
Sub OndtpChanged()
'offen was hier zu tun ist
End Sub
Private Sub PrepareDependingControl(Control As Control) Private Sub PrepareDependingControl(Control As Control)
If TypeOf Control Is Label Then If TypeOf Control Is Label Then
Exit Sub Exit Sub

View File

@ -176,12 +176,24 @@ Public Class ClassPatterns
Continue For Continue For
End If End If
LOGGER.Debug("Getting control metadata..") LOGGER.Debug("Getting control metadata from object: [{0}]", oControl?.Tag?.ToString())
Dim oMeta = DirectCast(oControl.Tag, ClassControls.ControlMeta) If oControl.Tag Is Nothing Then
LOGGER.Warn("No Metadata object found for control [{0}]. Skipping.", oControl.Name)
Continue For
End If
Dim oMeta = TryCast(oControl.Tag, ClassControls.ControlMeta)
LOGGER.Debug("Metadata IndexName: [{0}]", oMeta.IndexName)
LOGGER.Debug("Metadata IndexType: [{0}]", oMeta.IndexType)
LOGGER.Debug("Checking Control Name matches..") LOGGER.Debug("Checking Control Name matches..")
If oMeta Is Nothing Then
LOGGER.Warn("No Metadata found for control [{0}]. Skipping.", oControl.Name)
Continue For
End If
If oMeta.IndexName = controlName Then If oMeta.IndexName = controlName Then
LOGGER.Debug("Control Name matches! Matching Control: [{0}]", controlName) LOGGER.Debug("Control Name matches! Matching Control: [{0}]", controlName)
@ -194,6 +206,8 @@ Public Class ClassPatterns
If oFoundControl IsNot Nothing Then If oFoundControl IsNot Nothing Then
Dim oValue As String = String.Empty Dim oValue As String = String.Empty
LOGGER.Debug("Found Control [{0}], continuing with setting value..", oFoundControl.Name)
If TypeOf oFoundControl Is TextBox Then If TypeOf oFoundControl Is TextBox Then
Try Try
oValue = DirectCast(oFoundControl, TextBox).Text oValue = DirectCast(oFoundControl, TextBox).Text
@ -219,6 +233,8 @@ Public Class ClassPatterns
Case "VARCHAR" Case "VARCHAR"
Dim oWrapped = oLookupControl.SelectedValues.Select(Function(v) $"'{v}'") Dim oWrapped = oLookupControl.SelectedValues.Select(Function(v) $"'{v}'")
oValue = String.Join(",", oWrapped) oValue = String.Join(",", oWrapped)
Case Else
LOGGER.Warn("Lookup Control with [{0}] is not supported!", oFoundType)
End Select End Select
Else Else
oValue = NotNull(oLookupControl.SelectedValues.Item(0), "") oValue = NotNull(oLookupControl.SelectedValues.Item(0), "")
@ -228,10 +244,11 @@ Public Class ClassPatterns
LOGGER.Warn("Control Value for LookupControl2 [{0}] could not be retrieved!", oFoundControl.Name) LOGGER.Warn("Control Value for LookupControl2 [{0}] could not be retrieved!", oFoundControl.Name)
End Try End Try
Else Else
LOGGER.Debug("Unknown Control type for type [{0}], setting value to empty string.", oFoundControl.Name)
oValue = "" oValue = ""
End If End If
LOGGER.Debug("Retrieved Value from Control [{0}] is: [{1}]", oFoundControl.Name, oValue) LOGGER.Debug("Retrieved Value from Control [{0}] is: [{1}]", controlName, oValue)
result = ReplacePattern(result, PATTERN_CTRL, oValue) result = ReplacePattern(result, PATTERN_CTRL, oValue)
Else Else

View File

@ -83,20 +83,6 @@ Public Class frmIndex
lbl.Location = New Point(11, ylbl) lbl.Location = New Point(11, ylbl)
End Sub End Sub
Sub AddDateTimePicker(indexname As String, y As Integer)
Dim dtp As New DateTimePicker
dtp.Name = "dtp" & indexname
dtp.Format = DateTimePickerFormat.Short
dtp.Size = New Size(133, 27)
pnlIndex.Controls.Add(dtp)
dtp.Location = New Point(11, y)
AddHandler dtp.ValueChanged, AddressOf OndtpChanged
End Sub
Sub OndtpChanged()
'offen was hier zu tun ist
End Sub
Function Indexwert_checkValueDB(indexname As String, wert As String) Function Indexwert_checkValueDB(indexname As String, wert As String)
Try Try
Dim DR As DataRow Dim DR As DataRow
@ -1596,9 +1582,9 @@ Public Class frmIndex
Private Sub LoadIndexe_Man() Private Sub LoadIndexe_Man()
Try Try
Dim anz As Integer = 1 Dim oControlCount As Integer = 1
Dim ylbl As Integer = 11 Dim oLabelPosition As Integer = 11
Dim y As Integer = 33 Dim oControlPosition As Integer = 33
Dim oControls As New ClassControls(pnlIndex, Me) Dim oControls As New ClassControls(pnlIndex, Me)
If DT_INDEXEMAN.Rows.Count = 0 Then If DT_INDEXEMAN.Rows.Count = 0 Then
@ -1606,61 +1592,64 @@ Public Class frmIndex
LOGGER.Info(" - Keine Manuellen Indizes für die " & vbNewLine & "Dokumentart " & cmbDokumentart.Text & " definiert") LOGGER.Info(" - Keine Manuellen Indizes für die " & vbNewLine & "Dokumentart " & cmbDokumentart.Text & " definiert")
End If End If
For Each DR As DataRow In DT_INDEXEMAN.Rows For Each oRow As DataRow In DT_INDEXEMAN.Rows
Dim type = DR.Item("DATATYPE") Dim oDataType = oRow.Item("DATATYPE")
Dim MultiSelect As Boolean = DR.Item("MULTISELECT") Dim MultiSelect As Boolean = oRow.Item("MULTISELECT")
Dim AddNewItems As Boolean = DR.Item("VKT_ADD_ITEM") Dim AddNewItems As Boolean = oRow.Item("VKT_ADD_ITEM")
Dim PreventDuplicates As Boolean = DR.Item("VKT_PREVENT_MULTIPLE_VALUES") Dim PreventDuplicates As Boolean = oRow.Item("VKT_PREVENT_MULTIPLE_VALUES")
Dim oControlName As String = oRow.Item("NAME")
If type <> "BOOLEAN" Then If oDataType <> "BOOLEAN" Then
addLabel(DR.Item("NAME"), DR.Item("COMMENT").ToString, ylbl, anz) addLabel(oControlName, oRow.Item("COMMENT").ToString, oLabelPosition, oControlCount)
End If End If
Dim DefaultValue = Check_HistoryValues(DR.Item("NAME"), DR.Item("DOKUMENTART")) Dim DefaultValue = Check_HistoryValues(oControlName, oRow.Item("DOKUMENTART"))
If DefaultValue Is Nothing Then If DefaultValue Is Nothing Then
DefaultValue = DR.Item("DEFAULT_VALUE") DefaultValue = oRow.Item("DEFAULT_VALUE")
End If End If
Select Case type Select Case oDataType
Case "BOOLEAN" Case "BOOLEAN"
Dim chk As CheckBox = oControls.AddCheckBox(DR.Item("NAME"), y, DefaultValue, DR.Item("COMMENT").ToString) Dim chk As CheckBox = oControls.AddCheckBox(oControlName, oControlPosition, DefaultValue, oRow.Item("COMMENT").ToString)
If Not IsNothing(chk) Then If Not IsNothing(chk) Then
pnlIndex.Controls.Add(chk) pnlIndex.Controls.Add(chk)
End If End If
Case "INTEGER" Case "INTEGER"
If DR.Item("SUGGESTION") = True And DR.Item("SQL_RESULT").ToString.Length > 0 Then If oRow.Item("SUGGESTION") = True And oRow.Item("SQL_RESULT").ToString.Length > 0 Then
Dim oControl = oControls.AddVorschlag_ComboBox(DR.Item("NAME"), y, DR.Item("CONNECTION_ID"), DR.Item("SQL_RESULT"), MultiSelect, DR.Item("DATATYPE"), DefaultValue, AddNewItems, PreventDuplicates) Dim oControl = oControls.AddVorschlag_ComboBox(oControlName, oControlPosition, oRow.Item("CONNECTION_ID"), oRow.Item("SQL_RESULT"), MultiSelect, oDataType, DefaultValue, AddNewItems, PreventDuplicates)
If Not IsNothing(oControl) Then If Not IsNothing(oControl) Then
pnlIndex.Controls.Add(oControl) pnlIndex.Controls.Add(oControl)
End If End If
Else Else
'nur eine Textbox 'nur eine Textbox
Dim oControl = oControls.AddTextBox(DR.Item("NAME"), y, DefaultValue, DR.Item("DATATYPE")) Dim oControl = oControls.AddTextBox(oControlName, oControlPosition, DefaultValue, oDataType)
If Not IsNothing(oControl) Then If Not IsNothing(oControl) Then
pnlIndex.Controls.Add(oControl) pnlIndex.Controls.Add(oControl)
End If End If
End If End If
Case "VARCHAR" Case "VARCHAR"
If DR.Item("SUGGESTION") = True And DR.Item("SQL_RESULT").ToString.Length > 0 Then If oRow.Item("SUGGESTION") = True And oRow.Item("SQL_RESULT").ToString.Length > 0 Then
Dim oControl = oControls.AddVorschlag_ComboBox(DR.Item("NAME"), y, DR.Item("CONNECTION_ID"), DR.Item("SQL_RESULT"), MultiSelect, DR.Item("DATATYPE"), DefaultValue, AddNewItems, PreventDuplicates) Dim oControl = oControls.AddVorschlag_ComboBox(oControlName, oControlPosition, oRow.Item("CONNECTION_ID"), oRow.Item("SQL_RESULT"), MultiSelect, oDataType, DefaultValue, AddNewItems, PreventDuplicates)
If Not IsNothing(oControl) Then If Not IsNothing(oControl) Then
pnlIndex.Controls.Add(oControl) pnlIndex.Controls.Add(oControl)
End If End If
Else Else
If DR.Item("NAME").ToString.ToLower = "dateiname" Then If oControlName.ToString.ToLower = "dateiname" Then
Dim oControl = oControls.AddTextBox(DR.Item("NAME"), y, System.IO.Path.GetFileNameWithoutExtension(CURRENT_WORKFILE), DR.Item("DATATYPE")) Dim oControl = oControls.AddTextBox(oControlName, oControlPosition, System.IO.Path.GetFileNameWithoutExtension(CURRENT_WORKFILE), oDataType)
If Not IsNothing(oControl) Then If Not IsNothing(oControl) Then
pnlIndex.Controls.Add(oControl) pnlIndex.Controls.Add(oControl)
End If End If
Else Else
Dim VORBELGUNG As String = DefaultValue Dim VORBELGUNG As String = DefaultValue
Dim oControl = oControls.AddTextBox(DR.Item("NAME"), y, VORBELGUNG, DR.Item("DATATYPE")) Dim oControl = oControls.AddTextBox(oControlName, oControlPosition, VORBELGUNG, oDataType)
If Not IsNothing(oControl) Then If Not IsNothing(oControl) Then
pnlIndex.Controls.Add(oControl) pnlIndex.Controls.Add(oControl)
End If End If
End If End If
End If End If
Case "DATE" Case "DATE"
AddDateTimePicker(DR.Item("NAME"), y) Dim oPicker = oControls.AddDateTimePicker(oControlName, oControlPosition, oDataType)
pnlIndex.Controls.Add(oPicker)
Case Else Case Else
If USER_LANGUAGE = "de-DE" Then If USER_LANGUAGE = "de-DE" Then
MsgBox("Bitte überprüfen Sie den Datentyp des hinterlegten Indexwertes!", MsgBoxStyle.Critical, "Achtung:") MsgBox("Bitte überprüfen Sie den Datentyp des hinterlegten Indexwertes!", MsgBoxStyle.Critical, "Achtung:")
@ -1671,18 +1660,18 @@ Public Class frmIndex
LOGGER.Warn(" - Datentyp nicht hinterlegt - LoadIndexe_Man") LOGGER.Warn(" - Datentyp nicht hinterlegt - LoadIndexe_Man")
End Select End Select
anz += 1 oControlCount += 1
ylbl += 50 oLabelPosition += 50
y += 50 oControlPosition += 50
'make y as height in fom 'make y as height in fom
Next Next
Dim pnlHeight = y - 30 Dim oPanelHeight = oControlPosition - 30
If pnlIndex.Height < pnlHeight Then If pnlIndex.Height < oPanelHeight Then
If (Me.Height - 315) < pnlHeight Then If (Me.Height - 315) < oPanelHeight Then
Me.Height = (Me.Height - 315) + pnlHeight Me.Height = (Me.Height - 315) + oPanelHeight
End If End If
pnlIndex.Height = pnlHeight pnlIndex.Height = oPanelHeight
End If End If
SendKeys.Send("{TAB}") SendKeys.Send("{TAB}")