jj 19_01_16

This commit is contained in:
JenneJ
2016-01-19 15:07:04 +01:00
parent 85fccc233b
commit 5c014d3173
8 changed files with 240 additions and 362 deletions

View File

@@ -1,139 +1,9 @@
Imports DevExpress.XtraEditors.Controls
Public Class ClassControlValues
'Private Shared Function LoadControlAutoValue(ControlID As Integer, RecordID As Integer, control As Control) As String
' If TypeOf control Is Label Then
' Dim SQL = "SELECT SQL_COMMAND_1 FROM TBPMO_CONTROL WHERE GUID = " & ControlID
' Dim autoValue
' Dim result = ClassDatabase.Execute_Scalar(SQL)
' result = result.Replace("@FORM_ID", CURRENT_FORM_ID)
' result = result.Replace("@RECORD_ID", CURRENT_RECORD_ID)
' result = result.Replace("@RECORDID", CURRENT_RECORD_ID)
' result = result.Replace("@PARENTRECORD_ID", CURRENT_PARENTID)
' ' Wenn das SQL Command leer ist, hat dieses Control kein SQL Command
' ' Gib den ursprünlichen Text zurück
' If result = "" Then
' Return control.Text
' Else
' autoValue = ClassDatabase.Execute_Scalar(result)
' ' Wenn das SQL Command DBNull zurück gibt,
' ' Überschreibe den alten Wert mit " " (Leerzeichen)
' If IsDBNull(autoValue) Then
' SQL = "SELECT CONTROL_TEXT FROM TBPMO_CONTROL_SCREEN WHERE CONTROL_ID = " & ControlID
' Dim value = ClassDatabase.Execute_Scalar(SQL)
' Return value
' Else
' Return autoValue
' End If
' End If
' 'End If
' 'Return Nothing
' Else
' Return Nothing
' End If
'End Function
'Public Shared Sub LoadControlValue(RecordID As Integer, ControlID As Integer, control As Control)
' Try
' ' Dim DT1 As DataTable = ClassDatabase.Return_Datatable()
' Dim DT As DataTable = ClassDatabase.Return_Datatable("SELECT * FROM VWPMO_VALUES WHERE RECORD_ID = " & RecordID & " and CONTROL_ID = " & ControlID, "LaodControlValue: ReturnValues")
' If DT.Rows.Count = 0 Then
' Dim autoValue = LoadControlAutoValue(ControlID, RecordID, control)
' If Not String.IsNullOrEmpty(autoValue) Then
' control.Text = autoValue
' End If
' Exit Sub
' End If
' Dim result = DT.Rows(0).Item("VALUE")
' '22.06.2015
' If Not IsDBNull(result) Then
' Select Case DT.Rows(0).Item("CONTROL_TYPE_ID")
' Case 1 'Label
' Dim label As Label = DirectCast(control, Label)
' Dim autoValue As String = LoadControlAutoValue(ControlID, RecordID, control)
' If Not IsNothing(autoValue) Then
' label.Text = autoValue
' End If
' Case 2 ' TextBox
' Dim textbox As TextBox = DirectCast(control, TextBox)
' textbox.Text = result
' Case 10 ' CheckBox
' Dim checkbox As CheckBox = DirectCast(control, CheckBox)
' checkbox.Checked = CBool(result)
' Case 11 'RadioButton
' Dim radio As RadioButton = DirectCast(control, RadioButton)
' radio.Checked = CBool(result)
' Case 3 ' ComboBox
' Dim cmbbox As ComboBox = DirectCast(control, System.Windows.Forms.ComboBox)
' cmbbox.Text = result
' 'If LogErrorsOnly = False Then ClassLogger.Add(">> control ComboBox", False)
' 'Dim cmbSql As String = "SELECT SQL_COMMAND_1 FROM TBPMO_CONTROL WHERE GUID = " & ControlID
' 'cmbSql = ClassDatabase.Execute_Scalar(cmbSql)
' 'If Not (cmbSql Is Nothing Or cmbSql = String.Empty) Then
' ' If cmbSql.ToString.Contains("@") Then
' ' cmbSql = cmbSql.ToString.Replace("@RECORDID", CURRENT_RECORD_ID)
' ' cmbSql = cmbSql.ToString.Replace("@RECORD_ID", CURRENT_RECORD_ID)
' ' cmbSql = cmbSql.ToString.Replace("@PARENTRECORD_ID", CURRENT_PARENTID)
' ' If LogErrorsOnly = False Then ClassLogger.Add(">> SQL Combobox: " & cmbSql, False)
' ' End If
' ' If LogErrorsOnly = False Then ClassLogger.Add(">> SQL Combobox: " & cmbSql, False)
' ' 'SQL-Command vorhanden also Ausführen des SQL
' ' Dim DT_ComboBox As DataTable = ClassDatabase.Return_Datatable(cmbSql, "LoadControlValues: Combobox")
' ' If DT_ComboBox Is Nothing = False Then
' ' cmbbox.DataSource = DT_ComboBox
' ' Select Case DT_ComboBox.Columns.Count
' ' Case 2
' ' cmbbox.DisplayMember = DT_ComboBox.Columns(1).ColumnName
' ' cmbbox.ValueMember = DT_ComboBox.Columns(0).ColumnName
' ' Case 1
' ' cmbbox.DisplayMember = DT_ComboBox.Columns(0).ColumnName
' ' cmbbox.ValueMember = DT_ComboBox.Columns(0).ColumnName
' ' End Select
' ' End If
' 'End If
' ''combobox.DataSource = Nothing
' 'If cmbbox.SelectedIndex = -1 Then
' ' cmbbox.DataSource = Nothing
' ' cmbbox.Text = result
' 'Else
' ' cmbbox.SelectedIndex = cmbbox.FindStringExact(result)
' 'End If
' Case 4 'DateTimePicker
' Dim datepicker As DevExpress.XtraEditors.DateEdit = DirectCast(control, DevExpress.XtraEditors.DateEdit)
' If result = "" Or result = "00:00:00" Then
' datepicker.DateTime = DateTime.MinValue
' Else
' datepicker.DateTime = Date.Parse(result)
' End If
' Case 13 ' Listbox
' Dim listbox As DevExpress.XtraEditors.ListBoxControl = DirectCast(control, DevExpress.XtraEditors.ListBoxControl)
' listbox.SelectedIndex = listbox.FindStringExact(result)
' Case Else
' If LogErrorsOnly = False Then ClassLogger.Add(">> Sub LoadControlValue - Control-Type nicht berücksichtigt: " & DT.Rows(0).Item("CONTROL_TYPE_ID"), False)
' 'MsgBox(DT.Rows(0).Item("CONTROL_TYPE_ID"))
' End Select
' Else
' ClassLogger.Add(" >> Achtung, der Value für Control-ID: " & ControlID & " ist DBNull", False)
' End If
' Catch ex As Exception
' MsgBox("Error in LoadControlValue:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
' End Try
'End Sub
#Region "#### ClassControlValues REWRITE ####"
Public Shared Sub LoadControlValuesNeu(RecordId As Integer, ParentRecordId As Integer, FormId As Integer, controls As Control.ControlCollection)
Public Shared Sub LoadControlValues(RecordId As Integer, ParentRecordId As Integer, FormId As Integer, controls As Control.ControlCollection)
Try
'Dim SQL As String = String.Format("SELECT * FROM VWPMO_VALUES WHERE VALUE <> '' AND RECORD_ID = {0}", RecordId)
Dim SQL As String = String.Format("SELECT * FROM VWPMO_VALUES WHERE RECORD_ID = {0}", RecordId)
@@ -156,7 +26,7 @@ Public Class ClassControlValues
If TypeOf control Is GroupBox Then
Dim groupbox As GroupBox = DirectCast(control, GroupBox)
LoadControlValuesNeu(RecordId, ParentRecordId, FormId, groupbox.Controls)
LoadControlValues(RecordId, ParentRecordId, FormId, groupbox.Controls)
Else
LoadControlValueNeu(RecordId, ParentRecordId, ControlId, control, value)
End If
@@ -216,29 +86,47 @@ Public Class ClassControlValues
End Sub
#End Region
Public Shared Sub LoadControlValuesList(RecordID As Integer, ParentRecordId As Integer, FormID As Integer, controls As Control.ControlCollection)
Public Shared Sub LoadControlValuesList(FormID As Integer, controls As Control.ControlCollection)
Try
If controls.Count = 0 Then
MsgBox("Control.ControlCollection is unexpected empty!", MsgBoxStyle.Exclamation)
'MsgBox("LoadControlValuesList: Control.ControlCollection is unexpected empty!", MsgBoxStyle.Exclamation)
ClassLogger.Add("LoadControlValuesList: Control.ControlCollection is unexpected empty!")
Exit Sub
End If
Dim SW As Stopwatch = Stopwatch.StartNew()
' Zuerst alle SQL Commands für FormID finden
' CONTROL_SQLCOMMAND_1 wird als SQL gealiast
Dim SQL As String = String.Format("SELECT CONTROL_ID, CONTROL_SQLCOMMAND_1 AS SQL FROM VWPMO_CONTROL_SCREEN WHERE FORM_ID = {0} AND CONTROL_SQLCOMMAND_1 <> '' AND CONTROL_SQLCOMMAND_1 NOT LIKE '%@%'", FormID)
Dim dt As DataTable = ClassDatabase.Return_Datatable(SQL)
If dt.Rows.Count = 0 Then
Exit Sub
End If
For Each Ctrl As Control In controls
Dim controlTagId = CInt(Ctrl.Tag)
'Datatable nach row mit CONTROL_ID wie Ctrl suchen
Dim row As DataRow = dt.Select(String.Format("CONTROL_ID={0}", controlTagId)).FirstOrDefault()
If IsNothing(row) Then
Continue For
End If
Dim sqlcommand As String = row.Item("SQL")
Select Case Ctrl.GetType()
Case GetType(ComboBox)
Dim combobox = DirectCast(Ctrl, ComboBox)
ControlLoader.Combobox.LoadList(combobox, FormID, RecordID, ParentRecordId)
ControlLoader.Combobox.LoadList(combobox, FormID, sqlcommand)
Case GetType(DevExpress.XtraEditors.ListBoxControl)
Dim listbox = DirectCast(Ctrl, DevExpress.XtraEditors.ListBoxControl)
ControlLoader.ListBox.LoadList(listbox, FormID, RecordID, ParentRecordId)
ControlLoader.ListBox.LoadList(listbox, FormID, sqlcommand)
Case GetType(DevExpress.XtraEditors.CheckedListBoxControl)
Dim chlistbox = DirectCast(Ctrl, DevExpress.XtraEditors.CheckedListBoxControl)
ControlLoader.CheckedListBox.LoadList(chlistbox, FormID, RecordID, ParentRecordId)
ControlLoader.CheckedListBox.LoadList(chlistbox, FormID, sqlcommand)
End Select
Next
@@ -253,6 +141,66 @@ Public Class ClassControlValues
End Sub
Public Shared Sub LoadControlValuesListWithPlaceholders(FormId As Integer, RecordId As Integer, ParentRecordId As Integer, controls As Control.ControlCollection)
Try
If controls.Count = 0 Then
'MsgBox("LoadControlValuesListWithPlaceholders: Control.ControlCollection is unexpected empty!", MsgBoxStyle.Exclamation)
ClassLogger.Add("LoadControlValuesListWithPlaceholders: Control.ControlCollection is unexpected empty!")
Exit Sub
End If
Dim SQL As String = String.Format("SELECT CONTROL_ID, CONTROL_SQLCOMMAND_1 AS SQL FROM VWPMO_CONTROL_SCREEN WHERE FORM_ID = {0} AND CONTROL_SQLCOMMAND_1 <> '' AND CONTROL_SQLCOMMAND_1 LIKE '%@%'", FormId)
Dim SW As Stopwatch = Stopwatch.StartNew()
Dim commands As New List(Of String)
Dim dt As DataTable = ClassDatabase.Return_Datatable(SQL)
If dt.Rows.Count = 0 Then
Exit Sub
End If
For Each Ctrl As Control In controls
Dim controlTagId = CInt(Ctrl.Tag)
Dim row As DataRow = dt.Select(String.Format("CONTROL_ID={0}", controlTagId)).FirstOrDefault()
If IsNothing(row) Then
Continue For
End If
Dim sqlcommand As String = row.Item("SQL")
sqlcommand = ReplaceSqlCommandPlaceholders(sqlcommand, RecordId, ParentRecordId)
Select Case Ctrl.GetType()
Case GetType(ComboBox)
Dim combobox = DirectCast(Ctrl, ComboBox)
ControlLoader.Combobox.LoadList(combobox, FormId, sqlcommand)
Case GetType(DevExpress.XtraEditors.ListBoxControl)
Dim listbox = DirectCast(Ctrl, DevExpress.XtraEditors.ListBoxControl)
ControlLoader.ListBox.LoadList(listbox, FormId, sqlcommand)
Case GetType(DevExpress.XtraEditors.CheckedListBoxControl)
Dim chlistbox = DirectCast(Ctrl, DevExpress.XtraEditors.CheckedListBoxControl)
ControlLoader.CheckedListBox.LoadList(chlistbox, FormId, sqlcommand)
End Select
Next
SW.Stop()
Console.WriteLine("LoadControlValuesListWithPlaceholders took {0} milliseconds to load", SW.ElapsedMilliseconds)
Catch ex As Exception
MsgBox("Unexpected Error in LoadControlValuesListWithPlaceholders:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Public Shared Function ReplaceSqlCommandPlaceholders(sqlCommand As String, recordId As Integer, parentRecordId As Integer)
sqlCommand = sqlCommand.Replace("@RECORD_ID", recordId)
sqlCommand = sqlCommand.Replace("@RECORDID", recordId)
sqlCommand = sqlCommand.Replace("@PARENTRECORD_ID", parentRecordId)
sqlCommand = sqlCommand.Replace("@PARENTRECORDID", parentRecordId)
Return sqlCommand
End Function
Public Shared Sub UnloadControlValuesList(RecordID As Integer, FormID As Integer, controls As Control.ControlCollection)
For Each C As Control In controls
If TypeOf C Is ComboBox Then