Imports EgtUILib

Public Class CompoTrfData

   ' Riferimento alla MainWindow
   Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)

   Sub New(Owner As Window)
      Me.Owner = Owner
      InitializeComponent()
   End Sub

   Private Sub CompoTrfData_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
      Me.Top = Owner.Top + Owner.Height / 2 - Me.Height / 2
      Me.Left = Owner.Left + Owner.Width / 2 - Me.Width / 2
      OrdCodeTxBl.Text = EgtMsg(90390)    ' Order Code
      OrdDescTxBl.Text = EgtMsg(90391)    ' Order Description
      PartCodeTxBl.Text = EgtMsg(90396)   ' Part Code
      MatCodeTxBl.Text = EgtMsg(90392)    ' Material Code
      SurfCodeTxBl.Text = EgtMsg(90393)   ' Surface Code
      ThicknessTxBl.Text = EgtMsg(90394)  ' Thickness
   End Sub

   Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
      DialogResult = True
      SaveData()
      Close()
   End Sub

   Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExitBtn.Click
      DialogResult = False
      Close()
   End Sub

   Private Sub SaveData()
      WritePrivateProfileString(S_TRF, K_ORDCODE, OrdCodeTxBx.Text, m_MainWindow.GetIniFile())
      WritePrivateProfileString(S_TRF, K_ORDDESC, OrdDescTxBx.Text, m_MainWindow.GetIniFile())
      WritePrivateProfileString(S_TRF, K_PARTCODE, PartCodeTxBx.Text, m_MainWindow.GetIniFile())
      WritePrivateProfileString(S_TRF, K_MATCODE, MatCodeTxBx.Text, m_MainWindow.GetIniFile())
      WritePrivateProfileString(S_TRF, K_SURFCODE, SurfCodeTxBx.Text, m_MainWindow.GetIniFile())
      ' prima di salvare lo spessore converto in mm e poi di nuovo in stringa
      Dim dVal As Double = 0
      StringToLen(ThicknessTxBx.Text, dVal)
      WritePrivateProfileString(S_TRF, K_TRFTHICKNESS, DoubleToString(dVal, 4), m_MainWindow.GetIniFile())
   End Sub

   Friend Sub SetData(sOrdCode As String, sOrdDesc As String, sPartCode As String, sMatCode As String, sSurfCode As String, dTh As Double)
      ' se verifico che non sono stati iniziliazzti i campi allora provvedo a leggere il file ini del programma
      If sOrdCode = "" And sOrdDesc = "" And sPartCode = "" And sMatCode = "" And sSurfCode = "" Then
         GetPrivateProfileString(S_TRF, K_ORDCODE, sOrdCode, sOrdCode, m_MainWindow.GetIniFile())
         GetPrivateProfileString(S_TRF, K_ORDDESC, sOrdDesc, sOrdDesc, m_MainWindow.GetIniFile())
         GetPrivateProfileString(S_TRF, K_PARTCODE, sPartCode, sPartCode, m_MainWindow.GetIniFile())
         GetPrivateProfileString(S_TRF, K_MATCODE, sMatCode, sMatCode, m_MainWindow.GetIniFile())
         GetPrivateProfileString(S_TRF, K_SURFCODE, sSurfCode, sSurfCode, m_MainWindow.GetIniFile())
         ' recupero il dato dello spessore che deve essere in mm
         dTh = GetPrivateProfileDouble(S_TRF, K_TRFTHICKNESS, dTh, m_MainWindow.GetIniFile())
      End If
      ' inizializzo i campi della finestra
      OrdCodeTxBx.Text = sOrdCode
      OrdDescTxBx.Text = sOrdDesc
      PartCodeTxBx.Text = sPartCode
      MatCodeTxBx.Text = sMatCode
      SurfCodeTxBx.Text = sSurfCode
      ThicknessTxBx.Text = LenToString(dTh, 2)
   End Sub

   Friend Sub GetData(ByRef sOrdCode As String, ByRef sOrdDesc As String, ByRef sPartCode As String, ByRef sMatCode As String, ByRef sSurfCode As String, ByRef dTh As Double)
      sOrdCode = OrdCodeTxBx.Text
      sOrdDesc = OrdDescTxBx.Text
      sPartCode = PartCodeTxBx.Text
      sMatCode = MatCodeTxBx.Text
      sSurfCode = SurfCodeTxBx.Text
      StringToLen(ThicknessTxBx.Text, dTh)
   End Sub

End Class