Imports System.Collections.ObjectModel
Imports EgtUILib
Imports EgtWPFLib5
Imports EgtBEAMWALL.Core

Public Class ChangeMaterialWndVM
   Inherits VMBase

#Region "FIELDS & PROPERTIES"

   Friend Event m_CloseWindow(bDialogResult As Boolean)

   Private m_ProjMaterialList As New ObservableCollection(Of String)
   Public Property ProjMaterialList As ObservableCollection(Of String)
      Get
         Return m_ProjMaterialList
      End Get
      Set(value As ObservableCollection(Of String))
         m_ProjMaterialList = value
      End Set
   End Property

   Private m_SelProjMaterial As String
   Public Property SelProjMaterial As String
      Get
         Return m_SelProjMaterial
      End Get
      Set(value As String)
         m_SelProjMaterial = value
         NotifyPropertyChanged(NameOf(SelProjMaterial))
      End Set
   End Property

   Private m_WhMaterialList As New ObservableCollection(Of String)
   Public Property WhMaterialList As ObservableCollection(Of String)
      Get
         Return m_WhMaterialList
      End Get
      Set(value As ObservableCollection(Of String))
         m_WhMaterialList = value
      End Set
   End Property

   Private m_SelWhMaterial As String
   Public Property SelWhMaterial As String
      Get
         Return m_SelWhMaterial
      End Get
      Set(value As String)
         m_SelWhMaterial = value
         NotifyPropertyChanged(NameOf(SelWhMaterial))
      End Set
   End Property

   ' Definizione comandi
   Private m_cmdOk As ICommand

#End Region    ' FIELDS & PROPERTIES

#Region "MESSAGES"

   Public ReadOnly Property ProjMaterial_Msg As String
      Get
         Return EgtMsg(61962)
      End Get
   End Property

   Public ReadOnly Property WjMaterial_Msg As String
      Get
         Return EgtMsg(61963)
      End Get
   End Property

   Public ReadOnly Property Ok_Msg As String
      Get
         Return EgtMsg(61761)
      End Get
   End Property

   Public ReadOnly Property Cancel_Msg As String
      Get
         Return EgtMsg(61763)
      End Get
   End Property

#End Region    ' MESSAGES

#Region "CONSTRUCTOR"

   Sub New()
      ' recupero i materiali del progetto
      m_ProjMaterialList.Clear()
      For Each BTLPart In Map.refProjectVM.BTLStructureVM.BTLPartVMList
         If Not m_ProjMaterialList.Contains(BTLPart.sMATERIAL) Then
            m_ProjMaterialList.Add(BTLPart.sMATERIAL)
         End If
      Next
      ' recupero la lista dei SectionXMaterial presenti in Warehouse
      Dim WhSectXMatList As List(Of SectionXMaterial) = WarehouseWndVM.GetSectionXMaterialsFromWarehouse()
      ' ricavo la lista dei materiali presenti in Warehouse
      m_WhMaterialList.Clear()
      For Each WhSectXMat In WhSectXMatList
         For Each sMatItem In WhSectXMat.sMaterial
            If Not m_WhMaterialList.Contains(sMatItem) Then
               m_WhMaterialList.Add(sMatItem)
            End If
         Next
      Next
   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_SelProjMaterial) AndAlso m_SelProjMaterial <> "" AndAlso
         Not IsNothing(m_SelWhMaterial) AndAlso m_SelWhMaterial <> "" Then
         RaiseEvent m_CloseWindow(True)
      Else
         MessageBox.Show(EgtMsg(61858), EgtMsg(30007))
      End If
   End Sub

#End Region ' Ok

#End Region    ' COMMANDS

End Class
