Files
OmagPHOTO/OptionWindow/OptionWindowVM.vb
T
Emmanuele Sassi e60bef9257 OmagPHOTO :
- Aggiunto AboutBox.
- Migliorie varie.
2017-12-01 18:39:12 +00:00

304 lines
9.6 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtUILib
Imports EgtWPFLib5
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 = ProjectVM.ProjectModeOpt.DETAIL Then
' aggiorno spessore in OptionPanel
Map.refOptionPanelVM.SelSlab.NotifyPropertyChanged("Thickness")
ElseIf Map.refProjectVM.SelProjectMode = ProjectVM.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
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
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)
End If
End If
' Nascondo textbox per il nome
NewMatName_Visibility = Visibility.Collapsed
m_NewMatName = String.Empty
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
#End Region ' Messages
' Definizione comandi
Private m_cmdNewMat As ICommand
Private m_cmdRemoveMat 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
#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 "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
#End Region ' COMMANDS
End Class