100 lines
3.5 KiB
VB.net
100 lines
3.5 KiB
VB.net
Imports System.Windows.Forms
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Namespace Modules
|
|
''' <summary>
|
|
''' Patterns for control values on a panel
|
|
''' </summary>
|
|
Public Class Controls
|
|
Inherits BaseModule
|
|
Implements IModule
|
|
|
|
Public Const CTRL_VALUE_PANEL = "CTRL_VALUE_PANEL"
|
|
|
|
Public Property PatternIdentifier As String = "CTRL" Implements IModule.PatternIdentifier
|
|
Public Property IsComplex As Boolean = True Implements IModule.IsComplex
|
|
|
|
Public Sub New(pLogConfig As LogConfig)
|
|
MyBase.New(pLogConfig)
|
|
End Sub
|
|
|
|
Public Function Replace(pInput As String, pPanel As Panel) As String
|
|
Dim oControls As List(Of Control) = pPanel.Controls.Cast(Of Control).ToList()
|
|
Return Replace(pInput, oControls)
|
|
End Function
|
|
|
|
Public Function Replace(pInput As String, pControls As List(Of Control)) As String
|
|
Dim oResult = pInput
|
|
Dim oCounter = 0
|
|
|
|
While ContainsPattern(oResult, PatternIdentifier)
|
|
Try
|
|
Dim oControlName As String = GetNextPattern(oResult, PatternIdentifier).Value
|
|
|
|
Dim oControl As Control = pControls.
|
|
Where(Function(control) control.Name = oControlName).
|
|
FirstOrDefault()
|
|
|
|
If oControl IsNot Nothing Then
|
|
Dim oReplaceValue As String
|
|
|
|
If TryGetDevExpressCheckEditValue(oControl, oReplaceValue) Then
|
|
' value already determined by helper
|
|
Else
|
|
Select Case True
|
|
Case TypeOf oControl Is TextBox
|
|
oReplaceValue = oControl.Text
|
|
|
|
Case TypeOf oControl Is ComboBox
|
|
oReplaceValue = oControl.Text
|
|
|
|
Case TypeOf oControl Is CheckBox
|
|
Dim oCheckBox As CheckBox = DirectCast(oControl, CheckBox)
|
|
oReplaceValue = oCheckBox.Checked.ToString()
|
|
|
|
Case Else
|
|
oReplaceValue = "0"
|
|
End Select
|
|
End If
|
|
|
|
oResult = ReplacePattern(oResult, PatternIdentifier, oReplaceValue)
|
|
Else
|
|
Logger.Warn("Control [{0}] was not found. Exiting.")
|
|
Exit While
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Finally
|
|
IncrementCounterOrThrow(oCounter)
|
|
End Try
|
|
|
|
End While
|
|
|
|
Return oResult
|
|
End Function
|
|
|
|
End Class
|
|
End Namespace
|
|
|
|
Module DevExpressCheckEditCompatibility
|
|
Friend Function TryGetDevExpressCheckEditValue(control As Control, ByRef value As String) As Boolean
|
|
If control Is Nothing Then
|
|
Return False
|
|
End If
|
|
|
|
Dim controlType = control.GetType()
|
|
If controlType.FullName <> "DevExpress.XtraEditors.CheckEdit" Then
|
|
Return False
|
|
End If
|
|
|
|
Dim checkedProperty = controlType.GetProperty("Checked")
|
|
If checkedProperty Is Nothing Then
|
|
Return False
|
|
End If
|
|
|
|
Dim checkedValue = checkedProperty.GetValue(control)
|
|
value = Convert.ToString(checkedValue, Globalization.CultureInfo.InvariantCulture)
|
|
Return True
|
|
End Function
|
|
End Module
|