摘要:LIBClassNew.vb - ClassFormControlSetting

"ClassFormControlSetting"#Region "ClassFormControlSetting" ' Used in : Forgot
' History :
' 2009-09-03 : Developing
Public Class ClassFormControlSetting

Private mDictionary As New Dictionary() mDictionary As New Dictionary(Of String, Object) 
Private mDictionaryEnable As New Dictionary() mDictionaryEnable As New Dictionary(Of String, Object)

"SaveControlSetting"#Region "SaveControlSetting" 
Public Sub SaveControlSetting() Sub SaveControlSetting(ByVal pform As System.Windows.Forms.Form)
Try
mDictionary.Clear()
mDictionaryEnable.Clear()
Call nsControl.FormControlSearch(pform.Controls, AddressOf bSaveControl)
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub 
Private Function bSaveControl() Function bSaveControl(ByVal pControl As Control) As Boolean
Try
If TypeOf pControl Is C1.Win.C1List.C1Combo Then
mDictionaryEnable.Add(pControl.Name, pControl.Enabled)
mDictionary.Add(pControl.Name, pControl.Text)
ElseIf TypeOf pControl Is DateTimePicker Then
mDictionaryEnable.Add(pControl.Name, pControl.Enabled)
mDictionary.Add(pControl.Name, pControl.Text)
ElseIf TypeOf pControl Is TextBox Then
mDictionaryEnable.Add(pControl.Name, pControl.Enabled)
mDictionary.Add(pControl.Name, pControl.Text)
ElseIf TypeOf pControl Is CheckBox Then
mDictionaryEnable.Add(pControl.Name, pControl.Enabled)
Dim lchkBox As CheckBox = pControl
mDictionary.Add(pControl.Name, lchkBox.Checked)
ElseIf TypeOf pControl Is RadioButton Then
mDictionaryEnable.Add(pControl.Name, pControl.Enabled)
Dim loptBox As RadioButton = pControl
mDictionary.Add(pControl.Name, loptBox.Checked)
ElseIf TypeOf pControl Is Label Then
mDictionaryEnable.Add(pControl.Name, pControl.Enabled)
mDictionary.Add(pControl.Name, pControl.Text)
End If
Catch Err As Exception
Debug.Print(Me.GetType.ToString & " - " & Err.ToString)
End Try
End Function
#End Region

"LoadControlSetting"#Region "LoadControlSetting" 
Public Sub LoadControlSetting() Sub LoadControlSetting(ByVal pform As System.Windows.Forms.Form)
Try
Call nsControl.FormControlSearch(pform.Controls, AddressOf bLoadControl)
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub 
Private Function bLoadControl() Function bLoadControl(ByVal pControl As Control) As Boolean
Try
If TypeOf pControl Is C1.Win.C1List.C1Combo Then
pControl.Enabled = mDictionaryEnable.Item(pControl.Name)
pControl.Text = mDictionary.Item(pControl.Name)
ElseIf TypeOf pControl Is DateTimePicker Then
pControl.Enabled = mDictionaryEnable.Item(pControl.Name)
Dim ldtPicker As DateTimePicker = pControl
ldtPicker.Text = mDictionary.Item(pControl.Name)
ldtPicker.Checked = False
ElseIf TypeOf pControl Is TextBox Then
pControl.Enabled = mDictionaryEnable.Item(pControl.Name)
pControl.Text = mDictionary.Item(pControl.Name)
ElseIf TypeOf pControl Is CheckBox Then
pControl.Enabled = mDictionaryEnable.Item(pControl.Name)
Dim lchkBox As CheckBox = pControl
lchkBox.Checked = mDictionary.Item(lchkBox.Name)
ElseIf TypeOf pControl Is RadioButton Then
pControl.Enabled = mDictionaryEnable.Item(pControl.Name)
Dim loptBox As RadioButton = pControl
loptBox.Checked = mDictionary.Item(loptBox.Name)
ElseIf TypeOf pControl Is Label Then
pControl.Enabled = mDictionaryEnable.Item(pControl.Name)
pControl.Text = mDictionary.Item(pControl.Name)
End If
Catch Err As Exception
Debug.Print(Me.GetType.ToString & " - " & Err.ToString)
End Try
End Function
#End Region

"bIsControlChanged"#Region "bIsControlChanged" 
Public Function bIsControlChanged() Function bIsControlChanged(ByVal pform As System.Windows.Forms.Form) As Boolean
bIsControlChanged = False
Try
bIsControlChanged = nsControl.bFormControlSearch(pform.Controls, AddressOf bCompareControl)
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Function 
Private Function bCompareControl() Function bCompareControl(ByVal pControl As Control) As Boolean
Try
If TypeOf pControl Is C1.Win.C1List.C1Combo Then
If pControl.Enabled <> mDictionaryEnable.Item(pControl.Name) Then
bCompareControl = True
Exit Function
End If
If pControl.Text <> mDictionary.Item(pControl.Name) Then
bCompareControl = True
Exit Function
End If
ElseIf TypeOf pControl Is DateTimePicker Then
If pControl.Text <> mDictionary.Item(pControl.Name) Then
bCompareControl = True
Exit Function
End If
ElseIf TypeOf pControl Is TextBox Then
If pControl.Enabled <> mDictionaryEnable.Item(pControl.Name) Then
bCompareControl = True
Exit Function
End If
If pControl.Text <> mDictionary.Item(pControl.Name) Then
bCompareControl = True
Exit Function
End If
ElseIf TypeOf pControl Is CheckBox Then
If pControl.Enabled <> mDictionaryEnable.Item(pControl.Name) Then
bCompareControl = True
Exit Function
End If
Dim lchkBox As CheckBox = pControl
If lchkBox.Checked <> mDictionary.Item(lchkBox.Name) Then
bCompareControl = True
Exit Function
End If
ElseIf TypeOf pControl Is RadioButton Then
If pControl.Enabled <> mDictionaryEnable.Item(pControl.Name) Then
bCompareControl = True
Exit Function
End If
Dim loptBox As RadioButton = pControl
If loptBox.Checked <> mDictionary.Item(loptBox.Name) Then
bCompareControl = True
Exit Function
End If
End If
Catch Err As Exception
Debug.Print(Me.GetType.ToString & " - " & Err.ToString)
End Try
End Function
#End Region
End Class
#End Region

"nsControl"#Region "nsControl"
Namespace nsControl
Public Module mControl 
Public Sub FormAutoClose() Sub FormAutoClose(ByVal pform As Form, Optional ByVal piTimeOutInSecond As Integer = 60)
Try
Dim ClsAutoCloseFrom As New ClassAutoCloseFrom
ClsAutoCloseFrom.SetFrom(pform)
ClsAutoCloseFrom.SetTimerInterval(piTimeOutInSecond)
ClsAutoCloseFrom.StartTimer()
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub 
Public Sub FormAutoClose() Sub FormAutoClose(ByVal pform As Form, ByVal pFunc As DFunc0, Optional ByVal piTimeOutInSecond As Integer = 60)
Try
Dim ClsAutoCloseFrom As New ClassAutoCloseFrom
ClsAutoCloseFrom.SetFunc(pFunc)
ClsAutoCloseFrom.SetFrom(pform)
ClsAutoCloseFrom.SetTimerInterval(piTimeOutInSecond)
ClsAutoCloseFrom.StartTimer()
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub 
Public Sub FormControlSearch() Sub FormControlSearch(ByVal pControls As System.Windows.Forms.Control.ControlCollection, ByVal pDFunc1 As DFunc1)
Try
For Each lcControl As Control In pControls
If lcControl.Controls.Count > 0 Then
Call pDFunc1(lcControl)
Call FormControlSearch(lcControl.Controls, pDFunc1)
Else
Call pDFunc1(lcControl)
End If
Next
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub 
Public Function bFormControlSearch() Function bFormControlSearch(ByVal pControls As System.Windows.Forms.Control.ControlCollection, ByVal pDFunc1 As DFunc1) As Boolean
bFormControlSearch = False
Try
For Each lcControl As Control In pControls
If lcControl.Controls.Count > 0 Then
If pDFunc1(lcControl) = False Then Exit Function
Call FormControlSearch(lcControl.Controls, pDFunc1)
Else
If pDFunc1(lcControl) = False Then Exit Function
End If
Next
bFormControlSearch = True
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Function
End Module
End Namespace
#End Region
------------------
熱愛生命 喜愛新奇 有趣的事物
過去 是無法改變
將來 卻能夠創造
希望使大家生活更便利
世界更美好
a guy who loves IT and life