Files
EgtDOORCreator/DoorParameters/Compo.vb
T
Nicola Pievani aa367c4345 EgtDOORCreator :
- Passaggio a lettura intestazione file DDF per avere i parametri dei componenti.
2017-02-02 09:17:03 +00:00

419 lines
15 KiB
VB.net

Imports System.ComponentModel
Imports System.Collections.ObjectModel
Imports System.IO
Public Class Compo
Implements INotifyPropertyChanged
Friend m_rfCurrDoor As Door
Private m_CompoType As CompoType
Public ReadOnly Property CompoType As CompoType
Get
Return m_CompoType
End Get
End Property
#Region "Template ComboBox"
Private m_TemplateName As String
Public Property TemplateName As String
Get
Return m_TemplateName
End Get
Set(value As String)
m_TemplateName = value
End Set
End Property
Private m_TemplateDDFName As String
Public Property TemplateDDFName As String
Get
Return m_TemplateDDFName
End Get
Set(value As String)
m_TemplateDDFName = value
End Set
End Property
Private m_TemplateItemList As New List(Of String)
Public Property TemplateItemList As List(Of String)
Get
Return m_TemplateItemList
End Get
Set(value As List(Of String))
m_TemplateItemList = value
End Set
End Property
Private m_TemplateSelItem As String
Public Property TemplateSelItem As String
Get
Return m_TemplateSelItem
End Get
Set(value As String)
Dim CurrItemPath As String = m_CompoType.Path & "\" & value
If Not Path.HasExtension(CurrItemPath) Then
CurrItemPath &= ".lua"
End If
If Not File.Exists(CurrItemPath) Then Return
m_TemplateSelItem = value
Dim ReadCurrCompo() As String = File.ReadAllLines(CurrItemPath)
' creo la stringa che contiene la lista degli errori
Dim ErrorList As String = String.Empty
For LineIndex = 0 To ReadCurrCompo.Count - 1
Dim CurrCompoFileLine As String = ReadCurrCompo(LineIndex)
If RegexFunction.IsGraphicParametersTitle(CurrCompoFileLine) Then
Dim ParamIndex As Integer = 1
Dim NewCompoParam As CompoParam = Nothing
Dim bIsFinished As Boolean = False
While Not bIsFinished
NewCompoParam = Nothing
If Not String.IsNullOrWhiteSpace(ReadCurrCompo(LineIndex + ParamIndex)) Then
bIsFinished = Not ReadParam(ReadCurrCompo(LineIndex + ParamIndex), ParamIndex, NewCompoParam, ErrorList)
Else
LineIndex += 1
Continue While
End If
If Not IsNothing(NewCompoParam) Then
' se non esiste l'indice
If Not m_CompoParamList.Count > ParamIndex - 1 Then
' creo il parametro combo
Me.CompoParamList.Insert(ParamIndex - 1, NewCompoParam)
Else
' se esiste ma è diverso il nome DDF
If Not m_CompoParamList(ParamIndex - 1).DDFName = NewCompoParam.DDFName Then
' creo il nuovo parametro combo
m_CompoParamList.RemoveAt(ParamIndex - 1)
m_CompoParamList.Insert(ParamIndex - 1, NewCompoParam)
End If
End If
End If
If Not bIsFinished Then ParamIndex += 1
End While
For DeleteIndex = m_CompoParamList.Count - 1 To ParamIndex - 1 Step -1
m_CompoParamList.RemoveAt(DeleteIndex)
Next
Exit For
End If
Next
End Set
End Property
Private Function ReadParam(sLine As String, nParamIndex As Integer, ByRef NewCompoParam As CompoParam, sErrorList As String) As Boolean
Dim ReadLine As String = ParamLine(sLine, "Param" & nParamIndex)
If Not String.IsNullOrWhiteSpace(ReadLine) Then
Dim sItems() As String = ReadLine.Split(";"c)
If sItems.Count > 0 Then
Select Case sItems(0)
Case "ComboBox"
If sItems.Count >= 4 Then
' carico gli elementi della lista
Dim sComboItemList() As String = sItems(3).Split(","c)
Dim ComboItemList As New List(Of String)
Dim DDFComboItemList As New List(Of String)
For ItemIndex = 0 To sComboItemList.Count - 1
' carico la lista con i nomi DDF
Dim ComboItem() As String = sComboItemList(ItemIndex).Split("/"c)
DDFComboItemList.Add(ComboItem(0))
ComboItemList.Add(Utility.ReadMsg(ComboItem(1)))
Next
NewCompoParam = New ComboBoxParam(sItems(1), Utility.ReadMsg(sItems(2)), ComboItemList, DDFComboItemList)
Return True
Else
sErrorList &= String.Format("Error reading {0} param in {1} compo.", sItems(1), m_CompoType.DDFName)
End If
Case "TextBox"
If sItems.Count >= 3 Then
If sItems.Count > 3 Then
Dim DDFComboValuelList As New List(Of String)
Dim sComboItemList() As String = sItems(4).Split(","c)
For ItemIndex = 0 To sComboItemList.Count - 1
DDFComboValuelList.Add(sComboItemList(ItemIndex))
Next
For ParamIndex = 0 To m_CompoParamList.Count - 1
Dim CurrCompoParam As CompoParam = m_CompoParamList(ParamIndex)
If CurrCompoParam.DDFName = sItems(3) Then
If TypeOf CurrCompoParam Is ComboBoxParam Then
NewCompoParam = New TextBoxParam(sItems(1), Utility.ReadMsg(sItems(2)), DirectCast(CurrCompoParam, ComboBoxParam), DDFComboValuelList)
Return True
Else
NewCompoParam = New TextBoxParam(sItems(1), Utility.ReadMsg(sItems(2)), Nothing, Nothing)
Return True
End If
Exit For
End If
Next
NewCompoParam = New TextBoxParam(sItems(1), Utility.ReadMsg(sItems(2)), Nothing, Nothing)
Return True
Else
NewCompoParam = New TextBoxParam(sItems(1), Utility.ReadMsg(sItems(2)), Nothing, Nothing)
Return True
End If
Else
If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine
sErrorList &= String.Format("Error reading {0} param in {1} compo.", sItems(1), m_CompoType.DDFName)
End If
Case "TextBoxOnOff"
If sItems.Count >= 3 Then
If sItems.Count > 3 Then
Dim DDFComboValuelList As New List(Of String)
Dim sComboItemList() As String = sItems(4).Split(","c)
For ItemIndex = 0 To sComboItemList.Count - 1
DDFComboValuelList.Add(sComboItemList(ItemIndex))
Next
For ParamIndex = 0 To m_CompoParamList.Count - 1
Dim CurrCompoParam As CompoParam = m_CompoParamList(ParamIndex)
If CurrCompoParam.DDFName = sItems(3) Then
If TypeOf CurrCompoParam Is ComboBoxParam Then
NewCompoParam = New TextBoxOnOffParam(sItems(1), Utility.ReadMsg(sItems(2)), DirectCast(CurrCompoParam, ComboBoxParam), DDFComboValuelList)
Return True
Else
NewCompoParam = New TextBoxOnOffParam(sItems(1), Utility.ReadMsg(sItems(2)), Nothing, Nothing)
Return True
End If
Exit For
End If
Next
NewCompoParam = New TextBoxOnOffParam(sItems(1), Utility.ReadMsg(sItems(2)), Nothing, Nothing)
Return True
Else
NewCompoParam = New TextBoxOnOffParam(sItems(1), Utility.ReadMsg(sItems(2)), Nothing, Nothing)
Return True
End If
Else
If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine
sErrorList &= String.Format("Error reading {0} param in {1} compo.", sItems(1), m_CompoType.DDFName)
End If
End Select
If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine
If sItems.Count >= 2 Then
sErrorList &= String.Format("Erron in compo {0} param {1}: type {2} do not exist.", m_CompoType.DDFName, sItems(1), sItems(0))
Else
sErrorList &= String.Format("Erron in compo {0}: type {1} do not exist.", m_CompoType.DDFName, sItems(0))
End If
Return True
End If
End If
Return False
End Function
Private m_TemplateVisibility As Visibility
Public Property TemplateVisibility As Visibility
Get
Return m_TemplateVisibility
End Get
Set(value As Visibility)
m_TemplateVisibility = value
End Set
End Property
#End Region ' Template ComboBox
Private m_CompoParamList As New ObservableCollection(Of CompoParam)
Public Property CompoParamList As ObservableCollection(Of CompoParam)
Get
Return m_CompoParamList
End Get
Set(value As ObservableCollection(Of CompoParam))
m_CompoParamList = value
End Set
End Property
' Definizione comando
Private m_CmdApply As ICommand
Private m_CmdDelete As ICommand
Sub New(CompoType As CompoType, MyDoor As Door)
m_CompoType = CompoType
m_rfCurrDoor = MyDoor
End Sub
#Region "COMMANDS"
#Region "ApplyCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property ApplyCommand As ICommand
Get
If m_CmdApply Is Nothing Then
m_CmdApply = New Command(AddressOf Apply)
End If
Return m_CmdApply
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub Apply()
'DdfFile.WriteDDF(m_rfCurrDoor, "c:\EgtData\EgtDOORCreator\Temp\CurrDoor.ddf")
End Sub
#End Region ' ApplyCommand
#Region "DeleteCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property DeleteCommand As ICommand
Get
If m_CmdDelete Is Nothing Then
m_CmdDelete = New Command(AddressOf Delete)
End If
Return m_CmdDelete
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub Delete()
m_rfCurrDoor.RemoveCompo(Me)
End Sub
#End Region ' DeleteCommand
#End Region 'Commands
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Sub NotifyPropertyChanged(propName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
End Sub
End Class
Public Class CompoParam
Private m_Name As String
Public Property Name As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Private m_DDFName As String
Public Property DDFName As String
Get
Return m_DDFName
End Get
Set(value As String)
m_DDFName = value
End Set
End Property
Sub New(sDDFName As String, sName As String)
m_DDFName = sDDFName
m_Name = sName
End Sub
End Class
Public Class TextBoxParam
Inherits CompoParam
Private m_Value As String
Public Property Value As String
Get
Return m_Value
End Get
Set(value As String)
m_Value = value
End Set
End Property
Private m_ComboValuelList As New List(Of String)
Public Property ComboValuelList As List(Of String)
Get
Return m_ComboValuelList
End Get
Set(value As List(Of String))
m_ComboValuelList = value
End Set
End Property
Private m_ComboBox As ComboBoxParam
Private m_Visibility As Visibility
Public Property Visibility As Visibility
Get
Return m_Visibility
End Get
Set(value As Visibility)
m_Visibility = value
End Set
End Property
Sub New(sDDFName As String, sName As String, ComboBox As ComboBoxParam, ComboValuelList As List(Of String))
MyBase.New(sDDFName, sName)
m_ComboBox = ComboBox
m_ComboValuelList = ComboValuelList
End Sub
End Class
Public Class ComboBoxParam
Inherits CompoParam
Private m_ItemList As New List(Of String)
Public Property ItemList As List(Of String)
Get
Return m_ItemList
End Get
Set(value As List(Of String))
m_ItemList = value
End Set
End Property
Private m_ItemListDDF As New List(Of String)
Public Property ItemListDDF As List(Of String)
Get
Return m_ItemListDDF
End Get
Set(value As List(Of String))
m_ItemListDDF = value
End Set
End Property
Private m_SelItem As String
Public Property SelItem As String
Get
Return m_SelItem
End Get
Set(value As String)
m_SelItem = value
End Set
End Property
Sub New(sDDFName As String, sName As String, ItemList As List(Of String), ItemListDDF As List(Of String))
MyBase.New(sDDFName, sName)
m_ItemList = ItemList
m_ItemListDDF = ItemListDDF
End Sub
End Class
Public Class TextBoxOnOffParam
Inherits TextBoxParam
Private m_IsActive As Boolean
Public Property IsActive As Boolean
Get
Return m_IsActive
End Get
Set(value As Boolean)
m_IsActive = value
End Set
End Property
Sub New(sDDFName As String, sName As String, ComboBox As ComboBoxParam, ComboValuelList As List(Of String))
MyBase.New(sDDFName, sName, ComboBox, ComboValuelList)
End Sub
End Class