This commit is contained in:
SchreiberM
2016-04-28 14:56:48 +02:00
parent 0cae7cdc6a
commit 70e1d73fa4
9 changed files with 5594 additions and 4771 deletions

View File

@@ -141,60 +141,88 @@ Public Class ClassControlBuilder
combo.BackColor = Color.White
End Sub
Dim CONTROL_ID
Public Sub Enable_Controls()
End Sub
Public Sub Depending_Controls()
End Sub
Public Sub OnComboBoxValueChanged(sender As Object, ByVal e As EventArgs)
If CURRENT_RECORD_ENABLED = False Then Exit Sub
Public Sub Enable_Controls(control As Control, TableResult As DataTable, value As Object)
Try
Dim control As Control = DirectCast(sender, Control)
Dim controlId As Integer = DirectCast(control.Tag, ClassControlMetadata).Id
CONTROL_ID = controlId
If CONTROL_ID = 29 Then
Console.WriteLine("Obacht")
End If
'SQL für abhängige Auswahllisten
Dim SQL As String = String.Format("SELECT GUID, SQL_COMMAND_1 FROM TBPMO_CONTROL WHERE SQL_COMMAND_1 LIKE '%@{0}@%'", controlId)
Dim value
'SQL für enable control
Dim SQLenable As String = String.Format("SELECT GUID, SQL_COMMAND_2 FROM TBPMO_CONTROL WHERE SQL_COMMAND_1 LIKE '%@{0}@%'", controlId)
' Diese Befehle führen dazu, dass auch der ValueMember als Wert ausgelesen wird
' Das kann zu unerwarteten Ergebnissen führen, da der Benutzer nur den DisplayMember sieht.
'Select Case control.GetType()
' Case GetType(CustomComboBox)
' If IsNothing(DirectCast(control, CustomComboBox).ValueMember) Then
' value = DirectCast(control, CustomComboBox).Text
' Else
' value = DirectCast(control, CustomComboBox).SelectedValue
' End If
' Case Else
' Exit Sub
'End Select
' Die bessere Lösung ist für jetzt, einfach den angezeigten Wert auszulesen:
value = DirectCast(control, CustomComboBox).Text
If String.IsNullOrEmpty(value) Then
If TableResult.Rows.Count = 0 Then
Exit Sub
End If
Dim datatable As DataTable = ClassDatabase.Return_Datatable(SQL)
Dim datatable1 As DataTable = ClassDatabase.Return_Datatable(SQLenable)
If datatable.Rows.Count = 0 Then
Exit Sub
End If
If CURRENT_RECORD_ID = 0 And CtrlCommandUI.IsInsert = True Then
Exit Sub
End If
If CURRENT_RECORD_ID = 0 Then
Exit Sub
End If
For Each row As DataRow In datatable.Rows
For Each row As DataRow In TableResult.Rows
Dim sqlcommand As String = row.Item("SQL_COMMAND_2")
If IsNothing(sqlcommand) Then
Continue For
End If
sqlcommand = sqlcommand.ToUpper.Replace("@RECORD_ID", CURRENT_RECORD_ID)
Dim regex As New System.Text.RegularExpressions.Regex("(@(\d+)@)")
Dim match As System.Text.RegularExpressions.Match = regex.Match(sqlcommand)
If match.Success Then
' DependingControlId bezeichnet das Control, das die Abhängigkeit enthält
Dim dependingControlId As Integer = row.Item("GUID")
Dim panel As Panel = DirectCast(control.Parent, Panel)
' Über die Id das Control finden
Dim dependingControl As Control = panel.Controls.OfType(Of Control)().Where(Function(c As Control)
Return DirectCast(c.Tag, ClassControlMetadata).Id = dependingControlId
End Function).SingleOrDefault()
sqlcommand = sqlcommand.Replace(match.Groups(1).Value, value)
If LogErrorsOnly = False Then ClassLogger.Add(" >> " & String.Format("Executing SQL_COMMAND: '{0}' for controlID '{1}'", sqlcommand, dependingControlId))
Dim dt As DataTable = ClassDatabase.Return_Datatable(sqlcommand)
Dim type = dependingControl.GetType().Name
If dt.Rows.Count = 1 Then
Select Case type
Case "DateEdit"
Try
Dim enabled As Boolean = CBool(dt.Rows(0).Item(0))
dependingControl.Enabled = enabled
Catch ex As Exception
ClassLogger.Add("Unexpected Error in EnableControls - DateEdit: " & ex.Message, True)
End Try
Case "CustomComboBox"
Try
Dim enabled As Boolean = CBool(dt.Rows(0).Item(0))
dependingControl.Enabled = enabled
Catch ex As Exception
ClassLogger.Add("Unexpected Error in EnableControls - CustomComboBox: " & ex.Message, True)
End Try
Case "TextBox"
Try
Dim enabled As Boolean = CBool(dt.Rows(0).Item(0))
dependingControl.Enabled = enabled
Catch ex As Exception
ClassLogger.Add("Unexpected Error in EnableControls - TextBox: " & ex.Message, True)
End Try
End Select
Else
ClassLogger.Add(" >> Attention: RowCount for enabling control was '" & dt.Rows.Count.ToString & "' and not 1 as expected - Check SQL: '" & sqlcommand & "'")
End If
End If
Next
Catch ex As Exception
MsgBox("Error in Enable Controls - " & CONTROL_ID.ToString & ": " & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Public Sub Depending_Controls(control As Control, TableResult As DataTable, value As String)
Try
If TableResult.Rows.Count = 0 Then
Exit Sub
End If
If CURRENT_RECORD_ID = 0 Then
Exit Sub
End If
For Each row As DataRow In TableResult.Rows
Dim sqlcommand As String = row.Item("SQL_COMMAND_1")
If IsNothing(sqlcommand) Then
@@ -205,13 +233,13 @@ Public Class ClassControlBuilder
Dim regex As New System.Text.RegularExpressions.Regex("(@(\d+)@)")
Dim match As System.Text.RegularExpressions.Match = regex.Match(sqlcommand)
If match.Success Then
Dim sqlguid = String.Format("SELECT GUID FROM TBPMO_CONTROL_VALUE WHERE CONTROL_ID = {0} AND RECORD_ID = {1}", controlId, CURRENT_RECORD_ID)
Dim sqlguid = String.Format("SELECT GUID FROM TBPMO_CONTROL_VALUE WHERE CONTROL_ID = {0} AND RECORD_ID = {1}", CONTROL_ID, CURRENT_RECORD_ID)
Dim ctrlvalID = ClassDatabase.Execute_Scalar(sqlguid)
If Not IsNothing(ctrlvalID) Then
Dim upd1 = String.Format("UPDATE TBPMO_CONTROL_VALUE SET VALUE = '{0}' WHERE CONTROL_ID = {1} AND RECORD_ID = {2}", value.ToString, controlId, CURRENT_RECORD_ID)
Dim upd1 = String.Format("UPDATE TBPMO_CONTROL_VALUE SET VALUE = '{0}' WHERE CONTROL_ID = {1} AND RECORD_ID = {2}", value.ToString, CONTROL_ID, CURRENT_RECORD_ID)
ClassDatabase.Execute_non_Query(upd1)
Else
Dim ins = String.Format("INSERT INTO TBPMO_CONTROL_VALUE (CONTROL_ID,RECORD_ID,VALUE,ADDED_WHO) VALUES ({0},{1},'{2}','{3}')", controlId, CURRENT_RECORD_ID, value, Environment.UserName)
Dim ins = String.Format("INSERT INTO TBPMO_CONTROL_VALUE (CONTROL_ID,RECORD_ID,VALUE,ADDED_WHO) VALUES ({0},{1},'{2}','{3}')", CONTROL_ID, CURRENT_RECORD_ID, value, Environment.UserName)
If ClassDatabase.Execute_non_Query(ins) = True Then
If LogErrorsOnly = False Then ClassLogger.Add(" >> Value was nothing - Inserted the ControlValue '" & ins & "'")
End If
@@ -313,6 +341,119 @@ Public Class ClassControlBuilder
End If
Next
Catch ex As Exception
MsgBox("Error in DependingControls - " & CONTROL_ID.ToString & ": " & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Public Sub OnComboBoxValueChanged(sender As Object, ByVal e As EventArgs)
If CURRENT_RECORD_ENABLED = False Then Exit Sub
Try
Dim control As Control = DirectCast(sender, Control)
Dim controlId As Integer = DirectCast(control.Tag, ClassControlMetadata).Id
CONTROL_ID = controlId
If CONTROL_ID = 29 Then
Console.WriteLine("Obacht")
End If
'SQL für abhängige Auswahllisten
Dim SQL As String = String.Format("SELECT GUID, SQL_COMMAND_1 FROM TBPMO_CONTROL WHERE SQL_COMMAND_1 LIKE '%@{0}@%'", controlId)
Dim value
'SQL für enable control
Dim SQLenable As String = String.Format("SELECT GUID, SQL_COMMAND_2 FROM TBPMO_CONTROL WHERE SQL_COMMAND_2 LIKE '%@{0}@%'", controlId)
' Diese Befehle führen dazu, dass auch der ValueMember als Wert ausgelesen wird
' Das kann zu unerwarteten Ergebnissen führen, da der Benutzer nur den DisplayMember sieht.
'Select Case control.GetType()
' Case GetType(CustomComboBox)
' If IsNothing(DirectCast(control, CustomComboBox).ValueMember) Then
' value = DirectCast(control, CustomComboBox).Text
' Else
' value = DirectCast(control, CustomComboBox).SelectedValue
' End If
' Case Else
' Exit Sub
'End Select
' Die bessere Lösung ist für jetzt, einfach den angezeigten Wert auszulesen:
value = DirectCast(control, CustomComboBox).Text
If String.IsNullOrEmpty(value) Then
Exit Sub
End If
If CURRENT_RECORD_ID = 0 And CtrlCommandUI.IsInsert = True Then
Exit Sub
End If
Dim datatable As DataTable = ClassDatabase.Return_Datatable(SQL)
Dim datatable1 As DataTable = ClassDatabase.Return_Datatable(SQLenable)
Depending_Controls(control, datatable, value)
Enable_Controls(control, datatable1, value)
'Dim sqlcommand As String = datatable.Rows(0).Item("SQL_COMMAND_1")
'If IsNothing(sqlcommand) Then
' Exit Sub
'End If
'If String.IsNullOrEmpty(value) Then
' Exit Sub
'End If
'Dim regex As New System.Text.RegularExpressions.Regex("(@(\d+)@)")
'Dim match As System.Text.RegularExpressions.Match = regex.Match(sqlcommand)
'If match.Success Then
' ' DependingControlId bezeichnet das Control, das die Abhängigkeit enthält
' Dim dependingControlId As Integer = datatable.Rows(0).Item("GUID")
' Dim panel As Panel = DirectCast(control.Parent, Panel)
' ' Über die Id das Control finden
' Dim dependingControl As CustomComboBox = panel.Controls.OfType(Of CustomComboBox)().Where(Function(c As CustomComboBox)
' Return DirectCast(c.Tag, ClassControlMetadata).Id = dependingControlId
' End Function).SingleOrDefault()
' sqlcommand = sqlcommand.Replace(match.Groups(1).Value, value)
' Console.WriteLine("Executing SQL_COMMAND: {0}", sqlcommand)
' Dim dt As DataTable = ClassDatabase.Return_Datatable(sqlcommand)
' ControlLoader.Combobox.SetDataSource(dependingControl, dt)
'End If
Console.WriteLine("value changed")
Catch ex As Exception
If ex.Message.Contains("Objektverweis") Or ex.Message.Contains("reference not set") Then
Else
MsgBox("Error in OnComboBoxValueChanged - " & CONTROL_ID.ToString & ": " & ex.Message, MsgBoxStyle.Critical)
End If
End Try
End Sub
Public Sub CheckBoxChanged(sender As Object, ByVal e As EventArgs)
If CURRENT_RECORD_ENABLED = False Then Exit Sub
Try
Dim control As Control = DirectCast(sender, Control)
Dim controlId As Integer = DirectCast(control.Tag, ClassControlMetadata).Id
CONTROL_ID = controlId
Dim checkstate
'SQL für enable control
Dim SQLenable As String = String.Format("SELECT GUID, SQL_COMMAND_2 FROM TBPMO_CONTROL WHERE SQL_COMMAND_2 LIKE '%@{0}@%'", controlId)
Try
' Den CheckState setzen
checkstate = DirectCast(control, CheckBox).Checked
Catch ex As Exception
Exit Sub
End Try
If CURRENT_RECORD_ID = 0 And CtrlCommandUI.IsInsert = True Then
Exit Sub
End If
Dim datatable1 As DataTable = ClassDatabase.Return_Datatable(SQLenable)
Enable_Controls(control, datatable1, checkstate)
'Dim sqlcommand As String = datatable.Rows(0).Item("SQL_COMMAND_1")
@@ -403,7 +544,7 @@ Public Class ClassControlBuilder
Dim checkbox As CheckBox = CType(control, CheckBox)
AddHandler checkbox.CheckedChanged, AddressOf RecordChanged
AddHandler checkbox.EnabledChanged, AddressOf OnEnabledChanged
AddHandler checkbox.CheckedChanged, AddressOf CheckBoxChanged
Case "PictureBox"
Dim picturebox As PictureBox = CType(control, PictureBox)
AddHandler picturebox.BackgroundImageChanged, AddressOf RecordChanged