Files
2021-09-22 19:13:52 +02:00

453 lines
14 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Imports EgtPHOTOLib
Public Class OptionWindowVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Private m_LanguageList As New List(Of Language)
Public ReadOnly Property LanguageList As List(Of Language)
Get
Return m_LanguageList
End Get
End Property
Private m_SelLanguage As Language
Public Property SelLanguage As Language
Get
Return m_SelLanguage
End Get
Set(value As Language)
If value IsNot m_SelLanguage Then
m_SelLanguage = value
WriteMainPrivateProfileString(S_GENERAL, K_MESSAGES, m_SelLanguage.Name)
End If
End Set
End Property
Private m_MeasureUnitList As New List(Of String)({"inch", "mm"})
Public ReadOnly Property MeasureUnitList As List(Of String)
Get
Return m_MeasureUnitList
End Get
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)
Map.refStatusBarVM.SetMeasureUnit(value)
WriteMainPrivateProfileString(S_GENERAL, K_MMUNITS, value.ToString())
' aggiorno tolleranza spessore
NotifyPropertyChanged("ThicknessTolerance")
If Map.refProjectVM.SelProjectMode = ProjectSlabVM.ProjectModeOpt.DETAIL Then
' aggiorno spessore in OptionPanel
Map.refOptionPanelVM.SelSlab.NotifyPropertyChanged("Thickness")
ElseIf Map.refProjectVM.SelProjectMode = ProjectSlabVM.ProjectModeOpt.LIST Then
' aggiorno spessore nei tooltip delle lastre della lista
For Each Slab In Map.refProjectVM.SlabList
Slab.NotifyPropertyChanged("Slab_Tooltip")
Next
End If
End If
End Set
End Property
Public ReadOnly Property LabelFileName As String
Get
Return Map.refMainWindowVM.MainWindowM.sTemplateFilePrinter
End Get
End Property
Public ReadOnly Property LabelVisibility As Visibility
Get
If Map.refMainWindowVM.MainWindowM.PrinterIsVisible Then
Return Visibility.Visible
Else
Return Visibility.Collapsed
End If
End Get
End Property
Private m_ThicknessTolerance As Double
Public Property ThicknessTolerance As String
Get
Return LenToString(m_ThicknessTolerance, -2)
End Get
Set(value As String)
Dim dThicknessTolerance As Double = 0
If StringToLen(value, dThicknessTolerance) And dThicknessTolerance > -EPS_ZERO Then
m_ThicknessTolerance = dThicknessTolerance
WriteMainPrivateProfileString(S_SEARCH, K_THICKNESSTOLERANCE, DoubleToString(m_ThicknessTolerance, 2))
Else
NotifyPropertyChanged("ThicknessTolerance")
' Non sono ammessi spessori negativi
Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 18)
MessageBox.Show(sMsg)
End If
End Set
End Property
Private Sub SetThicknessTolerance(value As Double)
m_ThicknessTolerance = value
NotifyPropertyChanged("ThicknessTolerance")
End Sub
#Region "Material"
Private m_MaterialList As ObservableCollection(Of String)
Public ReadOnly Property MaterialList As ObservableCollection(Of String)
Get
Return m_MaterialList
End Get
End Property
Private m_SelMaterial As String
Public Property SelMaterial As String
Get
Return m_SelMaterial
End Get
Set(value As String)
m_SelMaterial = value
End Set
End Property
Private m_NewMatName As String
Public Property NewMatName As String
Get
Return m_NewMatName
End Get
Set(value As String)
m_NewMatName = value
' Verifico che il nome non sia vuoto
AddNewMaterial()
NotifyPropertyChanged("EnableOkNewMat")
End Set
End Property
Private m_EnableOkNewMat As Boolean = False
Public Property EnableOkNewMat As Boolean
Get
Return m_EnableOkNewMat
End Get
Set(value As Boolean)
m_EnableOkNewMat = value
End Set
End Property
Private m_NewMatName_Visibility As Visibility = Visibility.Collapsed
Public Property NewMatName_Visibility As Visibility
Get
Return m_NewMatName_Visibility
End Get
Set(value As Visibility)
m_NewMatName_Visibility = value
NotifyPropertyChanged("NewMatName_Visibility")
End Set
End Property
#End Region ' Material
#Region "Messages"
Public ReadOnly Property Title As String
Get
Return EgtMsg(MSG_OPTIONSPAGEUC + 1)
End Get
End Property
Public ReadOnly Property CurrentLanguageMsg As String
Get
Return EgtMsg(MSG_OPTIONSPAGEUC + 1)
End Get
End Property
Public ReadOnly Property LanguageAdvertMsg As String
Get
Return EgtMsg(MSG_OPTIONSPAGEUC + 2)
End Get
End Property
Public ReadOnly Property MeasureUnitMsg As String
Get
Return EgtMsg(MSG_OPTIONSPAGEUC + 3)
End Get
End Property
Public ReadOnly Property SearchMsg As String
Get
Return EgtMsg(MSG_SEARCHPANEL + 1)
End Get
End Property
Public ReadOnly Property ThicknessToleranceMsg As String
Get
Return EgtMsg(MSG_SEARCHPANEL + 2)
End Get
End Property
Public ReadOnly Property MaterialsMsg As String
Get
Return EgtMsg(MSG_ALARMSPAGEUC + 13)
End Get
End Property
Public ReadOnly Property NewMatMsg As String
Get
Return EgtMsg(MSG_ALARMSPAGEUC + 34)
End Get
End Property
Public ReadOnly Property RemoveMatMsg As String
Get
Return EgtMsg(MSG_ALARMSPAGEUC + 35)
End Get
End Property
Public ReadOnly Property BrowseMsg As String
Get
Return EgtMsg(92058)
End Get
End Property
Public ReadOnly Property LabelMsg As String
Get
Return EgtMsg(92056)
End Get
End Property
Public ReadOnly Property OkMsg As String
Get
Return "Ok"
End Get
End Property
Public ReadOnly Property CancelMsg As String
Get
Return "Cancel"
End Get
End Property
#End Region ' Messages
' Definizione comandi
Private m_cmdNewMat As ICommand
Private m_cmdRemoveMat As ICommand
Private m_cmdBrowse As ICommand
Private m_cmdOk As ICommand
Private m_cmdCanel As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' 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_SelLanguage = ReadLanguage
End If
nIndex += 1
End While
' Copio lista materiali
m_MaterialList = New ObservableCollection(Of String)(Map.refProjectVM.MaterialList)
' Leggo tolleranza spessore
SetThicknessTolerance(GetMainPrivateProfileDouble(S_SEARCH, K_THICKNESSTOLERANCE, 0))
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub CloseOptionWindow()
' Aggiorno lista materiali
Map.refProjectVM.MaterialList = New List(Of String)(m_MaterialList)
' Aggiorno lista materiali per ricerca
Map.refSearchPanelVM.InitSearchPanel()
' Scrivo lista materiali da file ini
Dim Index As Integer
For Index = 0 To m_MaterialList.Count - 1
WriteMainPrivateProfileString(S_MATERIALS, K_MATERIAL & (Index + 1).ToString, m_MaterialList(Index))
Next
' Cancello eventuali successivi rimasti
Dim sMaterial As String = String.Empty
While GetMainPrivateProfileString(S_MATERIALS, K_MATERIAL & Index, "", sMaterial) > 0
WriteMainPrivateProfileString(S_MATERIALS, K_MATERIAL & (Index + 1).ToString, String.Empty)
Index += 1
End While
End Sub
Private Function AddNewMaterial() As Boolean
If Not String.IsNullOrWhiteSpace(m_NewMatName) Then
' Verifico che il nome non sia già utilizzato
Dim bNameExist As Boolean = False
For Each Material In m_MaterialList
If Material = m_NewMatName Then
bNameExist = True
Exit For
End If
Next
If Not bNameExist Then
'm_MaterialList.Add(m_NewMatName)
m_EnableOkNewMat = True
Return True
End If
End If
' ' Nascondo textbox per il nome
' NewMatName_Visibility = Visibility.Collapsed
' m_NewMatName = String.Empty
m_EnableOkNewMat = False
Return False
End Function
#End Region
#Region "COMMANDS"
#Region "NewMatCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property NewMatCommand As ICommand
Get
If m_cmdNewMat Is Nothing Then
m_cmdNewMat = New Command(AddressOf NewMat)
End If
Return m_cmdNewMat
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub NewMat(ByVal param As Object)
NewMatName_Visibility = Visibility.Visible
End Sub
#End Region ' NewMatCommand
#Region "OkCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property OkCommand As ICommand
Get
If m_cmdOk Is Nothing Then
m_cmdOk = New Command(AddressOf OkMat)
End If
Return m_cmdOk
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub OkMat(ByVal param As Object)
' aggiungo il materiale alla lista
m_MaterialList.Add(m_NewMatName)
' Nascondo textbox per il nome
NewMatName_Visibility = Visibility.Collapsed
m_NewMatName = String.Empty
NotifyPropertyChanged("NewMatName")
End Sub
#End Region ' OkCommand
#Region "CancelCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property CamcelCommand As ICommand
Get
If m_cmdCanel Is Nothing Then
m_cmdCanel = New Command(AddressOf CancelMat)
End If
Return m_cmdCanel
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub CancelMat(ByVal param As Object)
' Nascondo textbox per il nome
NewMatName_Visibility = Visibility.Collapsed
m_NewMatName = String.Empty
NotifyPropertyChanged("NewMatName")
End Sub
#End Region ' CancelCommand
#Region "RemoveMatCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property RemoveMatCommand As ICommand
Get
If m_cmdRemoveMat Is Nothing Then
m_cmdRemoveMat = New Command(AddressOf RemoveMat)
End If
Return m_cmdRemoveMat
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub RemoveMat(ByVal param As Object)
If Not IsNothing(SelMaterial) Then
If MessageBox.Show(EgtMsg(MSG_ALARMSPAGEUC + 42), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
MaterialList.Remove(SelMaterial)
End If
End If
End Sub
#End Region ' RemoveMatCommand
#Region "Browse"
#End Region ' Browse
Public ReadOnly Property BrowseCommand As ICommand
Get
If m_cmdBrowse Is Nothing Then
m_cmdBrowse = New Command(AddressOf BrowseFile)
End If
Return m_cmdBrowse
End Get
End Property
Public Sub BrowseFile(ByVal Param As Object)
' recupero il nome del direttorio
Dim CurrDirectory As String = Path.GetDirectoryName(Map.refMainWindowVM.MainWindowM.sTemplateFilePrinter)
' Apro la finestra di dialogo aperta direttamente sulla cartella cercata
Dim OpenFileDialog As New Microsoft.Win32.OpenFileDialog() With {
.InitialDirectory = CurrDirectory
}
OpenFileDialog.Filter = "prn files (*.prn)|*.prn"
If OpenFileDialog.ShowDialog() <> True Then
' se la risposta è diversa da OK esce
Else
' carico l'indirizzo del template che voglio aprire
Map.refMainWindowVM.MainWindowM.sTemplateFilePrinter = OpenFileDialog.FileName
NotifyPropertyChanged("LabelFileName")
End If
End Sub
#End Region ' COMMANDS
End Class