6073472bee
- lettura dei file DDF con la gestione dei principali errori - scrittura del file DDF con le componenti già "impilate" e nell'ordine corretto
577 lines
29 KiB
VB.net
577 lines
29 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports System.Text.RegularExpressions
|
|
|
|
Friend Module DdfFile
|
|
Private m_rfMainWindowViewModel As MainWindowViewModel
|
|
|
|
' il vettore che conterrà tutti le linee del file DDF da leggere
|
|
Private FileContent As String()
|
|
' lista ordinata delle componenti da stampare
|
|
Friend CompoListOrder As New List(Of String)({"vision_cut_outs", "louver_cut_outs", "mail_slots", "viewers", "flush_pulls", "hinges", "locks", "flush_bolts", "edge_pulls", "roller_latchs", "pivots", "stops_and_closers", "oh_stop_close"})
|
|
|
|
#Region "LETTURA DDF"
|
|
' Genero una nuova porta da usare nella lettura di un DDF
|
|
Dim m_Door As New Door
|
|
' Leggo e stampo a video
|
|
Public Sub ReadDDF(sPathDDF As String, ByRef ReadDoor As Door)
|
|
m_Door = ReadDoor
|
|
' restituisce un problema nella lettura di un valore della compo
|
|
Dim InvalidValue As String = String.Empty
|
|
' controllo se esite il file DDF
|
|
If Not File.Exists(sPathDDF) Then Return
|
|
FileContent = File.ReadAllLines(sPathDDF)
|
|
' se il file esiste ma è vuoto
|
|
If FileContent.Count = 0 Then
|
|
MessageBox.Show("Empty file", EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
' leggo riga per riga
|
|
For LineIndex As Integer = 0 To FileContent.Count - 1
|
|
' size
|
|
If SearchKey(FileContent(LineIndex), K_SIZE) Then
|
|
LineIndex = GetSize(LineIndex + 1)
|
|
' se manca una parola chiave nel DDF
|
|
If LineIndex = -1 Then
|
|
' carico il messaggio di errore
|
|
InvalidValue += EgtMsg(50102) + K_SIZE + vbCrLf
|
|
' interrompo la lettura del file
|
|
Exit For
|
|
End If
|
|
End If
|
|
' swing
|
|
If SearchKey(FileContent(LineIndex), K_SWING) Then
|
|
LineIndex = GetSwing(LineIndex)
|
|
If LineIndex = -1 Then
|
|
InvalidValue += EgtMsg(50102) + K_SWING + vbCrLf
|
|
Exit For
|
|
End If
|
|
End If
|
|
' profiles
|
|
If SearchKey(FileContent(LineIndex), K_PROFILES) Then
|
|
LineIndex = GetProfiles(LineIndex + 1)
|
|
If LineIndex = -1 Then
|
|
InvalidValue += EgtMsg(50102) + K_PROFILES + vbCrLf
|
|
Exit For
|
|
End If
|
|
End If
|
|
|
|
' Compo
|
|
' se trovo un nome seguito dai due punti
|
|
If Not String.IsNullOrWhiteSpace(SearchName(FileContent(LineIndex))) Then
|
|
' carivo la stringa letta come nome DDF
|
|
Dim CompoNameDDF = SearchName(FileContent(LineIndex))
|
|
' passo la riga successiva e il nome DDF alla funzione che controlla se esiste e restituisce la riga successiva
|
|
LineIndex = GetNewCompo(LineIndex + 1, CompoNameDDF, InvalidValue)
|
|
ElseIf Not String.IsNullOrWhiteSpace(FileContent(LineIndex)) Then
|
|
If Not String.IsNullOrEmpty(InvalidValue) Then InvalidValue &= Environment.NewLine
|
|
InvalidValue &= String.Format("Error reading line {0}: ""{1}"" does not exist .", LineIndex, FileContent(LineIndex))
|
|
End If
|
|
Next
|
|
' quando finisce la lettura di tutte le righe esci dal ciclo
|
|
If Not String.IsNullOrWhiteSpace(InvalidValue) Then
|
|
MessageBox.Show(InvalidValue, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
End Sub
|
|
|
|
' restituisce il valore della stringa che precede i due punti
|
|
Friend Function SearchName(sLine As String) As String
|
|
Return Regex.Match(sLine, "\s*(.*?\b)\s*:.*").Groups(1).Value
|
|
End Function
|
|
|
|
' restituisce il trattino
|
|
Friend Function Score(sLine As String) As String
|
|
Return Regex.Match(sLine, "\s*(-)*\s*(.*?\b)\s*:.*").Groups(1).Value
|
|
End Function
|
|
|
|
' Cerca la stringa con il trattino
|
|
Friend Function SearchScore(sLine As String) As Boolean
|
|
If Regex.Match(sLine, "\s*(-).*$").Groups(1).Value = "-" Then Return True
|
|
Return False
|
|
End Function
|
|
|
|
' restituisce il nome compreso tra il trattino meno e i due punti
|
|
Friend Function SearchTemplate(sLine As String) As String
|
|
Return Regex.Match(sLine, "\s*-*\s*(.*?\b)\s*:.*$").Groups(1).Value
|
|
End Function
|
|
|
|
' restituisce la stringa dopo i due punti
|
|
Friend Function SearchKeyValue(sLine As String, sKey As String) As String
|
|
Return Regex.Match(sLine, "\s*-*\s*" & sKey & "\s*:\s*(.*?\b)\s*$").Groups(1).Value
|
|
End Function
|
|
|
|
' cerca il nome che precede i due punti
|
|
Friend Function SearchKey(sLine As String, sKey As String) As Boolean
|
|
If Not Regex.Match(sLine, "\s*(" & sKey & ")\s*:.*$").Groups(1).Value = sKey Then Return False
|
|
Return True
|
|
End Function
|
|
|
|
#Region "Carica il General della porta"
|
|
|
|
' carico valori di Size
|
|
Public Function GetSize(Index As Integer) As Integer
|
|
Dim Width As String = SearchKeyValue(FileContent(Index), K_WIDTH)
|
|
' se il valore restituito è nullo o vuoto
|
|
If String.IsNullOrWhiteSpace(Width) Then
|
|
' se non c'è la parola chiave allora esci
|
|
If Not SearchKey(FileContent(Index), K_WIDTH) Then Return -1
|
|
' altrimenti lascia il valore vuoto
|
|
Index += 1
|
|
Else
|
|
' carico il valore nella porta corrente
|
|
m_Door.Width = Width
|
|
' passo alla riga successiva
|
|
Index += 1
|
|
End If
|
|
Dim Height As String = SearchKeyValue(FileContent(Index), K_HEIGHT)
|
|
If String.IsNullOrWhiteSpace(Height) Then
|
|
If Not SearchKey(FileContent(Index), K_HEIGHT) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.Height = Height
|
|
Index += 1
|
|
End If
|
|
Dim Thickness As String = SearchKeyValue(FileContent(Index), K_THICKNESS)
|
|
If String.IsNullOrWhiteSpace(Thickness) Then
|
|
If Not SearchKey(FileContent(Index), K_THICKNESS) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.Thickness = Thickness
|
|
Index += 1
|
|
End If
|
|
' restituisco la riga successiva all'ultimo valore letto
|
|
Return Index
|
|
End Function
|
|
|
|
' carico valori swing
|
|
Public Function GetSwing(Index As Integer) As Integer
|
|
Dim Swing As String = SearchKeyValue(FileContent(Index), K_SWING)
|
|
' se il valore restituito è nullo o vuoto
|
|
If String.IsNullOrWhiteSpace(Swing) Then
|
|
' se non c'è la parola chiave allora esci
|
|
If Not SearchKey(FileContent(Index), K_SWING) Then Return -1
|
|
' altrimenti lascia il valore vuoto
|
|
Index += 1
|
|
Else
|
|
' carico il valore nella porta corrente
|
|
m_Door.Swing = Swing
|
|
' passo alla riga successiva
|
|
Index += 1
|
|
End If
|
|
' restituisco la riga successiva all'ultimo valore letto
|
|
Return Index
|
|
End Function
|
|
|
|
' carico valori profiles
|
|
Public Function GetProfiles(Index As Integer) As Integer
|
|
' Creo una stringa per scrivere gli errori
|
|
Dim ReadingError As String = String.Empty
|
|
' Lock
|
|
Dim LockEdgeType As String = SearchKeyValue(FileContent(Index), K_LOCKEDGE)
|
|
' se il valore restituito è nullo o vuoto
|
|
If String.IsNullOrWhiteSpace(LockEdgeType) Then
|
|
' se non c'è la parola chiave allora esci
|
|
If Not SearchKey(FileContent(Index), K_LOCKEDGE) Then Return -1
|
|
' altrimenti lascia il valore vuoto
|
|
Index += 1
|
|
Else
|
|
' carico il valore nella porta corrente
|
|
m_Door.LockEdgeType = LockEdgeType
|
|
' restituisco la riga successiva all'ultimo valore letto
|
|
Index += 1
|
|
End If
|
|
Dim LockEdgeMachining As String = SearchKeyValue(FileContent(Index), K_MACHINING)
|
|
If String.IsNullOrWhiteSpace(LockEdgeMachining) Then
|
|
If Not SearchKey(FileContent(Index), K_MACHINING) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.LockEdgeMachining = Utility.ConvertOnOffToBoolean(LockEdgeMachining)
|
|
Index += 1
|
|
End If
|
|
Dim LockEdgeOverMaterial As String = SearchKeyValue(FileContent(Index), K_OVERMATERAL)
|
|
If String.IsNullOrWhiteSpace(LockEdgeOverMaterial) Then
|
|
If Not SearchKey(FileContent(Index), K_OVERMATERAL) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.LockEdgeOverMaterial = LockEdgeOverMaterial
|
|
Index += 1
|
|
End If
|
|
|
|
' Hinge
|
|
Dim HingeEdgeType As String = SearchKeyValue(FileContent(Index), K_HINGEEDGE)
|
|
If String.IsNullOrWhiteSpace(HingeEdgeType) Then
|
|
If Not SearchKey(FileContent(Index), K_HINGEEDGE) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.HingeEdgeType = HingeEdgeType
|
|
Index += 1
|
|
End If
|
|
Dim HingeEdgeMachining As String = SearchKeyValue(FileContent(Index), K_MACHINING)
|
|
If String.IsNullOrWhiteSpace(HingeEdgeMachining) Then
|
|
If Not SearchKey(FileContent(Index), K_MACHINING) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.HingeEdgeMachining = ConvertOnOffToBoolean(HingeEdgeMachining)
|
|
Index += 1
|
|
End If
|
|
Dim HingeEdgeOverMaterial As String = SearchKeyValue(FileContent(Index), K_OVERMATERAL)
|
|
If String.IsNullOrWhiteSpace(HingeEdgeOverMaterial) Then
|
|
If Not SearchKey(FileContent(Index), K_OVERMATERAL) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.HingeEdgeOverMaterial = HingeEdgeOverMaterial
|
|
Index += 1
|
|
End If
|
|
|
|
' Top
|
|
Dim TopType As String = SearchKeyValue(FileContent(Index), K_TOP)
|
|
If String.IsNullOrWhiteSpace(TopType) Then
|
|
If Not SearchKey(FileContent(Index), K_TOP) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.TopType = TopType
|
|
Index += 1
|
|
End If
|
|
Dim TopMachining As String = SearchKeyValue(FileContent(Index), K_MACHINING)
|
|
If String.IsNullOrWhiteSpace(TopMachining) Then
|
|
If Not SearchKey(FileContent(Index), K_MACHINING) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.TopMachining = ConvertOnOffToBoolean(TopMachining)
|
|
Index += 1
|
|
End If
|
|
Dim TopOverMaterial As String = SearchKeyValue(FileContent(Index), K_OVERMATERAL)
|
|
If String.IsNullOrWhiteSpace(TopOverMaterial) Then
|
|
If Not SearchKey(FileContent(Index), K_OVERMATERAL) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.TopOverMaterial = TopOverMaterial
|
|
Index += 1
|
|
End If
|
|
|
|
' Bottom
|
|
Dim BottomType As String = SearchKeyValue(FileContent(Index), K_BOTTOM)
|
|
If String.IsNullOrWhiteSpace(BottomType) Then
|
|
If Not SearchKey(FileContent(Index), K_BOTTOM) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.BottomType = BottomType
|
|
Index += 1
|
|
End If
|
|
|
|
Dim BottomMachining As String = SearchKeyValue(FileContent(Index), K_MACHINING)
|
|
If String.IsNullOrWhiteSpace(BottomMachining) Then
|
|
If Not SearchKey(FileContent(Index), K_MACHINING) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.BottomMachining = ConvertOnOffToBoolean(BottomMachining)
|
|
Index += 1
|
|
End If
|
|
|
|
Dim BottomOverMaterial As String = SearchKeyValue(FileContent(Index), K_OVERMATERAL)
|
|
If String.IsNullOrWhiteSpace(BottomOverMaterial) Then
|
|
If Not SearchKey(FileContent(Index), K_OVERMATERAL) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.BottomOverMaterial = BottomOverMaterial
|
|
Index += 1
|
|
End If
|
|
' restituisco la riga successiva all'ultimo valore letto
|
|
Return Index
|
|
End Function
|
|
|
|
#End Region ' Carica il General della porta
|
|
|
|
' ricerco la compo nella lista dei compobtn
|
|
Public Function GetNewCompo(Index As Integer, CompoNameDDF As String, ByRef InvalidValue As String) As Integer
|
|
Dim bDDFName As Boolean = False
|
|
Dim bCompo As Boolean = False
|
|
Dim NewCompoIndex As Integer = Nothing
|
|
' controllo che il nome passato esiste nella lista delle componenti
|
|
Dim CompoListIndex As Integer
|
|
' se la stringa ha un trattino ipotizzo che il nome della componente sia lo stesso dell'ultima componente inserita
|
|
If Not String.IsNullOrWhiteSpace(Score(FileContent(Index - 1))) Then
|
|
CompoNameDDF = m_Door.m_CompoList.Last.CompoType.DDFName
|
|
Index -= 1
|
|
End If
|
|
|
|
For CompoListIndex = 0 To CompoPanelViewModel.CompoTypeList.Count() - 1
|
|
' se il nome esite
|
|
If CompoPanelViewModel.CompoTypeList(CompoListIndex).DDFName = CompoNameDDF Then
|
|
bDDFName = True
|
|
' inizializzo l'idice della lista delle componenti che sto per creare
|
|
NewCompoIndex = -1
|
|
' passo alla lettura delle righe successive
|
|
While Index < FileContent.Count AndAlso Not String.IsNullOrWhiteSpace(FileContent(Index))
|
|
|
|
' controllo che la stringa abbia i due punti: se non ha i due punti
|
|
If String.IsNullOrWhiteSpace(SearchName(FileContent(Index))) Then
|
|
If Not String.IsNullOrEmpty(InvalidValue) Then InvalidValue &= Environment.NewLine
|
|
InvalidValue &= String.Format("Error reading line {0}: ""{1}"".", Index, FileContent(Index))
|
|
' esco dalla lettura della compo
|
|
Exit While
|
|
' se ha il trattino
|
|
Else
|
|
' creo la nuova componente
|
|
Dim m_CurrCompo = New Compo(CompoPanelViewModel.CompoTypeList(CompoListIndex), m_Door)
|
|
' Leggo il file ini del componente per vedere se c'è il template: se c'è
|
|
Dim CurrCompoTypePath As String = CompoPanelViewModel.CompoTypeList(CompoListIndex).Path
|
|
If EgtUILib.GetPrivateProfileInt(S_TEMPLATE, K_ISACTIVE, 1, CurrCompoTypePath & "\" & CONFIGINI_FILE_NAME) <> 0 Then
|
|
' leggo nomi
|
|
Dim Name As String = String.Empty
|
|
Dim DDFName As String = String.Empty
|
|
IniFile.GetPrivateProfileCompoName(S_TEMPLATE, K_NAME, DDFName, Name, CurrCompoTypePath & "\" & CONFIGINI_FILE_NAME)
|
|
Dim TemplateList As New List(Of String)
|
|
IniFile.OpenDirectory(CompoPanelViewModel.CompoTypeList(CompoListIndex).Path, TemplateList)
|
|
' aggiungo il template come parametro
|
|
m_CurrCompo.TemplateDDFName = DDFName
|
|
m_CurrCompo.TemplateName = Name
|
|
m_CurrCompo.TemplateItemList = TemplateList
|
|
|
|
' cercco il template associato al nome DDF come parola preceduta dl trattino "-"
|
|
If SearchScore(FileContent(Index)) Then
|
|
' leggo il valore del template e lo assegno alla componente che sto generando
|
|
m_CurrCompo.TemplateSelItem = SearchKeyValue(FileContent(Index), SearchTemplate(FileContent(Index)))
|
|
' se il template non ha nessun nome
|
|
If String.IsNullOrWhiteSpace(m_CurrCompo.TemplateSelItem) Then
|
|
' elimina la compo che stai creando
|
|
m_CurrCompo = Nothing
|
|
' ed esci dal ciclo while
|
|
Exit While
|
|
End If
|
|
'mi sposto nella riga successiva
|
|
Index += 1
|
|
' leggo i parametri della componente
|
|
ReadParam(m_CurrCompo, InvalidValue, Index)
|
|
' se creo la componente allora assegno vero
|
|
bCompo = True
|
|
Else
|
|
' restituisco la riga precedente alla funzione ReadDDF
|
|
Index -= 1
|
|
' se non ha il trattino (ma ha un template) esci dal ciclo
|
|
Exit While
|
|
End If
|
|
' la componente non ha template (louver_cut_outs)
|
|
Else
|
|
' nascondo il template
|
|
m_CurrCompo.TemplateVisibility = Visibility.Collapsed
|
|
' leggo il nome del compo dal file config.ini
|
|
Dim sTemplateName As String = String.Empty
|
|
' controllo il tipo di estensione del file (nome letto da Config.ini)
|
|
EgtUILib.GetPrivateProfileString(S_TEMPLATE, K_COMPO, "", sTemplateName, CurrCompoTypePath & "\" & CONFIGINI_FILE_NAME)
|
|
If String.IsNullOrWhiteSpace(sTemplateName) Then
|
|
If Not String.IsNullOrEmpty(InvalidValue) Then InvalidValue &= Environment.NewLine
|
|
InvalidValue &= String.Format("Error reading {0} param in {1} compo.", K_COMPO, m_CurrCompo.TemplateName)
|
|
m_CurrCompo = Nothing
|
|
ElseIf Not File.Exists(CurrCompoTypePath & "\" & sTemplateName & ".lua") Then
|
|
If Not String.IsNullOrEmpty(InvalidValue) Then InvalidValue &= Environment.NewLine
|
|
InvalidValue &= String.Format("Error reading {0} {1} compo.", K_COMPO, m_CurrCompo.TemplateName)
|
|
m_CurrCompo = Nothing
|
|
Else
|
|
' assegno il nome del tipo di componente
|
|
m_CurrCompo.TemplateSelItem = sTemplateName
|
|
ReadParam(m_CurrCompo, InvalidValue, Index)
|
|
' se creo la compo allora assegno vero
|
|
bCompo = True
|
|
End If
|
|
End If
|
|
m_Door.CompoList.Add(m_CurrCompo)
|
|
End If
|
|
' se la stringa non ha i due punti
|
|
End While
|
|
Exit For
|
|
End If
|
|
Next
|
|
If Not bDDFName Then
|
|
' la componente none esiste
|
|
If Not String.IsNullOrEmpty(InvalidValue) Then InvalidValue &= Environment.NewLine
|
|
InvalidValue &= String.Format("Error reading {0}: ""{1}"" does not exist as {0}", K_COMPO, CompoNameDDF)
|
|
Index -= 1
|
|
End If
|
|
|
|
Return Index
|
|
End Function
|
|
|
|
Sub ReadParam(ByRef CompoTemplateItem As Compo, ByRef InvalidValue As String, ByRef IndexLine As Integer)
|
|
Dim IndexParam As Integer
|
|
For IndexParam = 0 To CompoTemplateItem.CompoParamList.Count - 1
|
|
' se il nome del parametro è lo stesso di quello presente nella componente
|
|
If String.Equals(Trim(CompoTemplateItem.CompoParamList(IndexParam).DDFName), Trim(SearchName(FileContent(IndexLine + IndexParam)))) Then
|
|
Dim CurrCompoParam As CompoParam = CompoTemplateItem.CompoParamList(IndexParam)
|
|
' verifico di che tipo si tratta: combobox
|
|
If TypeOf CurrCompoParam Is ComboBoxParam Then
|
|
' assegno il valore letto alla lista
|
|
Dim sVal As String = SearchKeyValue(FileContent(IndexLine + IndexParam), CurrCompoParam.DDFName)
|
|
DirectCast(CurrCompoParam, ComboBoxParam).SelItem = SearchKeyValue(FileContent(IndexLine + IndexParam), CurrCompoParam.DDFName)
|
|
' assegno il valore letto alla textbox
|
|
ElseIf TypeOf CurrCompoParam Is TextBoxParam Then
|
|
Dim sVal As String = SearchKeyValue(FileContent(IndexLine + IndexParam), CurrCompoParam.DDFName)
|
|
DirectCast(CurrCompoParam, TextBoxParam).Value = SearchKeyValue(FileContent(IndexLine + IndexParam), CurrCompoParam.DDFName)
|
|
ElseIf TypeOf CurrCompoParam Is TextBoxOnOffParam Then
|
|
' assegno il valore letto alla taxtboxonoff
|
|
Dim sVal As String = SearchKeyValue(FileContent(IndexLine + IndexParam), CurrCompoParam.DDFName)
|
|
DirectCast(CurrCompoParam, TextBoxOnOffParam).Value = SearchKeyValue(FileContent(IndexLine + IndexParam), CurrCompoParam.DDFName)
|
|
'Else
|
|
' ' il nome non DDF non è corretto
|
|
' InvalidValue &= String.Format("Error reading name {0} param in {1} compo.", CompoTemplateItem.CompoParamList(IndexParam).DDFName, CompoTemplateItem.CompoType.DDFName)
|
|
End If
|
|
' se il nome esiste ma è sabgliato
|
|
ElseIf Not String.IsNullOrWhiteSpace(SearchName(FileContent(IndexLine + IndexParam))) Then
|
|
' se il nome non è preceduto dal trattino
|
|
If String.IsNullOrWhiteSpace(Score(FileContent(IndexLine + IndexParam))) Then
|
|
' il nome DDF non è corretto
|
|
If Not String.IsNullOrEmpty(InvalidValue) Then InvalidValue &= Environment.NewLine
|
|
InvalidValue &= String.Format("Error reading name {0} param in {1} compo.", SearchName(FileContent(IndexLine + IndexParam)), CompoTemplateItem.CompoType.DDFName)
|
|
Else
|
|
' istanzio tutti i valori che mancano alla compo corrente di default
|
|
If Not String.IsNullOrEmpty(InvalidValue) Then InvalidValue &= Environment.NewLine
|
|
InvalidValue &= String.Format("Error reading {0} compo: missing {1} params.", CompoTemplateItem.CompoType.DDFName, CompoTemplateItem.CompoParamList.Count - IndexParam)
|
|
' esco dal ciclo for dei parametri
|
|
Exit For
|
|
End If
|
|
'se c'è una riga vuota
|
|
ElseIf String.IsNullOrWhiteSpace(SearchName(FileContent(IndexLine + IndexParam))) Then
|
|
' spostati alla riga successiva nel fie DDF
|
|
IndexLine += 1
|
|
' e continua a cercare lo stesso parametro
|
|
IndexParam -= 1
|
|
' se trovo un trattino vuol dire che cè una nuova componente
|
|
End If
|
|
Next
|
|
' terminata la lettura dei parametri
|
|
IndexLine += IndexParam
|
|
End Sub
|
|
|
|
|
|
|
|
#End Region ' Lettura ddf
|
|
|
|
#Region "SCRITTURA DDF"
|
|
|
|
'genero le stringhe che dovranno essere scritte nel DDF
|
|
Friend Sub WriteDDF(Door As Door, sPath As String)
|
|
' Door = DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel).CurrDoor
|
|
' pulisco lista prima di iniziare a scrivere
|
|
Dim DdfFileContent As New List(Of String)
|
|
'Genero una lista di stringhe
|
|
Dim dVal As Double = 0
|
|
DdfFileContent.Add(ConstCompo.K_SIZE & ":")
|
|
StringToDouble(Door.Width, dVal)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_WIDTH & ": " & DoubleToString(dVal, 3))
|
|
StringToDouble(Door.Height, dVal)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_HEIGHT & ": " & DoubleToString(dVal, 3))
|
|
StringToDouble(Door.Thickness, dVal)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_THICKNESS & ": " & DoubleToString(dVal, 3))
|
|
' aggiungo una riga vuota per separare la lista successiva
|
|
DdfFileContent.Add("")
|
|
DdfFileContent.Add("" & ConstCompo.K_SWING & ": " & Door.Swing)
|
|
' aggiungo una riga vuota per separare la lista successiva
|
|
DdfFileContent.Add("")
|
|
DdfFileContent.Add("" & ConstCompo.K_PROFILES & ":")
|
|
DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_LOCKEDGE & ": " & Door.LockEdgeType)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_MACHINING & ": " & ConvertBooleanToOnOff(Door.LockEdgeMachining))
|
|
StringToDouble(Door.LockEdgeOverMaterial, dVal)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_OVERMATERAL & ": " & DoubleToString(dVal, 3))
|
|
DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_HINGEEDGE & ": " & Door.HingeEdgeType)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_MACHINING & ": " & ConvertBooleanToOnOff(Door.HingeEdgeMachining))
|
|
StringToDouble(Door.HingeEdgeOverMaterial, dVal)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_OVERMATERAL & ": " & DoubleToString(dVal, 3))
|
|
DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_TOP & ": " & Door.TopType)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_MACHINING & ": " & ConvertBooleanToOnOff(Door.TopMachining))
|
|
StringToDouble(Door.TopOverMaterial, dVal)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_OVERMATERAL & ": " & DoubleToString(dVal, 3))
|
|
DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_BOTTOM & ": " & Door.BottomType)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_MACHINING & ": " & ConvertBooleanToOnOff(Door.BottomMachining))
|
|
StringToDouble(Door.BottomOverMaterial, dVal)
|
|
DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_OVERMATERAL & ": " & DoubleToString(dVal, 3))
|
|
' aggiungo una riga vuota per separare la lista successiva
|
|
DdfFileContent.Add("")
|
|
' Riordino e stampo le compo
|
|
SearchCompo(DdfFileContent, Door)
|
|
If Not Directory.Exists(Path.GetDirectoryName(sPath)) Then
|
|
Directory.CreateDirectory(Path.GetDirectoryName(sPath))
|
|
End If
|
|
File.WriteAllLines(sPath, DdfFileContent, Text.Encoding.UTF8)
|
|
End Sub
|
|
|
|
' stampa le compo seguedo l'ordine della lista delle componenti del ddf
|
|
Public Sub SearchCompo(DdfFileContent As List(Of String), ByRef Door As Door)
|
|
Dim NewCompoNameDDF = False
|
|
Dim WritingError As String = String.Empty
|
|
' cerco la prima componente da aggiungere alla lista delle componenti
|
|
For Index1 = 0 To DdfFile.CompoListOrder.Count() - 1
|
|
For Index2 = 0 To Door.CompoList.Count() - 1
|
|
' se trovo la componenete da aggiungere
|
|
If DdfFile.CompoListOrder(Index1) = Door.CompoList(Index2).CompoType.DDFName Then
|
|
' se il nome della componente da aggiungere già esiste
|
|
If Index2 >= 1 AndAlso String.Equals(Door.CompoList(Index2).CompoType.DDFName, Door.CompoList(Index2 - 1).CompoType.DDFName) Then
|
|
NewCompoNameDDF = True
|
|
Else
|
|
' aggiungo una riga vuota per separare il nome della nuova componente
|
|
DdfFileContent.Add("")
|
|
End If
|
|
' Carico nella lista dei componenti la lista di stringhe da stampare
|
|
DdfFileContent.AddRange(GenerateCompolistDDF(Door.CompoList(Index2), WritingError, NewCompoNameDDF))
|
|
End If
|
|
Next
|
|
Next
|
|
' finto di leggere tutte le componenti stampo il messaggio degli errori
|
|
If Not String.IsNullOrWhiteSpace(WritingError) Then
|
|
MessageBox.Show(WritingError, "Error", MessageBoxButton.OK)
|
|
End If
|
|
End Sub
|
|
|
|
'Genero la lista di parametri di ogni compo che vedo a video
|
|
Public Function GenerateCompolistDDF(Compo As Compo, ByRef sErrorList As String, bNewCompoNameDDF As Boolean) As List(Of String)
|
|
Dim CompoListDDF As New List(Of String)
|
|
' se il nome non esiste ancora nella lista lo aggiungo
|
|
If Not bNewCompoNameDDF Then
|
|
' aggiungo il nome DDF della componente
|
|
CompoListDDF.Add(Compo.CompoType.DDFName & ":")
|
|
End If
|
|
' se esiste il template
|
|
If Not String.IsNullOrWhiteSpace(Compo.TemplateDDFName) Then
|
|
' aggiungo " - nomeTemplate: TemplateSelezionato"
|
|
CompoListDDF.Add(K_SCORE & Compo.TemplateDDFName & ": " & Compo.TemplateSelItem)
|
|
End If
|
|
' creo l'indice dei parametri della compo
|
|
Dim ParamIndex As Integer
|
|
' scrivo tutti i parametri della compo
|
|
For ParamIndex = 0 To Compo.CompoParamList.Count - 1
|
|
Dim CurrCompoParam As CompoParam = Compo.CompoParamList(ParamIndex)
|
|
' controllo il tipo di parametro: ComboBox
|
|
If TypeOf CurrCompoParam Is ComboBoxParam Then
|
|
' controllo che sia selezionato un elemento
|
|
If Not String.IsNullOrWhiteSpace(DirectCast(CurrCompoParam, ComboBoxParam).SelItem) Then
|
|
CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, ComboBoxParam).DDFName & ": " & DirectCast(CurrCompoParam, ComboBoxParam).SelItem)
|
|
Else
|
|
' se non è selezionato nessun elemento (cosa impossibile...)
|
|
If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine
|
|
sErrorList &= String.Format("Error reading {0} param in {1} compo: value does not exist", DirectCast(CurrCompoParam, ComboBoxParam).Name, CurrCompoParam.DDFName)
|
|
End If
|
|
' TextBox
|
|
ElseIf TypeOf CurrCompoParam Is TextBoxParam Then
|
|
If Not String.IsNullOrWhiteSpace(DirectCast(CurrCompoParam, TextBoxParam).Value) Then
|
|
CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, TextBoxParam).DDFName & ": " & DirectCast(CurrCompoParam, TextBoxParam).Value)
|
|
' TextBoxOnOff e controllo che la TextBoxOnOff sia attiva
|
|
Else
|
|
If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine
|
|
sErrorList &= String.Format("Error reading {0} param in {1} compo: value does not exist", DirectCast(CurrCompoParam, TextBoxParam).Name, CurrCompoParam.DDFName)
|
|
End If
|
|
ElseIf TypeOf CurrCompoParam Is TextBoxOnOffParam AndAlso DirectCast(CurrCompoParam, TextBoxOnOffParam).IsActive Then
|
|
If Not String.IsNullOrWhiteSpace(DirectCast(CurrCompoParam, TextBoxOnOffParam).Value) Then
|
|
CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, TextBoxOnOffParam).DDFName & ": " & DirectCast(CurrCompoParam, TextBoxOnOffParam).Value)
|
|
Else
|
|
If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine
|
|
sErrorList &= String.Format("Error reading {0} param in {1} compo: value does not exist", DirectCast(CurrCompoParam, TextBoxOnOffParam).Name, CurrCompoParam.DDFName)
|
|
End If
|
|
End If
|
|
Next
|
|
Return CompoListDDF
|
|
End Function
|
|
|
|
#End Region ' Scrittura DDF
|
|
|
|
|
|
End Module
|