Imports System.Collections.ObjectModel Imports System.IO Imports EgtUILib Imports System.Text.RegularExpressions Friend Module DdfFile ' 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) Friend UnitMeasure As String #Region "SCRITTURA DDF" 'genero le stringhe che dovranno essere scritte nel DDF ' !!! attenzione !!! tutte le volte che stampo sul file di CurrDoor.ddf la variabile booelana DEVE essere settata su True Friend Sub WriteDDF(Door As Door, sPath As String, bIsDDf As Boolean) ' Door = DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel).CurrDoor ' pulisco lista prima di iniziare a scrivere Dim DdfFileContent As New List(Of String) If String.IsNullOrEmpty(Door.Measure) Then Door.Measure = OptionModule.m_SelectedMeasureUnit End If DdfFileContent.Add("#EGTDOORCREATOR") 'Genero una lista di stringhe If Door.Measure = "Inches" Then Door.Measure = "inches" End If DdfFileContent.Add(ConstCompo.K_MEASURES & ": " & Door.Measure) ' aggiungo una riga vuota per separare la lista successiva DdfFileContent.Add("") If String.IsNullOrEmpty(Door.Code) Then Door.Code = "1111" End If DdfFileContent.Add(ConstCompo.K_CODE & ": " & Door.Code) ' aggiungo una riga vuota per separare la lista successiva DdfFileContent.Add("") DdfFileContent.Add(ConstCompo.S_ORDER & ":") ' Probablimente da cambiare DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_CUSTOMER & ": ") DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_ELEVATION & ": ") DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_PROJECT & ": ") DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_PO & ": ") DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_LINE & ": ") ' aggiungo una riga vuota per separare la lista successiva DdfFileContent.Add("") DdfFileContent.Add(ConstCompo.K_DATE & ":" & " " & System.DateTime.Now.ToString("dd/MM/yyyy")) ' aggiungo una riga vuota per separare la lista successiva DdfFileContent.Add("") Dim dVal As Double = 0 DdfFileContent.Add(ConstCompo.K_SIZE & ":") If Not StringToDouble(Door.Width, dVal) Then MessageBox.Show(EgtMsg(50106) & K_WIDTH, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) Return End If DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_WIDTH & ": " & DoubleToString(dVal, 5)) If Not StringToDouble(Door.Height, dVal) Then MessageBox.Show(EgtMsg(50106) & K_HEIGHT, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) Return End If DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_HEIGHT & ": " & DoubleToString(dVal, 5)) If Not StringToDouble(Door.Thickness, dVal) Then MessageBox.Show(EgtMsg(50106) & K_THICKNESS, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) Return End If DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_THICKNESS & ": " & DoubleToString(dVal, 5)) ' aggiungo il peso della porta If Door.IsCheckedWeight = Visibility.Visible Then If Not StringToDouble(Door.Weight, dVal) Then MessageBox.Show(EgtMsg(50106) & K_WEIGHT, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) Return End If DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_WEIGHT & ": " & Door.Weight) End If ' 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("") ' aggiungo il secure nullo al DDF DdfFileContent.Add("" & ConstCompo.K_SECURE & ": " & "0") ' 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.Name) DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_MACHINING & ": " & ConvertBooleanToOnOff(Door.LockEdgeMachining)) If Not StringToDouble(Door.LockEdgeOverMaterial, dVal) Then MessageBox.Show(EgtMsg(50106) & K_LOCKEDGEOVERMATERIAL_INI, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) Return End If DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_OVERMATERAL & ": " & DoubleToString(dVal, 5)) DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_HINGEEDGE & ": " & Door.HingeEdgeType.Name) DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_MACHINING & ": " & ConvertBooleanToOnOff(Door.HingeEdgeMachining)) If Not StringToDouble(Door.HingeEdgeOverMaterial, dVal) Then MessageBox.Show(EgtMsg(50106) & K_HINGEDGEOVERMATERIAL_INI, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) Return End If DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_OVERMATERAL & ": " & DoubleToString(dVal, 5)) DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_TOP & ": " & Door.TopType.Name) DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_MACHINING & ": " & ConvertBooleanToOnOff(Door.TopMachining)) If Not StringToDouble(Door.TopOverMaterial, dVal) Then MessageBox.Show(EgtMsg(50106) & K_TOPOVERMATERIAL_INI, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) Return End If DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_OVERMATERAL & ": " & DoubleToString(dVal, 5)) DdfFileContent.Add(ConstCompo.K_SPACE3 & ConstCompo.K_BOTTOM & ": " & Door.BottomType.Name) DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_MACHINING & ": " & ConvertBooleanToOnOff(Door.BottomMachining)) If Not StringToDouble(Door.BottomOverMaterial, dVal) Then MessageBox.Show(EgtMsg(50106) & K_BOTTOMOVERMATERIAL_INI, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) Return End If DdfFileContent.Add(ConstCompo.K_SPACE5 & ConstCompo.K_OVERMATERAL & ": " & DoubleToString(dVal, 5)) ' Riordino e stampo le compo SearchCompo(DdfFileContent, Door, bIsDDf) 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, bIsDDf As Boolean) 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, bIsDDF)) End If NewCompoNameDDF = False Next Next ' finto di leggere tutte le componenti stampo il messaggio degli errori If Not String.IsNullOrWhiteSpace(WritingError) Then MessageBox.Show(WritingError, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) 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, bIsDDF 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 Dim IndexDDF As Integer = 0 ' carico la lista DDF Dim List As List(Of String) = DirectCast(CurrCompoParam, ComboBoxParam).ItemListDDF ' rccolgo il valore IndexDDF come indice del valore selezionato dalla lista IndexDDF = DirectCast(CurrCompoParam, ComboBoxParam).ItemList.IndexOf(DirectCast(CurrCompoParam, ComboBoxParam).SelItem) ' restituisco il valore DDF della lista associato all'indice passato Dim SelItemDDF As String = Trim(List(IndexDDF)) CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, ComboBoxParam).DDFName & ": " & SelItemDDF) Else ' se non è selezionato nessun elemento (cosa impossibile...) If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine sErrorList &= String.Format(EgtMsg(50114), DirectCast(CurrCompoParam, ComboBoxParam).Name, CurrCompoParam.DDFName) End If ElseIf TypeOf CurrCompoParam Is TextBoxOnOffParam Then If Not String.IsNullOrWhiteSpace(DirectCast(CurrCompoParam, TextBoxOnOffParam).ToolTipValue) AndAlso DirectCast(CurrCompoParam, TextBoxOnOffParam).IsActive Then ' se è stata inserita un'espressine non valida restituisco un errore If DirectCast(CurrCompoParam, TextBoxOnOffParam).ToolTipValue = EgtMsg(50143) Then If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine sErrorList &= String.Format(EgtMsg(50141), DirectCast(CurrCompoParam, TextBoxOnOffParam).Name, CurrCompoParam.DDFName) CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, TextBoxOnOffParam).DDFName & ": ") Else If bIsDDF Then CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, TextBoxOnOffParam).DDFName & ": " & DirectCast(CurrCompoParam, TextBoxOnOffParam).ToolTipValue) Else CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, TextBoxOnOffParam).DDFName & ": " & DirectCast(CurrCompoParam, TextBoxOnOffParam).Value) End If End If ElseIf Not String.IsNullOrWhiteSpace(DirectCast(CurrCompoParam, TextBoxOnOffParam).ToolTipValue) AndAlso Not DirectCast(CurrCompoParam, TextBoxOnOffParam).IsActive Then ' non restituire nessun tipo di errore End If ' TextBox ElseIf TypeOf CurrCompoParam Is TextBoxParam Then If Not String.IsNullOrWhiteSpace(DirectCast(CurrCompoParam, TextBoxParam).ToolTipValue) Then ' se è stata inserita un'espressine non valida restituisco iun errore If DirectCast(CurrCompoParam, TextBoxParam).ToolTipValue = EgtMsg(50143) Then If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine sErrorList &= String.Format(EgtMsg(50141), DirectCast(CurrCompoParam, TextBoxParam).Name, CurrCompoParam.DDFName) CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, TextBoxParam).DDFName & ": ") Else If bIsDDF Then CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, TextBoxParam).DDFName & ": " & DirectCast(CurrCompoParam, TextBoxParam).ToolTipValue) Else CompoListDDF.Add(K_SPACE5 & DirectCast(CurrCompoParam, TextBoxParam).DDFName & ": " & DirectCast(CurrCompoParam, TextBoxParam).Value) End If End If Else If Not String.IsNullOrEmpty(sErrorList) Then sErrorList &= Environment.NewLine sErrorList &= String.Format(EgtMsg(50141), DirectCast(CurrCompoParam, TextBoxParam).Name, CurrCompoParam.DDFName) End If End If Next Return CompoListDDF End Function #End Region ' Scrittura DDF 'eseguo il confronto tra il DDF Nuovo e quello in lettura nella finestra grafica: restituisce falso se i due file sono diversi Friend Function ComparisonFileDDF(sPathNewDoor As String, sPathTempDoor As String) As Boolean ''Dim FileContentNewDoor As String() ''Dim FileContentTempDoor As String() Dim bComparison As Boolean = False ''FileContentNewDoor = File.ReadAllLines(sPathNewDoor) ''FileContentTempDoor = File.ReadAllLines(sPathTempDoor) ''Dim nComparison As Integer '' individuo il file più corto tra i due ''Dim EndOfFile As Integer ''If FileContentNewDoor.Count > FileContentTempDoor.Count Then '' EndOfFile = FileContentTempDoor.Count '' nComparison = 1 ''ElseIf FileContentNewDoor.Count < FileContentTempDoor.Count Then '' EndOfFile = FileContentNewDoor.Count '' nComparison = -1 ''ElseIf FileContentNewDoor.Count = FileContentTempDoor.Count Then '' EndOfFile = FileContentNewDoor.Count '' nComparison = 0 ''End If ''Dim Line As Integer = 0 ''Dim LineBis As Integer = 0 '' confronto riga per riga i due file ''For Line = 0 To EndOfFile - 1 '' SkipWhiteSpace(FileContentNewDoor, Line, FileContentNewDoor.Count - 1) '' SkipWhiteSpace(FileContentTempDoor, LineBis, FileContentTempDoor.Count - 1) '' If Trim(FindComments(FileContentNewDoor(Line))) = Trim(FindComments(FileContentTempDoor(LineBis))) Then '' bComparison = True '' LineBis += 1 '' Else '' se la riga cercata è la data allora non considerare la modifica '' If Trim(SearchName(FileContentNewDoor(Line))) = "date" Then '' bComparison = True '' LineBis += 1 '' ElseIf IsNumeric(SearchKeyValue(FileContentNewDoor(Line), SearchName(FileContentNewDoor(Line)))) Then '' Dim sValNewDoor As Double '' StringToDouble(SearchKeyValue(FileContentNewDoor(Line), SearchName(FileContentNewDoor(Line))), sValNewDoor) '' Dim sValTempDoor As Double '' StringToDouble(SearchKeyValue(FileContentTempDoor(Line), SearchName(FileContentTempDoor(LineBis))), sValTempDoor) '' If sValNewDoor = sValTempDoor Then '' bComparison = True '' LineBis += 1 '' Else '' bComparison = False '' Exit For '' End If '' End If '' End If ''Next ''studio le righe che non sono state analizzate sopra ''Select Case nComparison '' Case 1 '' For MissinIndex = EndOfFile To FileContentNewDoor.Count - 1 '' If Not String.IsNullOrWhiteSpace(FindComments(FileContentNewDoor(MissinIndex))) Then '' bComparison = False '' Exit Select '' Else '' bComparison = True '' End If '' Next '' Case -1 '' For MissinIndex = EndOfFile To FileContentTempDoor.Count - 1 '' If Not String.IsNullOrWhiteSpace(FindComments(FileContentTempDoor(MissinIndex))) Then '' bComparison = False '' Exit Select '' Else '' bComparison = True '' End If '' Next ''End Select Return bComparison End Function ' se il titolo presenta * allora vuol dire che era stato modificato, altrinenti no .Trim("*"c) Friend Function SetModify(rMainWindow As MainWindowViewModel) As Boolean If Trim(rMainWindow.ProjectNameMsg) = Trim(rMainWindow.ProjectNameMsg.Trim("*"c)) Then Return True Else Return False End If End Function ''Public Function SkipWhiteSpace(Array() As String, ByRef Index As Integer, LastIndex As Integer) As Integer '' Array(Index) = FindComments(Array(Index)) '' While String.IsNullOrWhiteSpace(Array(Index)) And Index < LastIndex '' Index += 1 '' Array(Index) = FindComments(Array(Index)) '' End While '' Return Index ''End Function End Module