Imports EgtBEAMWALL.Core
Imports EgtBEAMWALL.Core.ConstBeam
Imports EgtUILib
Imports EgtWPFLib5

Public Class PartInRawPartManagerVM
   Inherits VMBase

#Region "FIELDS & PROPERTIES"

   Public ReadOnly Property MovePart_Visibility As Visibility
      Get
         If Not IsNothing(Map.refProjectVM) AndAlso Not IsNothing(Map.refProjectVM.BTLStructureVM) Then
            Return If(Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM, Visibility.Visible, Visibility.Collapsed)
         End If
         Return Visibility.Visible
      End Get
   End Property

   Private m_PartInRawPartManager_IsEnabled As Boolean = True
   Public ReadOnly Property PartInRawPartManager_IsEnabled As Boolean
      Get
         Return m_PartInRawPartManager_IsEnabled
      End Get
   End Property
   Friend Sub SetPartInRawPartManagerIsEnabled(bIsEnabled As Boolean)
      m_PartInRawPartManager_IsEnabled = bIsEnabled
      NotifyPropertyChanged(NameOf(PartInRawPartManager_IsEnabled))
   End Sub

   ' Definizione comandi
   Private m_cmdRemovePart As ICommand
   Private m_cmdMoveUpPart As ICommand
   Private m_cmdMoveDownPart As ICommand
   Private m_cmdReOrderPart As ICommand

#End Region    ' Fields & Properties

#Region "CONSTRUCTORS"

   Sub New()
      Map.SetRefPartInRawPartManagerVM(Me)
   End Sub

#End Region    ' Constructor

#Region "Messages"

   Public ReadOnly Property ReOrderPart_ToolTip As String
      Get
         Return EgtMsg(61916)
      End Get
   End Property

   Public ReadOnly Property MoveUpPart_ToolTip As String
      Get
         Return EgtMsg(61917)
      End Get
   End Property

   Public ReadOnly Property MoveDownPart_ToolTip As String
      Get
         Return EgtMsg(61918)
      End Get
   End Property

   Public ReadOnly Property RemovePart_ToolTip As String
      Get
         Return EgtMsg(61919)
      End Get
   End Property

#End Region    ' Messages

#Region "COMMANDS"

#Region "RemovePart"

   ''' <summary>
   ''' Returns a command that do Exec.
   ''' </summary>
   Public ReadOnly Property RemovePart_Command As ICommand
      Get
         If m_cmdRemovePart Is Nothing Then
            m_cmdRemovePart = New Command(AddressOf RemovePart)
         End If
         Return m_cmdRemovePart
      End Get
   End Property

   ''' <summary>
   ''' Execute the Exec.  This method is invoked by the ExecCommand.
   ''' </summary>
   Public Sub RemovePart()
      If IsNothing(ProjectManagerVM.CurrProd) Then Return
      Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
      If IsNothing(SelMachGroup) Then Return
      ' se barra gia' assegnata a supervisore, esco
      If SelMachGroup.nProduction_State >= ItemState.Assigned Then Return
      Dim SelPart As PartVM = SelMachGroup.SelPart
      If IsNothing(SelPart) Then Return
      SelPart.DeletePart()
      SelMachGroup.UpdateUsage()
      SelMachGroup.ResetCalcMachGroup()
   End Sub

#End Region    ' RemovePart

#Region "MoveUpPart"

   ''' <summary>
   ''' Returns a command that do Exec.
   ''' </summary>
   Public ReadOnly Property MoveUpPart_Command As ICommand
      Get
         If m_cmdMoveUpPart Is Nothing Then
            m_cmdMoveUpPart = New Command(AddressOf MoveUpPart)
         End If
         Return m_cmdMoveUpPart
      End Get
   End Property

   ''' <summary>
   ''' Execute the Exec.  This method is invoked by the ExecCommand.
   ''' </summary>
   Public Sub MoveUpPart()
      If IsNothing(ProjectManagerVM.CurrProd) Then Return
      Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
      If IsNothing(SelMachGroup) Then Return
      ' se barra gia' assegnata a supervisore, esco
      If SelMachGroup.nProduction_State >= ItemState.Assigned Then Return
      Dim SelPart As PartVM = SelMachGroup.SelPart
      If IsNothing(SelPart) Then Return
      If SelMachGroup.nType = MachineType.BEAM Then
         SelMachGroup.MoveBeam(SelPart, MoveDirections.UP)
         EgtDraw()
         ' riseleziono trave
         SelMachGroup.SelPart = SelPart
      End If
      SelMachGroup.ResetCalcMachGroup()
   End Sub

#End Region    ' MoveUpPart

#Region "MoveDownPart"

   ''' <summary>
   ''' Returns a command that do Exec.
   ''' </summary>
   Public ReadOnly Property MoveDownPart_Command As ICommand
      Get
         If m_cmdMoveDownPart Is Nothing Then
            m_cmdMoveDownPart = New Command(AddressOf MoveDownPart)
         End If
         Return m_cmdMoveDownPart
      End Get
   End Property

   ''' <summary>
   ''' Execute the Exec.  This method is invoked by the ExecCommand.
   ''' </summary>
   Public Sub MoveDownPart()
      If IsNothing(ProjectManagerVM.CurrProd) Then Return
      Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
      If IsNothing(SelMachGroup) Then Return
      ' se barra gia' assegnata a supervisore, esco
      If SelMachGroup.nProduction_State >= ItemState.Assigned Then Return
      Dim SelPart As PartVM = SelMachGroup.SelPart
      If IsNothing(SelPart) Then Return
      If SelMachGroup.nType = MachineType.BEAM Then
         SelMachGroup.MoveBeam(SelPart, MoveDirections.DOWN)
         EgtDraw()
         ' riseleziono trave
         SelMachGroup.SelPart = SelPart
      End If
      SelMachGroup.ResetCalcMachGroup()
   End Sub

#End Region    ' MoveDownPart

#Region "ReOrderPart"

   ''' <summary>
   ''' Returns a command that do Exec.
   ''' </summary>
   Public ReadOnly Property ReOrderPart_Command As ICommand
      Get
         If m_cmdReOrderPart Is Nothing Then
            m_cmdReOrderPart = New Command(AddressOf ReOrderPart)
         End If
         Return m_cmdReOrderPart
      End Get
   End Property

   ''' <summary>
   ''' Execute the Exec.  This method is invoked by the ExecCommand.
   ''' </summary>
   Public Sub ReOrderPart()
      If IsNothing(ProjectManagerVM.CurrProd) Then Return
      Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
      If IsNothing(SelMachGroup) Then Return
      ' se barra gia' assegnata a supervisore, esco
      If SelMachGroup.nProduction_State >= ItemState.Assigned Then Return
      Dim SelPart As PartVM = SelMachGroup.SelPart
      If IsNothing(SelPart) Then Return
      If SelMachGroup.nType = MachineType.BEAM Then
         SelMachGroup.ReorderBeam()
         EgtDraw()
         ' riseleziono trave
         If Not IsNothing(SelPart) Then
            SelMachGroup.SelPart = SelPart
         End If
      End If
      SelMachGroup.ResetCalcMachGroup()
   End Sub

#End Region    ' ReOrderPart

#End Region    ' Commands

End Class
