2019-04-15 14:30:00 +02:00

107 lines
3.8 KiB
VB.net

Imports DevExpress.XtraEditors
Imports DevExpress.XtraLayout
Imports DigitalData.Controls.LookupGrid
Imports DigitalData.GUIs.ClientSuite.Base
Imports DigitalData.Modules.Logging
Namespace Controls
Public Class ControlLoader
Inherits BaseClass
Private _LayoutControlGroup As LayoutControlGroup
Private _LayoutControls As List(Of BaseEdit)
Public ReadOnly Property LayoutControls As List(Of BaseEdit)
Get
If _LayoutControls Is Nothing Then
_LayoutControls = New List(Of BaseEdit)
End If
Return _LayoutControls
End Get
End Property
Public Sub New(LogConfig As LogConfig, LayoutControlGroup As LayoutControlGroup)
MyBase.New(LogConfig)
_LayoutControlGroup = LayoutControlGroup
End Sub
Public Sub AddControl(Name As String, Value As String, LayoutControlGroup As LayoutControlGroup)
Dim oTextEdit As New SimpleLabelItem() With {
.Name = Name,
.Text = Name & " - " & Value
}
LayoutControlGroup.AddItem(oTextEdit)
End Sub
Public Sub AddControl(Name As String, Value As String)
AddControl(Name, Value, _LayoutControlGroup)
End Sub
Public Sub AddSeparator(LayoutControlGroup As LayoutControlGroup)
Dim oSeparator = New SimpleSeparator()
LayoutControlGroup.AddItem(oSeparator)
End Sub
Public Sub AddSeparator()
AddSeparator(_LayoutControlGroup)
End Sub
Public Sub LoadControls(Datatable As DataTable, LayoutControlGroup As LayoutControlGroup)
For Each oRow As DataRow In Datatable.Rows
Dim oCaption As String = oRow.Item("COLNAME")
Dim oControlType As String = oRow.Item("CTRLTYPE")
Dim oControlId As Int64 = oRow.Item("RECORD_ID")
Dim oEditor As BaseEdit = CreateLayoutControl(oControlType, oControlId, oControlId)
If oEditor Is Nothing Then
Continue For
End If
oEditor.Tag = New Metadata() With {
.Id = oControlId,
.Type = oControlType,
.Caption = oCaption
}
LayoutControls.Add(oEditor)
LayoutControlGroup.AddItem(oCaption, oEditor)
Next
LayoutControlGroup.AddItem(New EmptySpaceItem())
End Sub
Public Sub LoadControls(Datatable As DataTable)
LoadControls(Datatable, _LayoutControlGroup)
End Sub
Public Function CreateLayoutControl(Type As String, Name As String, Id As Int64)
Dim oEditor As BaseEdit = Nothing
Logger.Debug("Create new Control of type {0} with name {1}", Type, Name)
Select Case Type
Case ClassConstants.CONTROL_TEXTEDIT
Dim oTextEdit As New TextEdit() With {.Name = Name}
oEditor = oTextEdit
Case ClassConstants.CONTROL_MEMOEDIT
Dim oMemoEdit As New MemoEdit() With {.Name = Name}
oEditor = oMemoEdit
Case ClassConstants.CONTROL_DATEEDIT
Dim oDateEdit As New DateEdit() With {.Name = Name}
oEditor = oDateEdit
Case ClassConstants.CONTROL_CHECKEDIT
Dim oCheckEdit As New CheckEdit() With {.Name = Name}
oEditor = oCheckEdit
Case ClassConstants.CONTROL_COMBOEDIT
Dim oComboEdit As New LookupControl2() With {.Name = Name}
oEditor = oComboEdit
Case Else
oEditor = Nothing
End Select
Return oEditor
End Function
End Class
End Namespace