Imports System.ComponentModel Imports System.Collections.ObjectModel Imports System.IO Imports EgtUILib Imports EgtWPFLib5 Public Class Hardware Implements INotifyPropertyChanged Dim bTypeListExist As Boolean = False ' Path StdTemplate.ini Private m_StdTemplate As String = String.Empty ' il percorso viene aggiornato ad ogni scelta dell'hardware in LoadType() Public ReadOnly Property StdTemplate As String Get Return m_StdTemplate End Get End Property ' i parametetri sono suddivisi in sottocapitolli (gruppi di parametri) Private m_GroupChapters As New ObservableCollection(Of Compo) Public Property GroupChapters As ObservableCollection(Of Compo) Get Return m_GroupChapters End Get Set(value As ObservableCollection(Of Compo)) m_GroupChapters = value End Set End Property #Region "BRAND" Public ReadOnly Property BrandList As ObservableCollection(Of CompoBrandDir) Get If Not IsNothing(m_HardwareGeneral) Then Return m_HardwareGeneral.HardwareFolderList Else Return Nothing End If End Get End Property Private m_SelBrand As CompoBrandDir Public Property SelBrand As CompoBrandDir Get Return m_SelBrand End Get Set(value As CompoBrandDir) m_SelBrand = value If Not IsNothing(m_SelBrand) Then ' Carico lista template TemplateList = m_SelBrand.ModelFileList If m_SelBrand.ModelFileList.Count > 0 Then SelTemplate = m_SelBrand.ModelFileList(0) Else SelTemplate = String.Empty End If Else SelTemplate = String.Empty End If NotifyPropertyChanged("SelBrand") End Set End Property #End Region ' Brand #Region "TEMPLATE" Private m_HardwareGeneral As CompoType Public Property HardwareGeneral As CompoType Get Return m_HardwareGeneral End Get Set(value As CompoType) m_HardwareGeneral = value End Set End Property Private m_TemplateList As New ObservableCollection(Of String) Public Property TemplateList As ObservableCollection(Of String) Get Return m_TemplateList End Get Set(value As ObservableCollection(Of String)) m_TemplateList = value NotifyPropertyChanged("TemplateList") End Set End Property Private m_SelTemplate As String ' questa proprietà non è usata nel momento in cui generiamo un nuovo Hardware Public Property SelTemplate As String Get Return m_SelTemplate End Get Set(value As String) If SaveControl() = SaveResult.nCancel Then Return m_SelTemplate = value ClearGroupChapters() ' Prima di procedere ripulisco la pagina dai vecchi paramatri If Not String.IsNullOrWhiteSpace(m_SelTemplate) Then If bTypeListExist Then ' False-> errore nel caricamento della lista o non esiste, True-> la lista è stata caricata correttamente SetTypeFromTemplate(m_SelTemplate) NotifyPropertyChanged("VisibilityType") End If ReadChapterTemplate() ' Rileggo i parametri del SetTemplate ReadTemplate(m_SelTemplate) ' Carico i dati del template End If Map.refSceneManagerVM.RefreshBtn() ' Creo un file temporaneo per gestire la grafica NotifyPropertyChanged("SelTemplate") NotifyPropertyChanged("TemplateList") End Set End Property Private m_VisibilityTemplate As Visibility = Visibility.Visible Public Property VisibilityTemplate As Visibility Get Return m_VisibilityTemplate End Get Set(value As Visibility) m_VisibilityTemplate = value End Set End Property Private m_TemplateName As String = String.Empty Public Property TemplateName As String Get Return m_TemplateName End Get Set(value As String) m_TemplateName = value ' al momento del slavatggio il nome del file è quello contenuto in m_SelTemplate m_SelTemplate = m_TemplateName NotifyPropertyChanged("TemplateName") End Set End Property #End Region ' Name-Template #Region "TYPELIST" Private m_TypeList As New List(Of TypeHardware) Public Property TypeList As List(Of TypeHardware) Get Return m_TypeList End Get Set(value As List(Of TypeHardware)) m_TypeList = value NotifyPropertyChanged("TypeList") End Set End Property ' se non dovessere esistere un tipo, al momento del salvataggio cerca il file con nome Template ed estensione .Templ Private m_SelType As TypeHardware = New TypeHardware("StdTemplate", "") Public Property SelType As TypeHardware Get Return m_SelType End Get Set(value As TypeHardware) ' verifico se tipo è cambiato Dim bChanged As Boolean = If(Not IsNothing(m_SelType), value.NameINI <> m_SelType.NameINI, True) m_SelType = value ' se cambiato carico il suo progetto con quotature/suggerimenti If bChanged Then Map.refHardwareHelpSceneHostV.LoadHelpProject() NotifyPropertyChanged("SelType") End Set End Property Private m_VisibilityType As Visibility = Visibility.Collapsed Public Property VisibilityType As Visibility Get Return m_VisibilityType End Get Set(value As Visibility) m_VisibilityType = value NotifyPropertyChanged("VisibilityType") End Set End Property ' se non viene modificata il tipo non può essere modificato Private m_IsEnableType As Boolean = False Public Property IsEnableType As Boolean Get If Not VisibilityType = Visibility.Visible Then Return False Return m_IsEnableType End Get Set(value As Boolean) m_IsEnableType = value NotifyPropertyChanged("IsEnableType") End Set End Property #End Region ' TypeList #Region "GENERAL FUNCTION" #Region "Caricamento" ' Carica il nome della Componente, La lista dei template, La lista dei tipi Public Sub LoadTemplate(ByRef CurrCompoType As CompoType) ' carico il general dell'hardware m_HardwareGeneral = CurrCompoType NotifyPropertyChanged("BrandList") bTypeListExist = LoadType() ' carico la lista dei Type If Not bTypeListExist Then SelBrand = Nothing ElseIf BrandList.Count > 0 Then SelBrand = BrandList(0) Else EgtNewFile() End If Dim ErrorList As String = String.Empty If EgtUILib.GetPrivateProfileInt(S_TEMPLATE, K_ISACTIVE, 1, CurrCompoType.Path & "\" & CONFIGINI_FILE_NAME) = 0 Then VisibilityTemplate = Visibility.Collapsed NotifyPropertyChanged("VisibilityTemplate") End If End Sub ' carico la lista dei tipi --> devo stampare gli errori Private Function LoadType() As Boolean Dim ErrorMsg As String = String.Empty ' costruisco la Path del template da leggere m_StdTemplate = m_HardwareGeneral.Path & "\" & STD_TEMPLATE If Not File.Exists(m_StdTemplate) Then Return False Dim List As New List(Of String) ' lista temporanea "1/Mort" If IniFile.StdTemplateGetPrivateProfileList(S_HARDWARE, K_TYPE, List) Then m_VisibilityType = Visibility.Visible ' rendo visibile la lista ' leggo nomi Dim ArrayNameSplit(1) As String For IndexListType As Integer = 0 To List.Count - 1 ArrayNameSplit = List(IndexListType).Split("/"c) If IsNumeric(ArrayNameSplit(0)) Then m_TypeList.Add(New TypeHardware(ArrayNameSplit(1), ArrayNameSplit(0))) Else ErrorMsg = "In file StdTempate.ini is missing numeric param in [Type]" TypeList.Add(New TypeHardware("Error!", "0")) Return False ' interrompo la lettura End If Next NotifyPropertyChanged("TypeList") NotifyPropertyChanged("TypeListName") Else m_VisibilityType = Visibility.Collapsed Return False ' se la lista è vuota restituisco falso End If Return True End Function ' setta il valore del template --> devo stampare gli errori Private Function SetTypeFromTemplate(value As String) As Boolean ' carico di Default il valore 1 For IndexListType As Integer = 0 To TypeList.Count - 1 If TypeList(IndexListType).NameINI = "1" Then SelType = TypeList(IndexListType) NotifyPropertyChanged("SelType") Exit For End If Next ' inizio la lettura del file lua selezionato Dim CurrItemPath As String = CurrPath() Dim ErrorMsg As String = String.Empty ' se il file ha estensione nge If Path.HasExtension(CurrItemPath) AndAlso Path.GetExtension(CurrItemPath).ToLower = NGE_EXTENSION Then If Not File.Exists(CurrItemPath) Then ErrorMsg = "File does not exist" : Return False ' controllo che esiste il file altrimenti esco Dim ConfigDefault As String = String.Empty ' configurazione del template EgtUILib.GetPrivateProfileString(S_NGECONFIG, K_DEFAULT, "", ConfigDefault, m_HardwareGeneral.Path & "\" & CONFIGINI_FILE_NAME) For IndexTypeList As Integer = 0 To TypeList.Count - 1 If TypeList(IndexTypeList).NameINI = ConfigDefault Then Exit For Else ErrorMsg = "Definition type is not correct: " & ConfigDefault : Return False Next Else ' se il file non ha estensione allora aggiungo l'estensione .lua If Not Path.GetExtension(CurrItemPath).ToLower = LUA_EXTENSION Then CurrItemPath &= LUA_EXTENSION End If ' controllo che esiste il file altrimenti esco If Not File.Exists(CurrItemPath) Then ErrorMsg = "File does not exist" : Return False ' m_TemplateSelItem = value ' carico un vettore con le stringhe del file corrente Dim ReadCurrCompo() As String = File.ReadAllLines(CurrItemPath) Dim EndOfFile As Boolean = False ' 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]: se lo trovo If RegexFunction.IsGraphicParametersTitle(CurrCompoFileLine) Then ' mi preparo per leggere la prima riga dopo il titolo Dim ParamIndex As Integer = 1 If Not String.IsNullOrWhiteSpace(ParamLine(ReadCurrCompo(LineIndex + ParamIndex), K_DEFAULT)) Then Dim ConfigDefault As String = Trim(ParamLine(ReadCurrCompo(LineIndex + ParamIndex), K_DEFAULT)) If Not IsNumeric(ConfigDefault) Then ErrorMsg = String.Format("In file {0} param 'Default' must be numeric.", CurrItemPath) Return False ' valore letto non è numerico Else For IndexListType As Integer = 0 To TypeList.Count - 1 If TypeList(IndexListType).NameINI = ConfigDefault Then SelType = TypeList(IndexListType) NotifyPropertyChanged("SelType") Exit For End If Next Exit For End If End If End If Next End If Return True End Function ' ricerca il nome dei capitoli associati e chiama la lettura dei parametri Public Sub ReadChapterTemplate() Dim ErrorList As String = String.Empty Dim sParam As String = String.Empty ' la stringa che contiene tutte le informazioni della componente Dim ParamIndex As Integer = 1 Dim ChapterIndex As Integer = 1 ' numero del capitolo Dim IndexChapter As String = "1" For IndexTypeList As Integer = 0 To m_TypeList.Count - 1 If m_TypeList(IndexTypeList) Is SelType Then IndexChapter = m_TypeList(IndexTypeList).NameINI Exit For End If Next Dim S_CHAPTER As String = S_GR_PARAM_HARDWARE & IndexChapter & "." ' il nome del capitolo da leggere "ParametersN." While EgtUILib.GetPrivateProfileString(S_CHAPTER & ChapterIndex, K_PARAM & ParamIndex, "", sParam, m_StdTemplate) > 0 ' Verifico che esista il capitolo nuovo "Type-ChapterIndex" Dim Chapter As New Compo(m_HardwareGeneral) Dim Name As String = String.Empty Dim LuaName As String = String.Empty ' legge il nome del parametro If StdTemplateGetPrivateProfileChapterName(S_CHAPTER & ChapterIndex, K_NAME, LuaName, Name) Then Chapter.TemplateName = Name End If Dim bIsActive As Boolean = True ' legge se è attivo Dim IndexParam As String = "1" ' il parametro cascade serve per riferisrsi al gruppo di parametri con l'indice indicato ' Se il gruppo di parametri con l'indice indicato è attvivo allora a casca rendo attivo anche questo gruppo di parametri ' attualmente non esiste nessuna struttura che garantisca il funzionamento If StdTemplateGetPrivateProfileChapterCascaded(S_CHAPTER & ChapterIndex, K_CASCADED, IndexParam) Then Chapter.Cascaded = IndexParam End If Dim nIsActive As Integer = StdTemplateGetPrivateProfileInt(S_CHAPTER & ChapterIndex, K_ISACTIVE, nIsActive) Select Case nIsActive Case 0 Chapter.SetIsFixed(False) Chapter.SetIsActiveChapter(False) Case 1 Chapter.SetIsFixed(False) Chapter.SetIsActiveChapter(True) Case 2 Chapter.SetIsFixed(True) Chapter.SetIsActiveChapter(True) End Select While EgtUILib.GetPrivateProfileString(S_CHAPTER & ChapterIndex, K_PARAM & ParamIndex, "", sParam, m_StdTemplate) > 0 ' Verifico che esista il parametro nuovo "Param-ParamIndex" If Not String.IsNullOrWhiteSpace(sParam) Then Dim NewParam As New CompoParam(m_HardwareGeneral.DDFName, m_HardwareGeneral.Name, Chapter) ' leggo il tipo di parametro, se la lettura va a buon fine la carico If Chapter.ReadParamHardware(sParam, NewParam, ErrorList) Then Chapter.CompoParamList.Add(NewParam) End If ParamIndex += 1 End While ' termina lettura del capitolo GroupChapters.Add(Chapter) ParamIndex = 1 ChapterIndex += 1 End While ' termina lettura della configurazione If Not String.IsNullOrEmpty(ErrorList) Then MessageBox.Show(ErrorList, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) End If End Sub ' elimina le liste di parametri precedenti ad ogni selezione Public Sub ClearGroupChapters() If Not IsNothing(GroupChapters) Then GroupChapters.Clear() End If NotifyPropertyChanged("GroupChapters") End Sub Friend Function ReadTemplate(sFile As String) As Boolean ' inizio la lettura del file lua selezionato Dim FileContent() As String Dim CurrItemPath As String = CurrPath() Dim Version As String = "2" ' 2 è la versione nuova, 1 la versione vecchia Dim IsActiveVersion As Integer = 0 Dim MakeHole As Boolean = False If StdTemplateGetPrivateProfileChapterVersioning("Versioning", "IsActive", IsActiveVersion) Then Version = "1" End If If Not Path.HasExtension(CurrItemPath) Then CurrItemPath &= LUA_EXTENSION Dim ErrorMsg As String = String.Empty ' se il file ha estensione o se ha estensione nge: esco If Path.GetExtension(CurrItemPath).ToLower = NGE_EXTENSION Then ErrorMsg = "File has nge extension." Return False End If If Not File.Exists(CurrItemPath) Then ErrorMsg = "File does not exist" : Return False ' controllo che esiste il file altrimenti esco FileContent = File.ReadAllLines(CurrItemPath) ' se il file esiste ma è vuoto If FileContent.Count = 0 Then MessageBox.Show(EgtMsg(50107), EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error) End If ' cerco la versione caricata If IsActiveVersion = 1 Then For Each Line In FileContent Dim CurrLine As String = Utility.DeleteLuaComment(Line) Dim sLine() As String = CurrLine.Split("="c) If sLine.Count < 2 OrElse sLine.Count > 2 Then Continue For If sLine(0).Contains(".VER") Then If Not IsNothing(sLine(1)) AndAlso IsNumeric(sLine(1).Replace("'", "")) Then Version = Trim(sLine(1).Replace("'", "")) End If Exit For End If Next End If Select Case Version Case "2" For IndexLine As Integer = 0 To FileContent.Count - 1 Dim CurrLine As String = Utility.DeleteLuaComment(FileContent(IndexLine)) Dim sLine() As String = CurrLine.Split("="c) If sLine.Count < 2 OrElse sLine.Count > 2 Then Continue For FindParamTemplateInConfigList(Trim(sLine(0)), Trim(sLine(1))) Next ' nuova versione Case "1" ' se è una lock If m_HardwareGeneral.DDFName = "locks" Then ' cerco il Parametro mh per l'attivazione del foro For Each Line In FileContent Dim CurrLine As String = Utility.DeleteLuaComment(Line) Dim sLine() As String = CurrLine.Split("="c) If sLine.Count < 2 OrElse sLine.Count > 2 Then Continue For If Trim(sLine(0)) = "tLkmPar.mh" Then If Not IsNothing(sLine(1)) AndAlso Trim(sLine(1)) = "true" Then MakeHole = True End If Exit For End If Next For IndexLine As Integer = 0 To FileContent.Count - 1 Dim CurrLine As String = Utility.DeleteLuaComment(FileContent(IndexLine)) Dim sLine() As String = CurrLine.Split("="c) If sLine.Count < 2 OrElse sLine.Count > 2 Then Continue For FindParamTemplateInConfigListOldVersionLock(Trim(sLine(0)), Trim(sLine(1)), MakeHole) Next Return True End If For IndexLine As Integer = 0 To FileContent.Count - 1 Dim CurrLine As String = Utility.DeleteLuaComment(FileContent(IndexLine)) Dim sLine() As String = CurrLine.Split("="c) If sLine.Count < 2 OrElse sLine.Count > 2 Then Continue For FindParamTemplateInConfigList(Trim(sLine(0)), Trim(sLine(1))) Next End Select Return True End Function Private Function FindParamTemplateInConfigList(sParam As String, sValue As String) As Boolean For IndexGroupChapters As Integer = 0 To m_GroupChapters.Count - 1 For IndexChapter As Integer = 0 To m_GroupChapters(IndexGroupChapters).CompoParamList.Count - 1 If m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter).DDFName = sParam Then ' ho trovato una corrispondenza tra il valore de file ini e quello lua in lettura ' allora significa che tutto il capitolo associato deve essere attivo m_GroupChapters(IndexGroupChapters).SetIsActiveChapter(True) If TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is TextBoxDGCParam Then Dim Text As TextBoxDGCParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), TextBoxDGCParam) Dim sItems() As String = sValue.Split("+"c) Dim sLen As String = Trim(Utility.GetMeasure(sItems(0))) Dim dVal As Double = 0.0 Text.SetValue(sLen) Text.SetConst(Text.ConstList(0)) If sItems.Count >= 2 Then For IndexConst As Integer = 0 To Text.ConstList.Count - 1 If Text.ConstList(IndexConst) = Trim(sItems(1)) Then Text.SetConst(Text.ConstList(IndexConst)) : Exit For Next End If ElseIf TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is TextBoxThicknessParam Then Dim Text As TextBoxThicknessParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), TextBoxThicknessParam) Dim dVal As Double Text.SetConst(Text.ConstList(2)) Text.SetValue("") If StringToDouble(sValue, dVal) AndAlso dVal < 0.0 Then For IndexItem As Integer = 0 To Text.ConstList.Count - 1 If Text.ConstList(IndexItem).dValue = dVal Then Text.SetConst(Text.ConstList(IndexItem)) Exit For End If Next End If If Text.SelConst.Name = OptionModule.m_SelectedMeasureUnit Then Dim sLen As String = Trim(Utility.GetMeasure(sValue)) Text.SetValue(sLen) End If ElseIf TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is TextBoxParam Then Dim Text As TextBoxParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), TextBoxParam) ' controllo il tipo di dato che si aspetta Select Case Text.TypeVar Case ConstGen.INCHES Dim sLen As String = Trim(Utility.GetMeasure(sValue)) Text.SetValue(sLen) Case ConstGen.MM Dim sLen As String = Trim(Utility.GetMeasure(sValue)) Text.SetValue(sLen) Case ConstGen.VAL_DOUBLE Dim dVal As Double = 0.0 If StringToDouble(sValue, dVal) Then Text.SetValue(sValue) Else Text.SetValue("0.000") Case ConstGen.VAL_STING Text.SetValue(Trim(Utility.DeleteSuperScript(sValue))) End Select ElseIf TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is CheckBoxParam Then Dim Text As CheckBoxParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), CheckBoxParam) Text.SetIsChecked(Utility.ConvertCheckBox(sValue)) ElseIf TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is ComboBoxParam Then Dim Text As ComboBoxParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), ComboBoxParam) Text.SetSelItem(Text.ItemList(0)) For IndexCombo As Integer = 0 To Text.ItemListDDF.Count - 1 If Trim(Utility.DeleteSuperScript(Text.ItemListDDF(IndexCombo))) = Trim(Utility.DeleteSuperScript(sValue)) Then Text.SetSelItem(Text.ItemList(IndexCombo)) Next End If Return True End If Next Next Return False End Function ' so già che il file contiene un foro al posto di una mortise Private Function FindParamTemplateInConfigListOldVersionLock(sParam As String, sValue As String, MakeHole As Boolean) As Boolean If MakeHole Then Select Case sParam Case "tLkmPar.L2" sParam = "" Case "tLkmPar.H2" sParam = "tLkmPar.HB2" Case "tLkmPar.T2" sParam = "tLkmPar.TB2" Case "tLkmPar.D_X" sParam = "tLkmPar.DH_X" Case "tLkmPar.LG2" sParam = "" Case "tLkmPar.LA" sParam = "" Case "tLkmPar.s" sParam = "" Case "tLkmPar.p2" sParam = "" Case "tLkmPar.d2" sParam = "" End Select Else Select Case sParam Case "tLkmPar.LGH" sParam = "" End Select End If Return FindParamTemplateInConfigList(sParam, sValue) End Function #End Region ' Caricamneto #Region "Salvataggio, Duplica, Nuovo, Aggiorna" Public Function Duplicate(sSelBrand As String, sTemplate As String) As Boolean If IsNothing(sTemplate) Then MessageBox.Show("Missing name of the new template!", EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Exclamation) Return False End If ' ricostruico il percorso del file da dupicare Dim OldDirPath As String = CurrPath() ' ricostruisco il nuovo file da creare Dim ModelDir As String = String.Empty If sSelBrand <> RegexFunction.ModelTemplate(m_HardwareGeneral.Path) Then ModelDir = sSelBrand & "\" Dim CurrDirPath As String = m_HardwareGeneral.Path & "\" & ModelDir & sTemplate & LUA_EXTENSION Dim IndexModel As Integer Dim TemSelBrand As String = String.Empty ' carico la lista dei file presenti nel direttorio selezionato Dim Temp_TemplateList As New ObservableCollection(Of String) For IndexModel = 0 To m_HardwareGeneral.HardwareFolderList.Count - 1 If m_HardwareGeneral.HardwareFolderList(IndexModel).ModelDirGraphic = sSelBrand Then TemSelBrand = m_HardwareGeneral.HardwareFolderList(IndexModel).ModelDirGraphic Temp_TemplateList = m_HardwareGeneral.HardwareFolderList(IndexModel).ModelFileList Exit For End If Next ' controllo se il nome è già presente nel direttorio selezionato Dim bNameExist As Boolean = False Dim IndexHardwList As Integer For IndexHardwList = 0 To Temp_TemplateList.Count - 1 If Temp_TemplateList(IndexHardwList) = sTemplate Then ' se il nome è nella lista allora esco dal ciclo e rendo falsa la variabile bNameExist bNameExist = True Exit For End If bNameExist = False Next ' se il nome esite già nel direttorio selezionato If bNameExist Then Select Case MessageBox.Show("The file: " & sTemplate & " already exist in directory " & sSelBrand & " . Do you want to overwrite it?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) ' decido di sovrescrivere il file esistente Case MessageBoxResult.Yes ' non eseguo nulla perchè il file è sempre se stesso! Return True Case Else ' deicido di non sovrescrivere interrompo Return False End Select End If ' elimino ilnome dalla lista dei file (alla fine il nome verrà aggiunto ancora) For IndexTempList As Integer = 0 To Temp_TemplateList.Count - 1 If Temp_TemplateList(IndexTempList) = sTemplate Then Temp_TemplateList.RemoveAt(IndexTempList) Exit For End If Next ' carico le variabili temporanee e aggiorno la grafica (lista dei file e Brand selezionato) SelBrand = m_HardwareGeneral.HardwareFolderList(IndexModel) TemplateList = Temp_TemplateList NotifyPropertyChanged("TemplateList") NotifyPropertyChanged("SelBrand") ' copio il file Try File.Copy(OldDirPath, CurrDirPath, True) Catch ex As System.IO.IOException MessageBox.Show("Error in copying: " & ex.Message) ' interrompo la copia e la creazione del nuovo file File.Delete(CurrDirPath) Return False End Try ' aggiungo il nome alla lista TemplateList.Add(sTemplate) For IndexTempList As Integer = 0 To m_TemplateList.Count - 1 ' aggiorno la grafica con il valore selzionato tra i template If m_TemplateList(IndexTempList) = sTemplate Then SelTemplate = m_TemplateList(IndexTempList) Next RefreshTemplateListEgtDOORCreator() Return True End Function Public Function NewHardware(sSelBrand As String, sTemplate As String, sType As TypeHardware) As Boolean ' ricostruico il percorso del file nuovo Dim ModelDir As String = String.Empty ModelDir = String.Empty If sSelBrand <> RegexFunction.ModelTemplate(m_HardwareGeneral.Path) Then ModelDir = sSelBrand & "\" Dim CurrDirPath As String = m_HardwareGeneral.Path & "\" & ModelDir & sTemplate & LUA_EXTENSION Dim IndexModel As Integer Dim TemSelBrand As String = String.Empty ' carico la lista dei file presenti nel direttorio selezionato Dim Temp_TemplateList As New ObservableCollection(Of String) For IndexModel = 0 To m_HardwareGeneral.HardwareFolderList.Count - 1 If m_HardwareGeneral.HardwareFolderList(IndexModel).ModelDirGraphic = sSelBrand Then TemSelBrand = m_HardwareGeneral.HardwareFolderList(IndexModel).ModelDirGraphic Temp_TemplateList = m_HardwareGeneral.HardwareFolderList(IndexModel).ModelFileList Exit For End If Next ' controllo se il nome è già presente nel direttorio selezionato Dim bNameExist As Boolean = False Dim IndexHardwList As Integer For IndexHardwList = 0 To Temp_TemplateList.Count - 1 If Temp_TemplateList(IndexHardwList) = sTemplate Then ' se il nome è nella lista allora esco dal ciclo e rendo falsa la variabile bNameExist bNameExist = True Exit For End If bNameExist = False Next ' se il nome esite già nel direttorio selezionato If bNameExist Then Select Case MessageBox.Show("The file: " & sTemplate & " already exist in directory " & sSelBrand & " . Do you want to overwrite it?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) ' decido di sovrescrivere il file esistente Case MessageBoxResult.Yes If File.Exists(CurrDirPath) Then Try ' elimino il file File.Delete(CurrDirPath) Catch ex As FileNotFoundException ' non è un problema Catch ex As Exception ' non è un problema End Try End If Case Else ' deicido di non sovrescrivere interrompo Return False End Select End If ' elimino il nome dalla lista dei file (alla fine il nome verrà aggiunto ancora) For IndexTempList As Integer = 0 To Temp_TemplateList.Count - 1 If Temp_TemplateList(IndexTempList) = sTemplate Then Temp_TemplateList.RemoveAt(IndexTempList) Exit For End If Next ' carico le variabili temporanee e aggiorno la grafica (lista dei file e Brand selezionato) SelBrand = m_HardwareGeneral.HardwareFolderList(IndexModel) TemplateList = Temp_TemplateList SelType = sType NotifyPropertyChanged("TemplateList") NotifyPropertyChanged("SelBrand") ' ripulisco la lista da eventuali residui di altri Hardware ClearGroupChapters() ' rileggo le component dell'hardware da StdTemplate ReadChapterTemplate() Dim ErrorMsg As String = String.Empty Dim NewFileContent As New ObservableCollection(Of String) If Not WriteFile(NewFileContent) Then Return False ' scrivo tutto sul file corrente File.WriteAllLines(CurrDirPath, NewFileContent) RefreshTemplateListEgtDOORCreator() Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False TemplateList.Add(sTemplate) For IndexTempList As Integer = 0 To m_TemplateList.Count - 1 ' aggiorno la grafica con il valore selzionato tra i template If m_TemplateList(IndexTempList) = sTemplate Then SelTemplate = m_TemplateList(IndexTempList) Next RefreshTemplateListEgtDOORCreator() Return True End Function ' crea il file temporaneao per aggiornare la parte grafica Public Function RefreshTempHardware() As Boolean Dim ErrorMsg As String = String.Empty ' Pulisco da componenti precedenti Map.refHardwarePageVM.Door.CompoList.Clear() If String.IsNullOrWhiteSpace(Map.refHardwarePageVM.CurrHardware.SelTemplate) Then Return False Dim NewFileContent As New ObservableCollection(Of String) If Not WriteFile(NewFileContent) Then Return False ' costruisco il nome del percorso del file corrente Dim sTempFileHardw As String = m_HardwareGeneral.Path & "\" & TEMP_FILE_HARDWARE ' salvo il file File.WriteAllLines(sTempFileHardw, NewFileContent) ' aggiungo la componente Map.refHardwarePageVM.Door.AddNewHardware(m_HardwareGeneral, Path.GetFileNameWithoutExtension(TEMP_FILE_HARDWARE)) Return True End Function Public Function Save() As Boolean Dim ErrorMsg As String = String.Empty ' costruisco la Path del template da leggere Dim TemplFile = m_HardwareGeneral.Path & "\" & m_SelType.Name & ".templ " If Not File.Exists(TemplFile) Then Return False Dim FileContent() As String = File.ReadAllLines(TemplFile) Dim NewFileContent As New ObservableCollection(Of String) If Not WriteFile(NewFileContent) Then Return False ' costruisco il nome del percorso del file corrente Dim CurrConfig As String = m_HardwareGeneral.Path & "\" & CONFIGINI_FILE_NAME Dim CurrItemPath As String = CurrPath() ' salvo il file File.WriteAllLines(CurrItemPath, NewFileContent) RefreshTemplateListEgtDOORCreator() Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False Return True End Function Private Function WriteFile(ByRef NewFileContent As ObservableCollection(Of String)) As Boolean Dim TemplFile = m_HardwareGeneral.Path & "\" & m_SelType.Name & ".templ " If Not File.Exists(TemplFile) Then Return False Dim FileContent() As String = File.ReadAllLines(TemplFile) ' inizio la lettura riga per riga For IndexLine As Integer = 0 To FileContent.Count - 1 NewFileContent.Add(FileContent(IndexLine)) Dim CurrLine As String = Utility.DeleteLuaComment(FileContent(IndexLine)) Dim sLine() As String = CurrLine.Split("="c) If sLine.Count < 2 OrElse sLine.Count > 2 Then Continue For ' significa che non è un parametro Dim sValue As String = Trim(sLine(1)) Dim sTemplValue As String = Trim(sLine(1)) If Not ConvertValueForLua(sValue) Then Continue For FileContent(IndexLine) = FileContent(IndexLine).Replace(sTemplValue, sValue) NewFileContent.RemoveAt(NewFileContent.Count - 1) If Not sValue = " nill" Then NewFileContent.Add(FileContent(IndexLine)) End If Next If IsNothing(NewFileContent) Then Return False Return True End Function Private Function RefreshTemplateListEgtDOORCreator() As Boolean For IndexHardw As Integer = 0 To Map.refCompoPanelVM.CompoTypeList.Count - 1 If m_HardwareGeneral.DDFName = Map.refCompoPanelVM.CompoTypeList(IndexHardw).DDFName Then Map.refCompoPanelVM.CompoTypeList(IndexHardw).LoadListTemplate() Return True Exit For End If Next Return False End Function Public Function ConvertValueForLua(ByRef sValue As String) As Boolean Dim bIsActive As Boolean = True Dim NameParam = Utility.FindNameParam(sValue) If String.IsNullOrEmpty(NameParam) Then Return False For IndexGroupChapters As Integer = 0 To m_GroupChapters.Count - 1 For IndexChapter As Integer = 0 To m_GroupChapters(IndexGroupChapters).CompoParamList.Count - 1 If m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter).DDFName = NameParam Then ' verifico che il parametro da stampare sia abilitato alla stampa (altriementi NON scrivere nel file) If Not m_GroupChapters(IndexGroupChapters).IsActiveChapter Then sValue = " nill" : Return True If TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is TextBoxDGCParam Then Dim Text As TextBoxDGCParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), TextBoxDGCParam) sValue = String.Empty Select Case Text.TypeVar Case ConstGen.INCHES If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then sValue = Text.TypeVar & "( " & Text.Value & ")" Else sValue = Text.Value If MmToInches(sValue) Then sValue = Text.TypeVar & "( " & sValue & ")" End If Case ConstGen.MM If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then sValue = Text.Value InchesToMm(sValue) Else sValue = Text.Value End If End Select sValue &= " + " & Text.SelConst Return True ElseIf TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is TextBoxThicknessParam Then Dim Text As TextBoxThicknessParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), TextBoxThicknessParam) sValue = String.Empty If Text.SelConst.dValue = 0 Then Select Case Text.TypeVar Case ConstGen.INCHES If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then sValue = Text.TypeVar & "( " & Text.Value & ")" Else sValue = Text.Value If MmToInches(sValue) Then sValue = Text.TypeVar & "( " & sValue & ")" End If Case ConstGen.MM If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then sValue = Text.Value InchesToMm(sValue) Else sValue = Text.Value End If End Select Return True End If sValue = DoubleToString(Text.SelConst.dValue, 1) Return True ElseIf TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is TextBoxParam Then Dim Text As TextBoxParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), TextBoxParam) sValue = String.Empty ' controllo il tipo di dato che si aspetta Select Case Text.TypeVar Case ConstGen.INCHES If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then sValue = Text.TypeVar & "( " & Text.Value & ")" Else sValue = Text.Value If MmToInches(sValue) Then sValue = Text.TypeVar & "( " & sValue & ")" End If Case ConstGen.MM If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then sValue = Text.Value InchesToMm(sValue) Else sValue = Text.Value End If Case ConstGen.VAL_DOUBLE sValue = Text.Value Case ConstGen.VAL_STING sValue = "'" & Text.Value & "'" End Select Return True ElseIf TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is CheckBoxParam Then Dim Text As CheckBoxParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), CheckBoxParam) sValue = String.Empty If Text.IsChecked = True Then sValue = " true" Else sValue = " false" Return True ElseIf TypeOf m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter) Is ComboBoxParam Then '-- attenzione a quando abbiamo da stampare delle stringhe! e non dei valori numerici Dim Text As ComboBoxParam = DirectCast(m_GroupChapters(IndexGroupChapters).CompoParamList(IndexChapter), ComboBoxParam) sValue = String.Empty For Index As Integer = 0 To Text.ItemList.Count - 1 If Text.SelItem = Text.ItemList(Index) Then sValue = Text.ItemListDDF(Index) : Return True Next sValue = Text.SelItem Return True End If End If Next Next Return True End Function ' lista delle riposte della funzione SaveControl Enum SaveResult As Integer nYes nNo nCancel End Enum ' restituisce il messaggio della selezione Public Function SaveControl() As SaveResult If Not Map.refMainWindowVM.ProjectNameMsg.Contains("*") Then Return SaveResult.nNo Select Case MessageBox.Show("Do you want to save the current changes?", "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question) Case MessageBoxResult.Yes ' decido di salvare Save() Return SaveResult.nYes Case MessageBoxResult.No ' decido di non salvare Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False Return SaveResult.nNo Case Else ' altrimenti interrompi sempre Return SaveResult.nCancel End Select End Function Public Function DelelteHardware() As Boolean Dim CurrDirPath As String = CurrPath() For Each ItemFile In m_TemplateList If ItemFile = m_SelTemplate Then Dim IndexList As Integer = m_TemplateList.IndexOf(m_SelTemplate) m_TemplateList.Remove(m_SelTemplate) If IndexList > 0 Then SelTemplate = m_TemplateList(IndexList - 1) ElseIf IndexList = 0 And m_TemplateList.Count > 0 Then SelTemplate = m_TemplateList(IndexList + 1) Else SelTemplate = Nothing End If Exit For End If Next If File.Exists(CurrDirPath) Then Try File.Delete(CurrDirPath) Catch ex As Exception End Try End If RefreshTemplateListEgtDOORCreator() NotifyPropertyChanged("TemplateList") Return True End Function #End Region ' Salvataggio, Duplica, Nuovo, Aggiorna Public Function CurrPath() As String Dim ModelDir As String = String.Empty ModelDir = String.Empty If m_SelBrand.ModelDir <> RegexFunction.ModelTemplate(m_HardwareGeneral.Path) Then ModelDir = m_SelBrand.ModelDirGraphic & "\" Return m_HardwareGeneral.Path & "\" & ModelDir & m_SelTemplate & LUA_EXTENSION End Function Public Sub New() ' ogni nuovo hardware che creao devo avere la lista di componenti vuota Me.ClearGroupChapters() End Sub #End Region ' Genaral Function 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 TypeHardware Inherits VMBase 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_NameINI As String Public Property NameINI As String Get Return m_NameINI End Get Set(value As String) m_NameINI = value End Set End Property Sub New(Name As String, NameINI As String) m_Name = Name m_NameINI = NameINI NotifyPropertyChanged("Name") NotifyPropertyChanged("NameINI") End Sub End Class