Public Class WaterJetPageUC

   ' Riferimento alla MainWindow
   Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
   Private m_refWaterjetDbWindowVM As WaterjetDbWindowVM_OmagCUT
   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 WaterjetDbWindowVM_OmagCUT(m_MainWindow.m_CurrentMachine.sMachDir)
      '----------------------------------------------------------------------------------------
      ' TEMPORANEO - se dati in INCH e richiesta di frazioni eseguo la conversione in frazione!
      ConvertParamListValueToFracrion()
      '----------------------------------------------------------------------------------------
      Me.DataContext = m_refWaterjetDbWindowVM
      EgtWPFLib.Utility.MainWindow = m_MainWindow
   End Sub

   Public Sub WaterJetPage_Reinitialize()
      m_refWaterjetDbWindowVM = New WaterjetDbWindowVM_OmagCUT(m_MainWindow.m_CurrentMachine.sMachDir)
      '----------------------------------------------------------------------------------------
      ' TEMPORANEO - se dati in INCH e richiesta di frazioni eseguo la conversione in frazione!
      ConvertParamListValueToFracrion()
      '----------------------------------------------------------------------------------------
      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

   Private Sub ConvertParamListValueToFracrion()
      ' TEMPORANEO - se dati in INCH e richiesta di frazioni eseguo la conversione in frazione!
      Dim Index1 As Integer = 0
      For Index1 = 0 To m_refWaterjetDbWindowVM.MaterialList.Count - 1
         Dim Index2 As Integer = 0
         For Index2 = 0 To m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList.Count - 1
            Dim Index3 As Integer = 0
            For Index3 = 0 To m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList.Count - 1
               Dim dThickness As Double
               Dim dQ1 As Double
               Dim dQ2 As Double
               Dim dQ3 As Double
               Dim dQ4 As Double
               Dim dQ5 As Double
               Dim dQExtra As Double
               Dim dAngComp As Double
               StringToLen(m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).Thickness, dThickness)
               Dim sVal As String = LenToString(dThickness, 3)
               m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).SetThickness(sVal)
               StringToLen(m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).Q1, dQ1)
               sVal = LenToString(dQ1, 3)
               m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).SetQ1(sVal)
               StringToLen(m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).Q2, dQ2)
               sVal = LenToString(dQ2, 3)
               m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).SetQ2(sVal)
               StringToLen(m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).Q3, dQ3)
               sVal = LenToString(dQ3, 3)
               m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).SetQ3(sVal)
               StringToLen(m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).Q4, dQ4)
               sVal = LenToString(dQ4, 3)
               m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).SetQ4(sVal)
               StringToLen(m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).Q5, dQ5)
               sVal = LenToString(dQ5, 3)
               m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).SetQ5(sVal)
               StringToLen(m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).QExtra, dQExtra)
               sVal = LenToString(dQExtra, 3)
               m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).SetQExtra(sVal)
               StringToDouble(m_refWaterjetDbWindowVM.MaterialList(Index1).SubMaterialList(Index2).ParamList(Index3).dAngComp, dAngComp)
            Next
         Next
      Next
   End Sub

End Class

