Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports EgtUILib
Imports EgtWPFLib
Imports EgtWPFLib5

Public Class WaterJetPageUC

   ' Riferimento alla MainWindow
   Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
   Private m_refWaterjetDbWindowVM As EgtWPFLib5.WaterjetDbWindowVM
   Private m_sOrigNewMaterial As String = String.Empty
   Private m_sOrigNewSubMaterial As String = String.Empty

   Private Sub WaterJetPage_Initialized(sender As Object, e As EventArgs)
      m_refWaterjetDbWindowVM = New EgtWPFLib5.WaterjetDbWindowVM(m_MainWindow.m_CurrentMachine.sMachDir)
      Me.DataContext = m_refWaterjetDbWindowVM
      EgtWPFLib.Utility.MainWindow = m_MainWindow
   End Sub

   Public Sub WaterJetPage_Reinitialize()
      m_refWaterjetDbWindowVM = New EgtWPFLib5.WaterjetDbWindowVM(m_MainWindow.m_CurrentMachine.sMachDir)
      Me.DataContext = m_refWaterjetDbWindowVM
   End Sub

   Private Sub NewMaterial_EgtOpening(sender As Object, e As EventArgs) Handles NewMaterialNameTxBx.EgtOpening
      m_sOrigNewMaterial = NewMaterialNameTxBx.Text
   End Sub

   Private Sub NewSubMaterial_EgtOpening(sender As Object, e As EventArgs) Handles NewSubMaterialNameTxBx.EgtOpening
      m_sOrigNewSubMaterial = NewSubMaterialNameTxBx.Text
   End Sub

   Private Sub NewMaterial_EgtClosed(sender As Object, e As EventArgs) Handles NewMaterialNameTxBx.EgtClosed
      m_refWaterjetDbWindowVM.sNewMaterial = NewMaterialNameTxBx.Text
      If String.IsNullOrEmpty(m_refWaterjetDbWindowVM.sNewMaterial) OrElse m_refWaterjetDbWindowVM.sNewMaterial = m_sOrigNewMaterial Then
         m_refWaterjetDbWindowVM.NewMaterial_Visibility = Visibility.Collapsed
      Else
         m_refWaterjetDbWindowVM.Done("")
         NewMaterialNameTxBx.Clear()
      End If
   End Sub

   Private Sub NewSubMaterial_EgtClosed(sender As Object, e As EventArgs) Handles NewSubMaterialNameTxBx.EgtClosed
      m_refWaterjetDbWindowVM.sNewSubMaterial = NewSubMaterialNameTxBx.Text
      If String.IsNullOrEmpty(m_refWaterjetDbWindowVM.sNewSubMaterial) OrElse m_refWaterjetDbWindowVM.sNewSubMaterial = m_sOrigNewSubMaterial Then
         m_refWaterjetDbWindowVM.NewSubMaterial_Visibility = Visibility.Collapsed
      Else
         m_refWaterjetDbWindowVM.Done("")
         NewSubMaterialNameTxBx.Clear()
      End If
   End Sub

End Class

