980d89f8ac
- Correzione liste brand ora divise per Door, Frame e Hardware.
770 lines
35 KiB
VB.net
770 lines
35 KiB
VB.net
Imports System.ComponentModel
|
|
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class Hardware
|
|
Implements INotifyPropertyChanged
|
|
|
|
Dim bTypeListExist As Boolean = False
|
|
|
|
' 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
|
|
Return m_HardwareGeneral.HardwareFolderList
|
|
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
|
|
' Carico lista template
|
|
TemplateList = m_SelBrand.ModelFileList
|
|
If Not m_VisibilityTextTemplate = Visibility.Visible And m_SelBrand.ModelFileList.Count > 0 Then
|
|
SelTemplate = m_SelBrand.ModelFileList(0)
|
|
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
|
|
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
|
|
ClearGroupChapters() ' Prima di procedere ripulisco la pagina dai vecchi paramatri
|
|
ReadChapterTemplate() ' Rileggo i parametri del SetTemplate
|
|
ReadTemplate(m_SelTemplate) ' Carico i dati del template
|
|
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_VisibilityTextTemplate As Visibility = Visibility.Collapsed
|
|
' in caso di nuovo Hardware incollo sopra alla combobox la textbox (non Collasso/Nascondo la combobox!)
|
|
Public Property VisibilityTextTemplate As Visibility
|
|
Get
|
|
If Not m_VisibilityTemplate = Visibility.Visible Then Return Visibility.Collapsed
|
|
Return m_VisibilityTextTemplate
|
|
End Get
|
|
Set(value As Visibility)
|
|
m_VisibilityTextTemplate = value
|
|
NotifyPropertyChanged("VisibilityTextTemplate")
|
|
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
|
|
Public Property SelType As TypeHardware
|
|
Get
|
|
Return m_SelType
|
|
End Get
|
|
Set(value As TypeHardware)
|
|
m_SelType = value
|
|
' se la text è visibile non passo mai dal SelTemplate quindi sposto qui il caricamento dei dati
|
|
If VisibilityTextTemplate = Visibility.Visible Then
|
|
ClearGroupChapters()
|
|
ReadChapterTemplate()
|
|
End If
|
|
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 BrandList.Count > 0 Then
|
|
SelBrand = BrandList(0)
|
|
End If
|
|
Dim ErrorList As String = String.Empty
|
|
If EgtUILib.GetPrivateProfileInt(S_TEMPLATE, K_ISACTIVE, 1, CurrCompoType.Path & "\" & CONFIGINI_FILE_NAME) = 0 Then
|
|
' If HardwareGeneral.HardwareFolderList.Count > 0 Then
|
|
' ' prendo il primo direttorio
|
|
' For IndexFile As Integer = 0 To HardwareGeneral.HardwareFolderList(0).ModelFileList.Count - 1
|
|
' TemplateList.Add(HardwareGeneral.HardwareFolderList(0).ModelFileList(IndexFile))
|
|
' Next
|
|
' 'm_SelBrand = m_BrandList(0) ' Carico il primo modello della lista
|
|
' NotifyPropertyChanged("SelBrand")
|
|
' SelTemplate = m_TemplateList(0)
|
|
' End If
|
|
'Else ' se non c'è il template
|
|
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
|
|
IniFile.m_StdTemplate = m_HardwareGeneral.Path & "\StdTemplate.ini"
|
|
If Not File.Exists(IniFile.m_StdTemplate) Then Return False
|
|
Dim List As New List(Of String) ' lista temporanea "1/Mort"
|
|
If IniFile.StdTemplateGetPrivateProfileList("Hardware", "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
|
|
m_SelType = TypeList(IndexListType)
|
|
NotifyPropertyChanged("SelType")
|
|
Exit For
|
|
End If
|
|
Next
|
|
' inizio la lettura del file lua selezionato
|
|
Dim CurrConfig As String = m_HardwareGeneral.Path & "\" & CONFIGINI_FILE_NAME
|
|
Dim ModelDir As String = String.Empty
|
|
If m_SelBrand.ModelDir <> RegexFunction.ModelTemplate(m_HardwareGeneral.Path) Then ModelDir = m_SelBrand.ModelDir & "\"
|
|
Dim CurrItemPath As String = ModelDir & value
|
|
|
|
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, CurrConfig)
|
|
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 = "In file " & CurrItemPath & " param 'Default' must be numeric."
|
|
Return False ' valore letto non è numerico
|
|
Else
|
|
For IndexListType As Integer = 0 To TypeList.Count - 1
|
|
If TypeList(IndexListType).NameINI = ConfigDefault Then
|
|
m_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, IniFile.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
|
|
If StdTemplateGetPrivateProfileChapterName(S_CHAPTER & ChapterIndex, "Name", LuaName, Name) Then
|
|
Chapter.TemplateName = Name
|
|
End If
|
|
While EgtUILib.GetPrivateProfileString(S_CHAPTER & ChapterIndex, K_PARAM & ParamIndex, "", sParam, IniFile.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, "Error", 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 ModelDir As String = String.Empty
|
|
If m_SelBrand.ModelDir <> RegexFunction.ModelTemplate(m_HardwareGeneral.Path) Then ModelDir = m_SelBrand.ModelDir & "\"
|
|
Dim CurrItemPath As String = ModelDir & sFile
|
|
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
|
|
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
|
|
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
|
|
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 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 "inch"
|
|
Dim sLen As String = Trim(Utility.GetMeasure(sValue))
|
|
Text.SetValue(sLen)
|
|
Case "mm"
|
|
Dim sLen As String = Trim(Utility.GetMeasure(sValue))
|
|
Text.SetValue(sLen)
|
|
Case "double"
|
|
Dim dVal As Double = 0.0
|
|
If StringToDouble(sValue, dVal) Then Text.SetValue(sValue) Else Text.SetValue("0.000")
|
|
Case "string"
|
|
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(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
|
|
|
|
#End Region ' Caricamneto
|
|
|
|
#Region "Salvataggio, Duplica, Aggiorna"
|
|
|
|
Public Function Duplicate(sSelBrand As String, sTemplate As String) As Boolean
|
|
If IsNothing(m_SelTemplate) Then
|
|
MessageBox.Show("Impossible to duplicate Hardware if there is no Hardware selected!", EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Exclamation)
|
|
Return False
|
|
End If
|
|
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 ModelDir As String = String.Empty
|
|
If m_SelBrand.ModelDir <> RegexFunction.ModelTemplate(m_HardwareGeneral.Path) Then ModelDir = m_SelBrand.ModelDir & "\"
|
|
Dim OldDirPath As String = m_HardwareGeneral.Path & "\" & ModelDir & m_SelTemplate & LUA_EXTENSION
|
|
' ricostruisco il nuovo file da creare
|
|
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 m_TemplateList.Count - 1
|
|
If m_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 ilnome dalla lista dei file (alla fine il nome verrà aggiunto ancora)
|
|
For IndexTempList As Integer = 0 To m_TemplateList.Count - 1
|
|
If m_TemplateList(IndexTempList) = sTemplate Then
|
|
TemplateList.RemoveAt(IndexTempList)
|
|
Exit For
|
|
End If
|
|
Next
|
|
' carico le variabili temporanee e aggiorno la grafica (lista dei file e Brand selezionato)
|
|
SelBrand.ModelDir = TemSelBrand
|
|
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
|
|
|
|
' crea il file temporaneao per aggiornare la parte grafica
|
|
Public Function RefreshTempHardware() 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)
|
|
' inizio la lettura riga per riga
|
|
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 ' 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)
|
|
Next
|
|
' costruisco il nome del percorso del file corrente
|
|
Dim sTempFileHardw As String = m_HardwareGeneral.Path & "\" & TEMP_FILE_HARDWARE
|
|
' salvo il file
|
|
File.WriteAllLines(sTempFileHardw, FileContent)
|
|
' aggiungo la componente
|
|
Map.refHardwarePageVM.Door.CompoList.Clear()
|
|
Map.refHardwarePageVM.Door.AddNewHardware(m_HardwareGeneral, Path.GetFileNameWithoutExtension(TEMP_FILE_HARDWARE))
|
|
'Map.refSceneManagerVM.RefreshBtn()
|
|
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)
|
|
' inizio la lettura riga per riga
|
|
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 ' 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)
|
|
Next
|
|
' costruisco il nome del percorso del file corrente
|
|
Dim CurrConfig As String = m_HardwareGeneral.Path & "\" & CONFIGINI_FILE_NAME
|
|
Dim ModelDir As String = String.Empty
|
|
If m_SelBrand.ModelDir <> RegexFunction.ModelTemplate(m_HardwareGeneral.Path) Then ModelDir = m_SelBrand.ModelDir & "\"
|
|
Dim CurrItemPath As String = m_HardwareGeneral.Path & "\" & ModelDir & m_SelTemplate & LUA_EXTENSION
|
|
' devo controllare che il file con questo nome non esiste (solo nel caso di TextTemplate visibile)
|
|
If VisibilityTextTemplate = Visibility.Visible Then
|
|
Dim bNameExist As Boolean = False
|
|
Dim IndexHardwList As Integer
|
|
For IndexHardwList = 0 To m_TemplateList.Count - 1
|
|
If m_TemplateList(IndexHardwList) = m_SelTemplate 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: " & m_SelTemplate & " already exist in directory " & m_SelBrand.ModelDir & " . Do you want to overwrite it?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning)
|
|
' decido di sovrescrivere il file esistente
|
|
Case MessageBoxResult.Yes
|
|
' salvo il file
|
|
File.WriteAllLines(CurrItemPath, FileContent)
|
|
Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False
|
|
Return True
|
|
Case Else
|
|
' deicido di non sovrescrivere interrompo
|
|
Return False
|
|
End Select
|
|
End If
|
|
End If
|
|
' salvo il file
|
|
File.WriteAllLines(CurrItemPath, FileContent)
|
|
RefreshTemplateListEgtDOORCreator()
|
|
Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = 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 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
|
|
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 "inch"
|
|
If OptionModule.m_SelectedMeasureUnit = "Inches" Then
|
|
sValue = Text.TypeVar & "( " & Text.Value & ")"
|
|
Else
|
|
sValue = Text.Value
|
|
If MmToInches(sValue) Then sValue = Text.TypeVar & "( " & sValue & ")"
|
|
End If
|
|
Case "mm"
|
|
If OptionModule.m_SelectedMeasureUnit = "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 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 "inch"
|
|
If OptionModule.m_SelectedMeasureUnit = "Inches" Then
|
|
sValue = Text.TypeVar & "( " & Text.Value & ")"
|
|
Else
|
|
sValue = Text.Value
|
|
If MmToInches(sValue) Then sValue = Text.TypeVar & "( " & sValue & ")"
|
|
End If
|
|
Case "mm"
|
|
If OptionModule.m_SelectedMeasureUnit = "Inches" Then
|
|
sValue = Text.Value
|
|
InchesToMm(sValue)
|
|
Else
|
|
sValue = Text.Value
|
|
End If
|
|
Case "double"
|
|
sValue = Text.Value
|
|
Case "string"
|
|
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
|
|
|
|
#End Region ' Salvataggio, Duplica, Aggiorna
|
|
|
|
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
|