161 lines
6.0 KiB
VB.net
161 lines
6.0 KiB
VB.net
Imports DevExpress.Utils
|
|
Imports DevExpress.XtraEditors
|
|
Imports DevExpress.XtraEditors.Controls
|
|
Imports DevExpress.XtraLayout
|
|
Imports DigitalData.Modules.Base
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Public Class ParameterLoader
|
|
Inherits BaseClass
|
|
|
|
Private Const LIST_CONTROL_NULL_TEXT As String = "Kein Wert ausgewählt"
|
|
|
|
Private Database As MSSQLServer
|
|
Private LayoutControl As LayoutControl
|
|
|
|
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pLayoutControl As LayoutControl)
|
|
MyBase.New(pLogConfig)
|
|
Database = pDatabase
|
|
LayoutControl = pLayoutControl
|
|
End Sub
|
|
|
|
Private Function GetDefaultValue(pParam As SearchParameter) As Object
|
|
Dim oResult As Object = Nothing
|
|
|
|
Select Case pParam.DataType
|
|
Case Constants.DataTypeEnum.Boolean
|
|
Boolean.TryParse(pParam.DefaultValue, oResult)
|
|
|
|
Case Constants.DataTypeEnum.Date
|
|
Date.TryParse(pParam.DefaultValue, oResult)
|
|
|
|
Case Constants.DataTypeEnum.Integer
|
|
Integer.TryParse(pParam.DefaultValue, oResult)
|
|
|
|
Case Else
|
|
oResult = pParam.DefaultValue
|
|
|
|
End Select
|
|
|
|
Return oResult
|
|
End Function
|
|
|
|
Public Sub LoadParameters(pSearch As Search)
|
|
For Each oParam As SearchParameter In pSearch.Parameters
|
|
Dim oControl As Control
|
|
|
|
Select Case oParam.DataType
|
|
Case Constants.DataTypeEnum.Boolean
|
|
Dim oDefaultValue As Boolean = GetDefaultValue(oParam)
|
|
Dim oCheckbox = New CheckEdit With {
|
|
.Text = oParam.Title,
|
|
.Checked = oDefaultValue
|
|
}
|
|
|
|
oControl = oCheckbox
|
|
|
|
|
|
Case Constants.DataTypeEnum.Date
|
|
Dim oDefaultValue As Date = GetDefaultValue(oParam)
|
|
|
|
If oDefaultValue = Date.MinValue Then
|
|
oDefaultValue = Now
|
|
End If
|
|
|
|
Dim oDateEdit As New DateEdit() With {
|
|
.EditValue = oDefaultValue
|
|
}
|
|
oDateEdit.Properties.ShowClear = False
|
|
|
|
oControl = oDateEdit
|
|
|
|
Case Constants.DataTypeEnum.String
|
|
Dim oDefaultValue As String = GetDefaultValue(oParam)
|
|
|
|
Select Case oParam.ItemType
|
|
Case Constants.ItemTypeEnum.List
|
|
Dim oCombobox = New ComboBoxEdit() With {
|
|
.Name = oParam.PatternTitle,
|
|
.Tag = oParam.PatternTitle,
|
|
.EditValue = oDefaultValue
|
|
}
|
|
Dim oClearButton = GetClearButtonForControl(oCombobox)
|
|
Dim oItems = oParam.ItemString.Split(";"c).ToList()
|
|
oCombobox.Properties.Items.AddRange(oItems)
|
|
oCombobox.Properties.NullText = LIST_CONTROL_NULL_TEXT
|
|
oCombobox.Properties.Buttons.Add(oClearButton)
|
|
oControl = oCombobox
|
|
|
|
Case Constants.ItemTypeEnum.SQL
|
|
Dim oGridCombobox = New LookUpEdit() With {
|
|
.Name = oParam.PatternTitle,
|
|
.Tag = oParam.PatternTitle,
|
|
.EditValue = oDefaultValue
|
|
}
|
|
Dim oClearButton = GetClearButtonForControl(oGridCombobox)
|
|
Dim oSQL = oParam.ItemString
|
|
Dim oTable = Database.GetDatatable(oSQL)
|
|
oGridCombobox.Properties.DataSource = oTable
|
|
oGridCombobox.Properties.DisplayMember = oTable.Columns.Item(0).ColumnName
|
|
oGridCombobox.Properties.ValueMember = oTable.Columns.Item(0).ColumnName
|
|
oGridCombobox.Properties.NullText = LIST_CONTROL_NULL_TEXT
|
|
oGridCombobox.Properties.Buttons.Add(oClearButton)
|
|
oControl = oGridCombobox
|
|
|
|
Case Else
|
|
oControl = New TextEdit() With {
|
|
.EditValue = oDefaultValue
|
|
}
|
|
End Select
|
|
|
|
Case Else
|
|
Dim oDefaultValue As Object = GetDefaultValue(oParam)
|
|
|
|
oControl = New TextEdit() With {
|
|
.EditValue = oDefaultValue
|
|
}
|
|
|
|
End Select
|
|
|
|
oControl.Name = oParam.PatternTitle
|
|
oControl.Tag = oParam.PatternTitle
|
|
|
|
Dim oItem As LayoutControlItem = LayoutControl.AddItem()
|
|
oItem.Text = oParam.Title
|
|
oItem.Control = oControl
|
|
oItem.TextLocation = Locations.Top
|
|
oItem.TextToControlDistance = 3
|
|
oItem.Padding = New DevExpress.XtraLayout.Utils.Padding(0, 0, 10, 0)
|
|
|
|
|
|
Next
|
|
End Sub
|
|
|
|
Private Function GetClearButtonForControl(pControl As Control) As EditorButton
|
|
Dim oClearButton As New EditorButton() With {
|
|
.Kind = ButtonPredefines.Clear,
|
|
.Tag = pControl.Name
|
|
}
|
|
AddHandler oClearButton.Click, AddressOf ClearButton_Click
|
|
Return oClearButton
|
|
End Function
|
|
|
|
Private Sub ClearButton_Click(sender As Object, e As EventArgs)
|
|
Dim oButton As EditorButton = sender
|
|
Dim oControlName As String = oButton.Tag.ToString
|
|
|
|
Dim oControl = LayoutControl.Controls.Find(oControlName, True).SingleOrDefault()
|
|
|
|
Select Case oControl.GetType
|
|
Case GetType(LookUpEdit)
|
|
DirectCast(oControl, LookUpEdit).EditValue = Nothing
|
|
|
|
Case GetType(ComboBoxEdit)
|
|
DirectCast(oControl, ComboBoxEdit).EditValue = Nothing
|
|
End Select
|
|
|
|
End Sub
|
|
End Class
|
|
|