Files
EgtDOORCreator/DoorParameters/Compo.vb
T
Nicola Pievani 6073472bee EgtDOORCreator :
- lettura dei file DDF con la gestione dei principali errori
- scrittura del file DDF con le componenti già "impilate" e nell'ordine corretto
2017-02-10 12:37:25 +00:00

596 lines
28 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
' dalla scelta TemplateSelItem genero la lista di parametri
Private m_TemplateSelItem As String
Public Property TemplateSelItem As String
Get
Return m_TemplateSelItem
End Get
' aggiorno la lista dei parametri
Set(value As String)
Dim CurrItemPath As String = m_CompoType.Path & "\" & value
' se il file ha estensione nge
If Path.HasExtension(CurrItemPath) AndAlso Path.GetExtension(CurrItemPath).ToLower = ".nge" Then
' controllo che esiste il file altrimenti esco
If Not File.Exists(CurrItemPath) Then Return
m_TemplateSelItem = value
' creo la stringa che contiene la lista degli errori
Dim ErrorList As String = String.Empty
Dim ParamIndex As Integer = 1
Dim sParam As String = String.Empty
Dim NewCompoParam As CompoParam = Nothing
' ricerco la parola chiave Param nella stringa nel file Cinfig.ini
While EgtUILib.GetPrivateProfileString(S_NGECONFIG, K_PARAM & ParamIndex, "", sParam, m_CompoType.Path & "\" & CONFIGINI_FILE_NAME) > 0
If Not String.IsNullOrWhiteSpace(sParam) Then
' leggo il tipo di parametro
ReadParam(sParam, NewCompoParam, ErrorList)
' carico il parametro nella lista della componente
InsertCompoParam(NewCompoParam, ParamIndex)
End If
ParamIndex += 1
End While
Else
' se il file non ha estensione allora creo l'estensione .lua
CurrItemPath &= ".lua"
' controllo che esiste il file altrimenti esco
If Not File.Exists(CurrItemPath) Then Return
m_TemplateSelItem = value
' carico un vettore con le stringhe del file corrente
Dim ReadCurrCompo() As String = File.ReadAllLines(CurrItemPath)
' creo la stringa che contiene la lista degli errori
Dim ErrorList As String = String.Empty
' leggo il vettore di stringhe del file corrente
For LineIndex = 0 To ReadCurrCompo.Count - 1
' copio il valore della riga
Dim CurrCompoFileLine As String = ReadCurrCompo(LineIndex)
' cerco il titolo [Graphic parameters]
If RegexFunction.IsGraphicParametersTitle(CurrCompoFileLine) Then
Dim ParamIndex As Integer = 1
Dim NewCompoParam As CompoParam = Nothing
Dim bIsFinished As Boolean = False
While Not bIsFinished
' attualizzo il componente a nulla
NewCompoParam = Nothing
' cerco nella riga successiva al titolo il primo parametro
If Not String.IsNullOrWhiteSpace(ReadCurrCompo(LineIndex + ParamIndex)) Then
Dim ReadLine As String
' carico i valori della stringa che seguono la chiave "--Param1="
ReadLine = ParamLine(ReadCurrCompo(LineIndex + ParamIndex), "Param" & ParamIndex)
' se uno dei paraemtri è completamente sbagliato allora restituisce falso e non riempo la NewCompoParam che rimane Nothing
bIsFinished = Not ReadParam(ReadLine, NewCompoParam, ErrorList)
Else
' altrimenti se la riga è vuota mi sposto alla successiva
LineIndex += 1
' e continuo il ciclo while
Continue While
End If
' insrisco la nuova componenenet: se la riga è vuota o la componente non è stata creata allora il componete è Nothing
InsertCompoParam(NewCompoParam, ParamIndex)
' se il parametro è stato creato passa alla riga successiva
If Not bIsFinished Then ParamIndex += 1
End While
' esiste già una lista
For DeleteIndex = m_CompoParamList.Count - 1 To ParamIndex - 1 Step -1
m_CompoParamList.RemoveAt(DeleteIndex)
Next
Exit For
End If
Next
End If
End Set
End Property
' inserisco il parametro letto nella lista dei paramtri senza modificare i parametri già esistenti
Private Sub InsertCompoParam(NewCompoParam As CompoParam, ParamIndex As Integer)
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
End Sub
' leggo il nome DDF e il nome, restituisco il nome solo se esiste un messaggio associato
Private Function MsgContol(sDDFName As String, sName As String, ByRef sErrorList As String) As String
'If IsNumeric(sName) Then
' se è numerico ma non esiste un messaggio associato
Dim ErrorMsg As String = "Msg" & Trim(sName)
If String.Equals(Utility.ReadMsg(sName), ErrorMsg) Then
Return sDDFName
Else
' restituisco il messaggio letto
Return Utility.ReadMsg(sName)
sErrorList &= String.Format("Error reading name {0} param in {1} compo: does not exist.", sName, m_CompoType.DDFName)
End If
End Function
' lettura del parametro passato dalla riga del file aperto
Private Function ReadParam(sReadLine As String, ByRef NewCompoParam As CompoParam, sErrorList As String) As Boolean
If Not String.IsNullOrWhiteSpace(sReadLine) Then
' carico un vettore con i valori della stringa
Dim sItems() As String = sReadLine.Split(";"c)
' se esistono almeno due elementi "ComboBox; NomeDDF"
If sItems.Count > 1 Then
' il primo elemento del vettore disti gue tre categorie
Select Case sItems(0)
Case "ComboBox"
' se la combobox contiene almeno un elemento "ComboBox; NomeDDF; Nome; NomeDDFItem/NomeItem"
If sItems.Count >= 4 Then
' carico gli elementi della lista in un vettore
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
Dim ComboItem() As String = sComboItemList(ItemIndex).Split("/"c)
' se esiste il NomeDDF e il Nome allora separo
If ComboItem.Count = 2 Then
' carico la lista con i nomi DDF
DDFComboItemList.Add(ComboItem(0))
' carico la lista con i nomi
ComboItemList.Add(MsgContol(ComboItem(0), ComboItem(1), sErrorList))
Else
' se esiste solo un nome considero sia il nome DDF
ComboItemList.Add(ComboItem(0))
' Errore nella lettura del nome: manca la definizione del nome nella lingua corrente
sErrorList &= String.Format("Error reading name {0} param in {1} compo.", ComboItem(0), m_CompoType.DDFName)
End If
Next
NewCompoParam = New ComboBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), ComboItemList, DDFComboItemList, ComboItemList(0))
Return True
Else
' non esiste una lista di nemmeno un elemento
sErrorList &= String.Format("Error reading {0} param in {1} compo: do not exist.", sItems(1), m_CompoType.DDFName)
Return False
End If
Case "TextBox"
Dim dHeight As Double
' leggo il valore altezza che già esite nella porta
StringToDouble(m_rfCurrDoor.Height, dHeight)
Dim dDefaultValue As Double
' verifico che sono presenti "TextBox; NomeDDF; Nome"
If sItems.Count >= 3 Then
' verifico che sono presenti "TextBox; NomeDDF; Nome; Valore"
If sItems.Count >= 4 Then
' se converto il valore in double
sItems(3) = Replace(sItems(3).ToUpper, "TH", "(" & m_rfCurrDoor.Thickness & ")")
StringToDouble(sItems(3), dDefaultValue)
Dim sDefaultValue As String = DoubleToString(dDefaultValue, -3)
' verifico che la misura letta sia minore dell'altezza della porta
If dDefaultValue < dHeight Then
' verifico che sono presenti "TextBox; NomeDDF; Nome; Valore; NomeLista; NomeElementoLista"
If sItems.Count > 5 Then
' creo la lista associata alla TextBox se esiste almeno un elemento
Dim DDFComboValuelList As New List(Of String)
' carico gli elementi della lista in un vettore
Dim sComboItemList() As String = sItems(5).Split(","c)
' carico la lista dal vettore
For ItemIndex = 0 To sComboItemList.Count - 1
DDFComboValuelList.Add(sComboItemList(ItemIndex))
Next
' cerco nella lista dei paraletri già esistenti il nome della lista a cui fa riferimento
For ParamIndex = 0 To m_CompoParamList.Count - 1
Dim CurrCompoParam As CompoParam = m_CompoParamList(ParamIndex)
' verifico che il nome della lista associata esista
If CurrCompoParam.DDFName = sItems(4) Then
' verifico che il nome del paramertro è di una combobox
If TypeOf CurrCompoParam Is ComboBoxParam Then
' creo la componente nuova
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), Utility.ReadMsg(sItems(2)), sErrorList), sDefaultValue, DirectCast(CurrCompoParam, ComboBoxParam), DDFComboValuelList)
Return True
Else
' se esiste il nome della lista associata ma non è una combobox creo il componente senza la lista
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, Nothing, Nothing)
sErrorList &= String.Format("Error reading {0} param in {1} compo.", sItems(4), m_CompoType.DDFName)
Return True
End If
Exit For
End If
Next
' se non trovo nella lista dei parametri il nome della lista creo il componente senza la lista
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, Nothing, Nothing)
sErrorList &= String.Format("Error reading {0} param in {1} compo: do not exist.", sItems(4), m_CompoType.DDFName)
Return True
ElseIf sItems.Count = 5 Then
'se non esiste una lista ma solo il nome della lista
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, Nothing, Nothing)
sErrorList &= String.Format("Error reading {0} param in {1} compo: do not exist list", sItems(4), m_CompoType.DDFName)
Return True
ElseIf sItems.Count = 4 Then
' se la text contiente solo 4 parametri
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, Nothing, Nothing)
Return True
End If
Else
' se la misura passata è più grande di quella della porta non carico il valore e creo il parametro senza lista
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), "0.000", Nothing, Nothing)
sItems(2) = MsgContol(sItems(1), sItems(2), sErrorList)
sErrorList &= String.Format("Error reading {0} param in {1} compo: {2}.", sItems(2), m_CompoType.DDFName, sDefaultValue)
' ma faccio andare avanti nella lettura dei parametri
Return True
End If
Else
' se la stringa ha 3 elemtni "TextBox; NomeDDF; Nome"
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), "0.000", Nothing, Nothing)
sItems(2) = MsgContol(sItems(1), sItems(2), sErrorList)
sErrorList &= String.Format("Error reading {0} param in {1} compo: do not exist value.", sItems(2), m_CompoType.DDFName)
Return True
End If
Else
' se ha solo 2 elementi "TextBox; NomeDDF"
NewCompoParam = Nothing
sErrorList &= String.Format("Error reading {0} param in {1} compo.", sItems(1), m_CompoType.DDFName)
Return False
End If
Case "TextBoxOnOff"
Dim dHeight As Double
' leggo il valore altezza che già esite nella porta
StringToDouble(m_rfCurrDoor.Height, dHeight)
Dim dItem As Double
' verifico che sono presenti "TextBox; NomeDDF; Nome"
Dim dDefaultValue As Double
If sItems.Count >= 3 Then
' verifico che sono presenti "TextBox; NomeDDF; Nome; Valore"
If sItems.Count >= 4 Then
sItems(3) = Replace(sItems(3).ToUpper, "TH", "(" & m_rfCurrDoor.Thickness & ")")
StringToDouble(sItems(3), dDefaultValue)
Dim sDefaultValue As String = DoubleToString(dDefaultValue, -3)
' converto il valore in double
StringToDouble(sItems(3), dItem)
' verifico che la misura letta sia minore dell'altezza della porta
If dDefaultValue < dHeight Then
' verifico che sono presenti "TextBox; NomeDDF; Nome; Valore; NomeLista; NomeElementoLista"
If sItems.Count > 5 Then
' creo la lista associata alla TextBox se esiste almeno un elemento
Dim DDFComboValuelList As New List(Of String)
' carico gli elementi della lista in un vettore
Dim sComboItemList() As String = sItems(5).Split(","c)
' carico la lista dal vettore
For ItemIndex = 0 To sComboItemList.Count - 1
DDFComboValuelList.Add(sComboItemList(ItemIndex))
Next
' cerco nella lista dei paraletri già esistenti il nome della lista a cui fa riferimento
For ParamIndex = 0 To m_CompoParamList.Count - 1
Dim CurrCompoParam As CompoParam = m_CompoParamList(ParamIndex)
' verifico che il nome della lista associata esista
If CurrCompoParam.DDFName = sItems(4) Then
' verifico che il nome del paramertro è di una combobox
If TypeOf CurrCompoParam Is ComboBoxParam Then
' creo la componente nuova
NewCompoParam = New TextBoxOnOffParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, DirectCast(CurrCompoParam, ComboBoxParam), DDFComboValuelList)
Return True
Else
' se esiste il nome della lista associata ma non è una combobox creo il componente senza la lista
NewCompoParam = New TextBoxOnOffParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, Nothing, Nothing)
Return True
End If
Exit For
End If
Next
' se non trovo nella lista dei parametri il nome della lista creo il componente senza la lista
NewCompoParam = New TextBoxOnOffParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, Nothing, Nothing)
Return True
ElseIf sItems.Count = 5 Then
'se non esiste una lista ma solo il nome della lista
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, Nothing, Nothing)
sErrorList &= String.Format("Error reading {0} param in {1} compo: do not exist list", sItems(4), m_CompoType.DDFName)
Return True
ElseIf sItems.Count = 4 Then
' se la text contiente solo 4 parametri
NewCompoParam = New TextBoxParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), sDefaultValue, Nothing, Nothing)
Return True
End If
Else
' se la misura passata è più grande di quella della porta non carico il valore e creo il parametro senza lista
NewCompoParam = New TextBoxOnOffParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), "0", Nothing, Nothing)
If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine
sErrorList &= String.Format("Error reading {0} param in {1} compo.", sItems(1), m_CompoType.DDFName)
' ma faccio andare avanti nella lettura dei parametri
Return True
End If
Else
' se la stringa ha 3 elemtni "TextBox; NomeDDF; Nome"
NewCompoParam = New TextBoxOnOffParam(sItems(1), MsgContol(sItems(1), sItems(2), sErrorList), "0", Nothing, Nothing)
Return True
End If
Else
' se ha solo 2 elementi "TextBox; NomeDDF"
NewCompoParam = Nothing
If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine
sErrorList &= String.Format("Error reading {0} param in {1} compo.", sItems(1), m_CompoType.DDFName)
Return False
End If
End Select
Else
' se non è nessuno dei casi precedenti del select case
sErrorList &= String.Format("Erron in compo {0} param {1}: do not exist.", m_CompoType.DDFName, sItems(0))
Return True
End If
End If
' creo la stringa di errore
If Not String.IsNullOrEmpty(sErrorList) Then
sErrorList &= Environment.NewLine
sErrorList &= sErrorList
Else
sErrorList &= sErrorList
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, sValue As String, ComboBox As ComboBoxParam, ComboValuelList As List(Of String))
MyBase.New(sDDFName, sName)
m_Value = sValue
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), sSelItem As String)
MyBase.New(sDDFName, sName)
m_ItemList = ItemList
m_ItemListDDF = ItemListDDF
m_SelItem = sSelItem
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, sValue As String, ComboBox As ComboBoxParam, ComboValuelList As List(Of String))
MyBase.New(sDDFName, sName, sValue, ComboBox, ComboValuelList)
End Sub
End Class