jj_04_01_16
This commit is contained in:
254
app/DD-Record-Organiser/ClassControlLoader.vb
Normal file
254
app/DD-Record-Organiser/ClassControlLoader.vb
Normal file
@@ -0,0 +1,254 @@
|
||||
Namespace ControlLoader
|
||||
|
||||
Public Class _BaseControl
|
||||
End Class
|
||||
|
||||
Public Class _ListControl : Inherits _BaseControl
|
||||
Public Shared Function _GetDynamicValue(controlId As Integer, formId As Integer, recordId As Integer, parentRecordId As Integer) As DynamicValue
|
||||
Dim returnValue As DynamicValue
|
||||
|
||||
returnValue.StaticList = CheckForStaticList(controlId, recordId)
|
||||
returnValue.DataTable = CheckForSqlCommand(controlId, formId, recordId, parentRecordId)
|
||||
|
||||
Return returnValue
|
||||
End Function
|
||||
|
||||
Private Shared Function CheckForStaticList(controlId As Integer, recordId As Integer) As List(Of String)
|
||||
Try
|
||||
Dim SQL As String = String.Format("SELECT VALUE FROM VWPMO_VALUES WHERE CONTROL_ID = {0} AND RECORD_ID = {1}", controlId, recordId)
|
||||
Dim staticList As String = ClassDatabase.Execute_Scalar(SQL)
|
||||
|
||||
If IsNothing(staticList) Then
|
||||
Return Nothing
|
||||
Else
|
||||
Return New List(Of String)(staticList.Split(";"))
|
||||
End If
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in CheckForStaticList: " & vbNewLine & ex.Message)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Shared Function CheckForSqlCommand(controlId As Integer, formId As Integer, recordId As Integer, parentRecordId As Integer) As DataTable
|
||||
Try
|
||||
Dim SQL As String = String.Format("SELECT SQL_COMMAND_1 FROM TBPMO_CONTROL WHERE GUID = {0}", controlId)
|
||||
Dim SqlCommand As String = ClassDatabase.Execute_Scalar(SQL)
|
||||
|
||||
If SqlCommand Is Nothing Or SqlCommand = String.Empty Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
If SqlCommand.Contains("@") Then
|
||||
SqlCommand = ReplaceSqlCommandPlaceholders(SqlCommand, recordId, parentRecordId)
|
||||
End If
|
||||
|
||||
Dim CachedDataTable As DataTable = ClassControlValueCache.LoadFromCache(formId, controlId)
|
||||
Dim FinalDataTable As DataTable
|
||||
If CachedDataTable Is Nothing Then
|
||||
FinalDataTable = ClassDatabase.Return_Datatable(SqlCommand)
|
||||
ClassControlValueCache.SaveToCache(formId, controlId, FinalDataTable)
|
||||
Else
|
||||
FinalDataTable = CachedDataTable
|
||||
End If
|
||||
|
||||
Return FinalDataTable
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in CheckForSqlCommand: " & vbNewLine & ex.Message)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private 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
|
||||
End Class
|
||||
|
||||
Public Structure DynamicValue
|
||||
Public StaticList As List(Of String)
|
||||
Public DataTable As DataTable
|
||||
End Structure
|
||||
|
||||
Public Class Label : Inherits _BaseControl
|
||||
|
||||
Public Shared Sub LoadValue(control As Windows.Forms.Label, value As String)
|
||||
' TODO: LoadControlAutoValue aufrufen
|
||||
control.Text = value
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Public Class Checkbox : Inherits _BaseControl
|
||||
|
||||
Public Shared Sub LoadValue(control As Windows.Forms.CheckBox, value As String)
|
||||
Dim result As Boolean = False
|
||||
Boolean.TryParse(value, result)
|
||||
control.Checked = result
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Public Class RadioButton : Inherits _BaseControl
|
||||
|
||||
Public Shared Sub LoadValue(control As Windows.Forms.RadioButton, value As String)
|
||||
Dim result As Boolean = False
|
||||
Boolean.TryParse(value, result)
|
||||
control.Checked = result
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Public Class TextBox : Inherits _BaseControl
|
||||
|
||||
Public Shared Sub LoadValue(control As Windows.Forms.TextBox, value As String)
|
||||
control.Text = value
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Public Class DateTimePicker : Inherits _BaseControl
|
||||
|
||||
Public Shared Sub LoadValue(control As DevExpress.XtraEditors.DateEdit, value As String)
|
||||
If String.IsNullOrWhiteSpace(value) Or value = "00:00:00" Then
|
||||
control.DateTime = DateTime.MinValue
|
||||
Else
|
||||
control.DateTime = DateTime.Parse(value)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Public Class Combobox : Inherits _ListControl
|
||||
|
||||
Public Shared Sub LoadValue(control As Windows.Forms.ComboBox, value As String)
|
||||
control.Text = value
|
||||
End Sub
|
||||
|
||||
Public Shared Sub LoadList(control As Windows.Forms.ComboBox, formId As Integer, recordId As Integer, parentRecordId As Integer)
|
||||
Try
|
||||
Dim dynamic As DynamicValue = _GetDynamicValue(control.Tag, formId, recordId, parentRecordId)
|
||||
|
||||
If dynamic.StaticList IsNot Nothing Then
|
||||
control.DataSource = dynamic.StaticList
|
||||
End If
|
||||
|
||||
If dynamic.DataTable IsNot Nothing AndAlso dynamic.DataTable.Rows.Count > 0 Then
|
||||
Dim dt As DataTable = dynamic.DataTable
|
||||
|
||||
control.DataSource = dt
|
||||
If dt.Columns.Count = 1 Then
|
||||
control.DisplayMember = dt.Columns(0).ColumnName
|
||||
control.ValueMember = dt.Columns(0).ColumnName
|
||||
ElseIf dt.Columns.Count = 2 Then
|
||||
control.DisplayMember = dt.Columns(1).ColumnName
|
||||
control.ValueMember = dt.Columns(0).ColumnName
|
||||
End If
|
||||
|
||||
CalculateDropdownWidth(control, dt)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in Combobox.LoadList:" & vbNewLine & ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Shared Sub CalculateDropdownWidth(control As Windows.Forms.ComboBox, dt As DataTable)
|
||||
Const WIDEST_WIDTH As Integer = 300
|
||||
Dim FinalWidth As Integer = WIDEST_WIDTH
|
||||
For Each row As DataRow In dt.Rows
|
||||
'Die Breite der Dropdown-List anpassen
|
||||
Using g As Graphics = control.CreateGraphics()
|
||||
Dim valueWidth As Integer = g.MeasureString(row.Item(1).ToString(), control.Font).Width
|
||||
If valueWidth + 30 > FinalWidth Then
|
||||
FinalWidth = valueWidth + 30
|
||||
End If
|
||||
g.Dispose()
|
||||
End Using
|
||||
Next
|
||||
|
||||
If FinalWidth > WIDEST_WIDTH Then
|
||||
control.DropDownWidth = Math.Max(FinalWidth, control.Width)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Public Class CheckedListBox : Inherits _ListControl
|
||||
|
||||
Public Shared Sub LoadValue(control As DevExpress.XtraEditors.CheckedListBoxControl, value As String)
|
||||
|
||||
For Each item As String In control.Items
|
||||
|
||||
Dim pos = control.FindStringExact(value)
|
||||
control.SetItemCheckState(pos, CheckState.Checked)
|
||||
|
||||
Next
|
||||
|
||||
End Sub
|
||||
|
||||
Public Shared Sub LoadList(control As DevExpress.XtraEditors.CheckedListBoxControl, formId As Integer, recordId As Integer, parentRecordId As Integer)
|
||||
Try
|
||||
Dim dynamic As DynamicValue = _GetDynamicValue(control.Tag, formId, recordId, parentRecordId)
|
||||
|
||||
If dynamic.StaticList IsNot Nothing Then
|
||||
control.DataSource = dynamic.StaticList
|
||||
|
||||
'For Each item As String In dynamic.StaticList
|
||||
' Dim pos = control.FindStringExact(item)
|
||||
' control.SetItemCheckState(pos, CheckState.Checked)
|
||||
'Next
|
||||
End If
|
||||
|
||||
If dynamic.DataTable IsNot Nothing AndAlso dynamic.DataTable.Rows.Count > 0 Then
|
||||
Dim dt As DataTable = dynamic.DataTable
|
||||
|
||||
control.DataSource = dt
|
||||
If dt.Columns.Count = 1 Then
|
||||
control.DisplayMember = dt.Columns(0).ColumnName
|
||||
control.ValueMember = dt.Columns(0).ColumnName
|
||||
ElseIf dt.Columns.Count = 2 Then
|
||||
control.DisplayMember = dt.Columns(1).ColumnName
|
||||
control.ValueMember = dt.Columns(0).ColumnName
|
||||
End If
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in CheckedListBox.LoadList:" & vbNewLine & ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Public Class ListBox : Inherits _ListControl
|
||||
|
||||
Public Shared Sub LoadValue(control As DevExpress.XtraEditors.ListBoxControl, value As String)
|
||||
control.SelectedIndex = control.FindStringExact(value)
|
||||
End Sub
|
||||
|
||||
Public Shared Sub LoadList(control As DevExpress.XtraEditors.ListBoxControl, formId As Integer, recordId As Integer, parentRecordId As Integer)
|
||||
Dim dynamic As DynamicValue = _GetDynamicValue(control.Tag, formId, recordId, parentRecordId)
|
||||
|
||||
If dynamic.StaticList IsNot Nothing Then
|
||||
control.DataSource = dynamic.StaticList
|
||||
End If
|
||||
|
||||
If dynamic.DataTable IsNot Nothing AndAlso dynamic.DataTable.Rows.Count > 0 Then
|
||||
Dim dt As DataTable = dynamic.DataTable
|
||||
|
||||
control.DataSource = dt
|
||||
If dt.Columns.Count = 1 Then
|
||||
control.DisplayMember = dt.Columns(0).ColumnName
|
||||
control.ValueMember = dt.Columns(0).ColumnName
|
||||
ElseIf dt.Columns.Count = 2 Then
|
||||
control.DisplayMember = dt.Columns(1).ColumnName
|
||||
control.ValueMember = dt.Columns(0).ColumnName
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user