Imports EgtWPFLib5
Imports EgtUILib

Public Class AddPartWndVM
   Inherits VMBase

#Region "FIELDS & PROPERTIES"

   Friend Event m_CloseWindow(bDialogResult As Boolean)

   Private m_nPDN As Integer
   Public Property nPDN As Integer
      Get
         Return m_nPDN
      End Get
      Set(value As Integer)
         m_nPDN = value
      End Set
   End Property

   Private m_sNAM As String
   Public Property sNAM As String
      Get
         Return m_sNAM
      End Get
      Set(value As String)
         m_sNAM = value
      End Set
   End Property

   Private m_dL As Double
   Public ReadOnly Property dL As Double
      Get
         Return m_dL
      End Get
   End Property
   Public Property sL As String
      Get
         Return LenToString(m_dL, 3)
      End Get
      Set(value As String)
         Dim dTempL As Double
         If StringToLenAdv(value, dTempL, True) AndAlso dTempL > 0 Then
            m_dL = dTempL
         Else
            NotifyPropertyChanged("sL")
         End If
      End Set
   End Property

   Private m_dW As Double
   Public ReadOnly Property dW As Double
      Get
         Return m_dW
      End Get
   End Property
   Public Property sW As String
      Get
         Return LenToString(m_dW, 3)
      End Get
      Set(value As String)
         Dim dTempW As Double
         If StringToLenAdv(value, dTempW, True) AndAlso dTempW > 0 Then
            EgtDraw()
            m_dW = dTempW
         Else
            NotifyPropertyChanged("sW")
         End If
      End Set
   End Property

   Private m_dH As Double
   Public ReadOnly Property dH As Double
      Get
         Return m_dH
      End Get
   End Property
   Public Property sH As String
      Get
         Return LenToString(m_dH, 3)
      End Get
      Set(value As String)
         Dim dTempH As Double
         If StringToLenAdv(value, dTempH, True) AndAlso dTempH > 0 Then
            EgtDraw()
            m_dH = dTempH
         Else
            NotifyPropertyChanged("sH")
         End If
      End Set
   End Property

   Private m_sMAT As String
   Public Property sMAT As String
      Get
         Return m_sMAT
      End Get
      Set(value As String)
         m_sMAT = value
      End Set
   End Property

   Private m_nCNT As Integer
   Public ReadOnly Property nCNT As Integer
      Get
         Return m_nCNT
      End Get
   End Property
   Public Property sCNT As String
      Get
         Return m_nCNT
      End Get
      Set(value As String)
         Dim nTempCNT As Integer
         If Integer.TryParse(value, nTempCNT) AndAlso nTempCNT > 0 Then
            m_nCNT = nTempCNT
         Else
            NotifyPropertyChanged("sCNT")
         End If
      End Set
   End Property

   ' Definizione comandi
   Private m_cmdOk As ICommand

#End Region    ' FIELDS & PROPERTIES

#Region "CONSTRUCTOR"

   Sub New()
      If Not IsNothing(Map.refProjectVM.BTLStructureVM.BTLPartVMList) Then
         If Not IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLPart) Then
            m_dW = Map.refProjectVM.BTLStructureVM.SelBTLPart.dW
            m_dH = Map.refProjectVM.BTLStructureVM.SelBTLPart.dH
            m_dL = Map.refProjectVM.BTLStructureVM.SelBTLPart.dL
         ElseIf Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count > 0 Then
            m_dW = Map.refProjectVM.BTLStructureVM.BTLPartVMList(0).dW
            m_dH = Map.refProjectVM.BTLStructureVM.BTLPartVMList(0).dH
            m_dL = Map.refProjectVM.BTLStructureVM.BTLPartVMList(0).dL
         End If
         m_nPDN = Map.refProjectVM.BTLStructureVM.BTLStructureM.NewPDN()
      End If
      m_nCNT = 1
   End Sub

#End Region    ' CONSTRUCTOR

#Region "COMMANDS"

#Region "Ok"

   Public ReadOnly Property Ok_Command As ICommand
      Get
         If m_cmdOk Is Nothing Then
            m_cmdOk = New Command(AddressOf Ok)
         End If
         Return m_cmdOk
      End Get
   End Property

   Public Sub Ok()
      'verifico che tutti i campi contengano un valore valido
      If Not IsNothing(m_dL) AndAlso m_dL > 0 AndAlso
         Not IsNothing(m_dW) AndAlso m_dW >= 0 AndAlso
         Not IsNothing(m_dH) AndAlso m_dH >= 0 Then
         RaiseEvent m_CloseWindow(True)
      Else
         MessageBox.Show(EgtMsg(61853), EgtMsg(30007))
      End If
   End Sub

#End Region ' Ok

#End Region    ' COMMANDS

End Class
