Files
egtbeamwall/EgtBEAMWALL.Supervisor/ConfigurationPage/ConfigurationPageVM.vb
T
2021-11-04 18:01:43 +01:00

779 lines
28 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Imports EgtBEAMWALL.Core
Public Class ConfigurationPageVM
Inherits VMBase
' Definizione comandi
Private m_cmdSave As ICommand
Private m_cmdAddVariable As ICommand
Private m_cmdRemoveVariable As ICommand
' Contatore delle variabili rimosse per successiva rimozione dal file INI
Friend m_RemovedVarsCount As Integer = 0
Private m_LanguageList As New ObservableCollection(Of Language)
Public ReadOnly Property LanguageList As ObservableCollection(Of Language)
Get
Return m_LanguageList
End Get
End Property
Private m_UnitMeasureList As List(Of String) = New List(Of String)({"inch", "mm"})
Public ReadOnly Property UnitMeasureList As List(Of String)
Get
Return m_UnitMeasureList
End Get
End Property
Private m_SelectedLanguage As Language
Public Property SelectedLanguage As Language
Get
Return m_SelectedLanguage
End Get
Set(value As Language)
If value IsNot m_SelectedLanguage Then
m_SelectedLanguage = value
End If
End Set
End Property
Public Property SelMeasureUnit As Integer
Get
Return If(EgtUiUnitsAreMM(), MeasureUnitOpt.MM, MeasureUnitOpt.INCH)
End Get
Set(value As Integer)
' salvo unità di misura precedente
Dim PrevMeasureUnit As MeasureUnitOpt = If(EgtUiUnitsAreMM(), MeasureUnitOpt.MM, MeasureUnitOpt.INCH)
If value <> PrevMeasureUnit Then
' cambio unità di misura
EgtSetUiUnits(DirectCast(value, MeasureUnitOpt) = MeasureUnitOpt.MM)
End If
End Set
End Property
' lista delle colonne con le relative proprietà della DataGrid
Private m_DGColumnsList_View As CollectionView = Nothing
Protected m_DGColumnsList As New ObservableCollection(Of IniDataGridColumn)
Public Property DGColumnsList As ObservableCollection(Of IniDataGridColumn)
Get
Return m_DGColumnsList
End Get
Set(value As ObservableCollection(Of IniDataGridColumn))
m_DGColumnsList = value
End Set
End Property
Protected m_VariablesColumns As New ObservableCollection(Of EgtDataGridColumn)
Public Property VariablesColumns As ObservableCollection(Of EgtDataGridColumn)
Get
Return m_VariablesColumns
End Get
Set(value As ObservableCollection(Of EgtDataGridColumn))
m_VariablesColumns = value
End Set
End Property
Private m_VariablesList As New ObservableCollection(Of ConfigVariable)
Public Property VariablesList As ObservableCollection(Of ConfigVariable)
Get
Return m_VariablesList
End Get
Set(value As ObservableCollection(Of ConfigVariable))
m_VariablesList = value
End Set
End Property
Private m_SelVariable As ConfigVariable
Public Property SelVariable As ConfigVariable
Get
Return m_SelVariable
End Get
Set(value As ConfigVariable)
m_SelVariable = value
End Set
End Property
#Region "Messages"
Public ReadOnly Property L_Msg As String
Get
Return EgtMsg(61803)
End Get
End Property
Public ReadOnly Property T_Msg As String
Get
Return EgtMsg(61804)
End Get
End Property
Public ReadOnly Property PRC_Msg As String
Get
Return EgtMsg(61805)
End Get
End Property
Public ReadOnly Property NAM_Msg As String
Get
Return EgtMsg(61608)
End Get
End Property
Public ReadOnly Property Description_Msg As String
Get
Return EgtMsg(61603)
End Get
End Property
Public ReadOnly Property Default_Msg As String
Get
Return EgtMsg(61802)
End Get
End Property
Public ReadOnly Property Min_Msg As String
Get
Return EgtMsg(61616)
End Get
End Property
Public ReadOnly Property Max_Msg As String
Get
Return EgtMsg(61617)
End Get
End Property
Public ReadOnly Property CurrentLanguage_Msg As String
Get
Return EgtMsg(6501)
End Get
End Property
Public ReadOnly Property LanguageAdvert_Msg As String
Get
Return EgtMsg(6502)
End Get
End Property
Public ReadOnly Property MMUnits_Msg As String
Get
Return EgtMsg(6540)
End Get
End Property
Public ReadOnly Property DisplayIndex_Msg As String
Get
Return EgtMsg(61842)
End Get
End Property
Public ReadOnly Property ColumnName_Msg As String
Get
Return EgtMsg(61843)
End Get
End Property
Public ReadOnly Property CanUserReorder_Msg As String
Get
Return EgtMsg(61844)
End Get
End Property
Public ReadOnly Property CanUserResize_Msg As String
Get
Return EgtMsg(61845)
End Get
End Property
Public ReadOnly Property CanUserSort_Msg As String
Get
Return EgtMsg(61846)
End Get
End Property
Public ReadOnly Property IsReadOnly_Msg As String
Get
Return EgtMsg(61847)
End Get
End Property
Public ReadOnly Property Visible_Msg As String
Get
Return EgtMsg(61848)
End Get
End Property
Public ReadOnly Property Name_Msg As String
Get
Return EgtMsg(61808)
End Get
End Property
Public ReadOnly Property VarPath_Msg As String
Get
Return EgtMsg(61849)
End Get
End Property
Public ReadOnly Property Type_Msg As String
Get
Return EgtMsg(61850)
End Get
End Property
#End Region ' Messages
#Region "Constructor"
Sub New()
' imposto riferimento in Map
Map.SetRefConfigurationPageVM(Me)
' Leggo nome lingua corrente
Dim sLanguage As String = String.Empty
GetMainPrivateProfileString(S_GENERAL, K_MESSAGES, "", sLanguage)
' Leggo elenco lingue disponibili da file ini e imposto lingua corrente
Dim nIndex As Integer = 1
While True
Dim ReadLanguage As Language = GetMainPrivateProfileLanguage(S_LANGUAGES, K_LANGUAGE & nIndex)
If IsNothing(ReadLanguage) Then Exit While
m_LanguageList.Add(ReadLanguage)
If String.Compare(ReadLanguage.Name, sLanguage, True) = 0 Then
m_SelectedLanguage = ReadLanguage
End If
nIndex += 1
End While
' Inizializzo la lingua corrente
m_SelectedLanguage = m_LanguageList(0)
Dim sMsgName As String = String.Empty
IniFile.GetMainPrivateProfileString(S_GENERAL, K_MESSAGES, "", sMsgName)
For Each Language In m_LanguageList
If Language.Name = sMsgName Then
m_SelectedLanguage = Language
Exit For
End If
Next
' carico la lista delle colonne delle DataGrid in ConfigurationPage
LoadConfigDGColumns()
' setto il grouping ad 1 livello per la DataGrid
m_DGColumnsList_View = CollectionViewSource.GetDefaultView(m_DGColumnsList)
m_DGColumnsList_View.GroupDescriptions.Add(New PropertyGroupDescription(NameOf(IniDataGridColumn.VisParentDataGridName)))
' carico la lista delle colonne delle variabili della macchina in ConfigurationPage
GetPrivateProfileColumns(S_VARIABLESLIST, VariablesColumns)
' carico le Variables della macchina
LoadVariables()
End Sub
#End Region ' Constructor
#Region "SaveCommand"
''' <summary>
''' Returns a command that do Save.
''' </summary>
Public ReadOnly Property SaveCommand As ICommand
Get
If m_cmdSave Is Nothing Then
m_cmdSave = New Command(AddressOf Save)
End If
Return m_cmdSave
End Get
End Property
''' <summary>
''' Execute the Save. This method is invoked by the SaveCommand.
''' </summary>
Public Sub Save()
WriteVariables()
WriteDataGridColumns()
WriteMainPrivateProfileString(S_GENERAL, K_MESSAGES, m_SelectedLanguage.Name)
WriteMainPrivateProfileString(S_SCENE, K_MMUNITS, SelMeasureUnit.ToString())
End Sub
#End Region ' SaveCommand
#Region "AddVariable"
Public ReadOnly Property AddVariable_Command As ICommand
Get
If m_cmdAddVariable Is Nothing Then
m_cmdAddVariable = New Command(AddressOf AddVariable)
End If
Return m_cmdAddVariable
End Get
End Property
Public Sub AddVariable()
VariablesList.Add(New ConfigVariable("[Name]", "[VariablePath]", "plc"))
End Sub
#End Region ' AddVariable
#Region "RemoveVariable"
Public ReadOnly Property RemoveVariable_Command As ICommand
Get
If m_cmdRemoveVariable Is Nothing Then
m_cmdRemoveVariable = New Command(AddressOf RemoveVariable)
End If
Return m_cmdRemoveVariable
End Get
End Property
Public Sub RemoveVariable()
VariablesList.Remove(SelVariable)
m_RemovedVarsCount += 1
End Sub
#End Region ' RemoveVariable
#Region "Methods"
' funzione che verifica la modifica dei valori in Configurazione e ne chiede il salvataggio
Friend Sub VerifyConfigPageModification()
' verifico se i valori delle colonne DataGrid sono stati modificati
For Each DGColumnItem In DGColumnsList
If DGColumnItem.IsModified Then
If MessageBox.Show(EgtMsg(61882), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
' scrivo i valori delle colonne DataGrid modificate
WriteDataGridColumns()
Else
' se da non salvare li resetto ed esco dai For
LoadConfigDGColumns()
Exit For
End If
End If
Next
End Sub
' funzione che carica la DataGrid di configurazione delle colonne delle EgtDataGrid
Public Sub LoadConfigDGColumns()
DGColumnsList.Clear()
GetPrivateProfileIniColumns(S_OPENPROJFILEDLG_PROD, DGColumnsList)
GetPrivateProfileIniColumns(S_RAWPARTLIST_SUPERVISOR, DGColumnsList)
GetPrivateProfileIniColumns(S_PARTINRAWPARTLIST_SUPERVISOR, DGColumnsList)
GetPrivateProfileIniColumns(S_FEATUREINPARTINRAWPARTLIST_SUPERVISOR, DGColumnsList)
GetPrivateProfileIniColumns(S_VARIABLESLIST, DGColumnsList)
End Sub
' funzione per calcolare e scrivere la stringhe dei parametri delle colonne relative ad una ParentDataGridName nell'INI
Public Sub SaveDataGridColumns(ParentDataGridName As String, DGColumnsList As ObservableCollection(Of IniDataGridColumn))
For Each ColumnItem In DGColumnsList
If ColumnItem.ParentDataGridName = ParentDataGridName Then
Dim sColumnParams = String.Empty
sColumnParams = ColumnItem.Name & "," & If(ColumnItem.CanUserReorder, 1, 0) & "," & If(ColumnItem.CanUserResize, 1, 0) & "," &
If(ColumnItem.CanUserSort, 1, 0) & "," & If(ColumnItem.IsReadOnly, 1, 0) & "," & DoubleToString(ColumnItem.Width.Value, 6) & "," &
ColumnItem.Width.UnitType & "," & If(ColumnItem.Visible, 1, 0) & "," & If(ColumnItem.CanUserEditVisible, 1, 0)
WriteColumnPrivateProfileParam(ParentDataGridName, ColumnItem.m_DisplayIndex, sColumnParams)
End If
Next
End Sub
' funzione che scrive i valori delle proprietà delle colonne customizzate delle EgtDataGrid nell'INI
Public Sub WriteDataGridColumns()
SaveDataGridColumns(S_OPENPROJFILEDLG_PROD, DGColumnsList)
SaveDataGridColumns(S_RAWPARTLIST_SUPERVISOR, DGColumnsList)
SaveDataGridColumns(S_PARTINRAWPARTLIST_SUPERVISOR, DGColumnsList)
SaveDataGridColumns(S_FEATUREINPARTINRAWPARTLIST_SUPERVISOR, DGColumnsList)
SaveDataGridColumns(S_VARIABLESLIST, DGColumnsList)
For Each DGColumnItem In DGColumnsList
DGColumnItem.IsModifiedReset()
Next
End Sub
' funzione che legge le variabili della macchina dall'INI
Public Sub LoadVariables()
VariablesList = New ObservableCollection(Of ConfigVariable)
Dim VarIndex As Integer = 1
Dim sValue As String = Nothing
While EgtUILib.GetPrivateProfileString(S_VARIABLES, VarIndex, String.Empty, sValue, CurrentMachine.sMachIniFile)
Dim sVariableValues() As String = sValue.Split(","c)
' verifico numero minimo di parametri
If sVariableValues.Count >= 4 Then
' cancello spazi
For Index = 0 To sVariableValues.Count - 1
sVariableValues(Index) = sVariableValues(Index).Trim()
Next
' creo parametro
Dim sName As String = sVariableValues(0)
Dim sVarPath As String = sVariableValues(1)
Dim sType As String = sVariableValues(3)
VariablesList.Add(New ConfigVariable(sName, sVarPath, sType))
End If
VarIndex += 1
End While
End Sub
' funzione che scrive i valori delle variabili della macchina nell'INI
Public Sub WriteVariables()
Dim VarIndex = 1
For Each VarItem In VariablesList
Dim VarStr As String = VarItem.sName & ", " & VarItem.sVarPath & ", c, " & VarItem.SelType
WritePrivateProfileString(S_VARIABLES, VarIndex, VarStr, CurrentMachine.sMachIniFile)
VarIndex += 1
Next
' Se ci sono variabili da rimuovere le rimuovo
For Index = VarIndex To VarIndex + m_RemovedVarsCount
WritePrivateProfileString(S_VARIABLES, Index, Nothing, CurrentMachine.sMachIniFile)
Next
End Sub
#End Region ' Methods
End Class
Public Class IniDataGridColumn
Private Property m_ParentDataGridName As String
Public Property ParentDataGridName As String
Get
Return m_ParentDataGridName
End Get
Set(value As String)
m_ParentDataGridName = value
End Set
End Property
' Nome datagrid di cui fa parte la colonna visualizzato nell'interfaccia
Public ReadOnly Property VisParentDataGridName As String
Get
Return ParentDataGridName.Replace(ParentDataGridName.Substring(0, 3), "").Trim()
End Get
End Property
Private Property 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
' Nome colonna visualizzato nell'interfaccia
Public ReadOnly Property VisName As String
Get
Return Name.Replace(Name.Substring(0, 3), "").Trim()
End Get
End Property
Private Property m_Width As DataGridLength
Public Property Width As DataGridLength
Get
Return m_Width
End Get
Set(value As DataGridLength)
m_Width = value
End Set
End Property
Private m_IsModifiedDisplayIndex
Friend Property m_DisplayIndex As Integer
Public Property DisplayIndex As Integer
Get
Return If(Visible, m_DisplayIndex, -1)
End Get
Set(value As Integer)
m_DisplayIndex = value
m_IsModifiedDisplayIndex = (m_Name <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.NAME))
' se DisplayIndex viene settato ad un valore che corrisponde a quello che aveva inizialmente aggiorno gli IsModified
' delle altre proprietà utilizzando il DisplayIndex attuale
If Not m_IsModifiedDisplayIndex Then
m_IsModifiedIsReadOnly = (m_IsReadOnly <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.ISREADONLY))
m_IsModifiedCanUserReorder = (m_CanUserReorder <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.REORDER))
m_IsModifiedCanUserResize = (m_CanUserResize <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.RESIZE))
m_IsModifiedCanUserSort = (m_CanUserSort <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.SORT))
m_IsModifiedVisible = (m_Visible <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.VISIBLE))
End If
End Set
End Property
Private m_IsModifiedIsReadOnly As Boolean = False
Private Property m_IsReadOnly As Boolean = True
Public Property IsReadOnly As Boolean
Get
Return m_IsReadOnly
End Get
Set(value As Boolean)
m_IsReadOnly = value
m_IsModifiedIsReadOnly = (m_IsReadOnly <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.ISREADONLY))
End Set
End Property
Private m_IsModifiedCanUserReorder As Boolean = False
Private m_CanUserReorder As Boolean
Public Property CanUserReorder As Boolean
Get
Return m_CanUserReorder
End Get
Set(value As Boolean)
m_CanUserReorder = value
m_IsModifiedCanUserReorder = (m_CanUserReorder <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.REORDER))
End Set
End Property
Private m_IsModifiedCanUserResize As Boolean = False
Private m_CanUserResize As Boolean
Public Property CanUserResize As Boolean
Get
Return m_CanUserResize
End Get
Set(value As Boolean)
m_CanUserResize = value
m_IsModifiedCanUserResize = (m_CanUserResize <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.RESIZE))
End Set
End Property
Private m_IsModifiedCanUserSort As Boolean = False
Private m_CanUserSort As Boolean
Public Property CanUserSort As Boolean
Get
Return m_CanUserSort
End Get
Set(value As Boolean)
m_CanUserSort = value
m_IsModifiedCanUserSort = (m_CanUserSort <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.SORT))
End Set
End Property
Private m_IsModifiedVisible As Boolean = False
Private m_Visible As Boolean
Public Property Visible As Boolean
Get
Return m_Visible
End Get
Set(value As Boolean)
m_Visible = value
' Utilizzo OldDGIndex e NewDGIndex per muovere la Column tra il gruppo dei Visible (in alto) o il gruppo
' dei non Visible (in basso): in ambo i casi verrà sempre spostata in mezzo ai due raggruppamenti
Dim OldDGIndex As Integer = Map.refConfigurationPageVM.DGColumnsList.IndexOf(Me)
If value Then
Dim NewDGIndex As Integer = Map.refConfigurationPageVM.DGColumnsList.IndexOf(Map.refConfigurationPageVM.DGColumnsList.FirstOrDefault(
Function(x) x.ParentDataGridName = ParentDataGridName AndAlso
x.Visible = False))
' se NewDGIndex = -1 (ovvero ho settato l'ultima Column rimasta non Visible a Visible) oppure
' se il nuovo indice è subito dopo il vecchio non la sposto altrimenti viene spostata in maniera sbagliata
If NewDGIndex <> -1 AndAlso NewDGIndex <> OldDGIndex + 1 Then Map.refConfigurationPageVM.DGColumnsList.Move(OldDGIndex, NewDGIndex)
Else
Dim NewDGIndex As Integer = Map.refConfigurationPageVM.DGColumnsList.IndexOf(Map.refConfigurationPageVM.DGColumnsList.FirstOrDefault(
Function(x) x.ParentDataGridName = ParentDataGridName AndAlso
x.Visible = False AndAlso
x.Name <> Name))
' se NewDGIndex = -1 vuol dire che erano tutte settate a Visible perciò devo calcolare l'indice
' dell'ultima Column con quel ParentDataGridName e spostarlo lì
If NewDGIndex = -1 Then
Dim FirstIndex As Integer = Map.refConfigurationPageVM.DGColumnsList.IndexOf(Map.refConfigurationPageVM.DGColumnsList.FirstOrDefault(
Function(x) x.ParentDataGridName = ParentDataGridName))
Dim LastIndex = FirstIndex
While LastIndex < Map.refConfigurationPageVM.DGColumnsList.Count AndAlso Map.refConfigurationPageVM.DGColumnsList(LastIndex).ParentDataGridName = ParentDataGridName
LastIndex += 1
End While
NewDGIndex = LastIndex
End If
Map.refConfigurationPageVM.DGColumnsList.Move(OldDGIndex, NewDGIndex - 1)
End If
' aggiorno i DisplayIndex di ciascuna Column della ParentDataGridName in questione
Dim index = 0
For Each DGColumnItem In Map.refConfigurationPageVM.DGColumnsList
If DGColumnItem.ParentDataGridName = ParentDataGridName Then
DGColumnItem.DisplayIndex = index
index += 1
End If
Next
' uso il Move col medesimo valore per i 2 argomenti per refreshare i DisplayIndex delle Column
' della ParentDataGridName in questione appena riordinate
For index = 0 To Map.refConfigurationPageVM.DGColumnsList.Count - 1
If Map.refConfigurationPageVM.DGColumnsList(index).ParentDataGridName = ParentDataGridName Then
Map.refConfigurationPageVM.DGColumnsList.Move(index, index)
End If
Next
' setto se il valore è stato modificato, a partire dalla verifica che il Nome e DisplayIndex combacino (altrimenti è per forza modificato)
m_IsModifiedVisible = (m_Name <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.NAME)) OrElse
(If(m_Visible, 1, 0) <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.VISIBLE))
End Set
End Property
Private m_CanUserEditVisible As Boolean
Public Property CanUserEditVisible As Boolean
Get
Return m_CanUserEditVisible
End Get
Set(value As Boolean)
m_CanUserEditVisible = value
End Set
End Property
Public ReadOnly Property IsModified() As Boolean
Get
Return m_IsModifiedDisplayIndex OrElse
m_IsModifiedIsReadOnly OrElse
m_IsModifiedCanUserReorder OrElse
m_IsModifiedCanUserResize OrElse
m_IsModifiedCanUserSort OrElse
m_IsModifiedVisible
End Get
End Property
Public Sub IsModifiedReset()
m_IsModifiedDisplayIndex = False
m_IsModifiedIsReadOnly = False
m_IsModifiedCanUserReorder = False
m_IsModifiedCanUserResize = False
m_IsModifiedCanUserSort = False
m_IsModifiedVisible = False
End Sub
Sub New(sName As String)
m_Name = sName
End Sub
Sub New(sParentDG As String, nDisplayIndex As Integer, sName As String, bCanUserReorder As Boolean, bCanUserResize As Boolean, bCanUserSort As Boolean, bIsReadOnly As Boolean, Width As DataGridLength, bVisible As Boolean, bCanUserEditVisible As Boolean)
m_ParentDataGridName = sParentDG
m_DisplayIndex = nDisplayIndex
m_Name = sName
m_CanUserReorder = bCanUserReorder
m_CanUserResize = bCanUserResize
m_CanUserSort = bCanUserSort
m_IsReadOnly = bIsReadOnly
m_Width = Width
m_Visible = bVisible
m_CanUserEditVisible = bCanUserEditVisible
End Sub
End Class
Public Class ConfigVariable
Private m_sName As String
Public Property sName As String
Get
Return m_sName
End Get
Set(value As String)
m_sName = value
End Set
End Property
Private m_sVarPath As String
Public Property sVarPath As String
Get
Return m_sVarPath
End Get
Set(value As String)
m_sVarPath = value
End Set
End Property
Private m_SelType As String
Public Property SelType As String
Get
Return m_SelType
End Get
Set(value As String)
m_SelType = value
End Set
End Property
Private m_TypeList As New ObservableCollection(Of String)({"plc", "cn"})
Public Property TypeList As ObservableCollection(Of String)
Get
Return m_TypeList
End Get
Set(value As ObservableCollection(Of String))
m_TypeList = value
End Set
End Property
Sub New(Name As String, VarPath As String, Type As String)
m_sName = Name
m_sVarPath = VarPath
m_SelType = TypeList.FirstOrDefault(Function(x) x = Type)
End Sub
End Class
'' Tipo parametro nel file di configurazione Macchina
'Public Enum MachParamType As Integer
' DOUBLE_ = 1
' STRING_ = 2
' COMBO = 3
' LENGTH = 4
' CHECKBOX = 5
'End Enum
Public Module IniDataGridColumnFunctions
' funzione per ottenere dal file INI le colonne da caricare nella DataGrid usata per customizzare le proprietà delle colonne delle EgtDataGrid del programma
Public Function GetPrivateProfileIniColumns(ParentDGName As String, ByRef ocColumns As ObservableCollection(Of IniDataGridColumn)) As Boolean
Dim colIndex As Integer = 0
Dim str = String.Empty
While EgtUILib.GetPrivateProfileString(ParentDGName, colIndex, String.Empty, str, m_sDataGridColumnsIniFile) > 0
Dim sColumnParams() As String = str.Split(","c)
' verifico numero minimo di parametri
If sColumnParams.Count >= 9 Then
' cancello spazi
For index = 0 To sColumnParams.Count - 1
sColumnParams(index) = sColumnParams(index).Trim()
Next
' creo colonna
Dim sName = sColumnParams(0)
Dim bReorder As Boolean = sColumnParams(1).Equals("1")
Dim bResize As Boolean = sColumnParams(2).Equals("1")
Dim bSort As Boolean = sColumnParams(3).Equals("1")
Dim bIsReadOnly As Boolean = sColumnParams(4).Equals("1")
Dim Width As Double
Dim WidthType As DataGridLengthUnitType
StringToDouble(sColumnParams(5), Width)
Integer.TryParse(sColumnParams(6), WidthType)
Dim bVisible As Boolean = sColumnParams(7).Equals("1")
Dim bCanUserEditVisible As Boolean = sColumnParams(8).Equals("1")
ocColumns.Add(New IniDataGridColumn(ParentDGName, colIndex, sName, bReorder, bResize, bSort, bIsReadOnly, New DataGridLength(Width, WidthType), bVisible, bCanUserEditVisible))
End If
colIndex += 1
End While
Return ocColumns.Count > 0
End Function
' funzione che ottiene dal file INI la singola proprietà legata ad una specifica colonna
Public Function GetPrivateProfileIniColumnProperty(ParentDGName As String, ocColumns As ObservableCollection(Of IniDataGridColumn), DisplayIndex As Integer, PropertyIndex As EgtDGColumnProperty) As String
Dim str = String.Empty
If EgtUILib.GetPrivateProfileString(ParentDGName, DisplayIndex, String.Empty, str, m_sDataGridColumnsIniFile) > 0 Then
Dim sColumnParams() As String = str.Split(","c)
' verifico numero minimo di parametri
If sColumnParams.Count >= 9 Then
' cancello spazi
For index = 0 To sColumnParams.Count - 1
sColumnParams(index) = sColumnParams(index).Trim()
Next
If PropertyIndex > -1 AndAlso PropertyIndex < sColumnParams.Count Then Return sColumnParams(PropertyIndex)
End If
End If
Return ""
End Function
Public Enum EgtDGColumnProperty
NAME = 0
REORDER = 1
RESIZE = 2
SORT = 3
ISREADONLY = 4
WIDTH = 5
WIDTHTYPE = 6
VISIBLE = 7
EDITVISIBLE = 8
End Enum
End Module