Imports IntraSell_DLL

Public Class ArtikelNettoBruttoHandler

    Dim PREIS_GENAUIGKEIT As Integer = 4


    Dim PreisATSTextBox As TextBox
    Dim PreisATS_BruttoTextBox As TextBox
    Dim MWSTTextBox As TextBox

    Public Sub HaendlerInitialisieren(PreisATSTextBox As TextBox, PreisATS_BruttoTextBox As TextBox, MWSTTextBox As TextBox)
        Me.PreisATSTextBox = PreisATSTextBox
        Me.PreisATS_BruttoTextBox = PreisATS_BruttoTextBox
        Me.MWSTTextBox = MWSTTextBox

        PREIS_GENAUIGKEIT = 4
        AddHandler PreisATSTextBox.Validated, AddressOf PreisATSTextBox_TextChanged
        AddHandler PreisATS_BruttoTextBox.Validated, AddressOf PreisATS_BruttoTextBox_TextChanged
        AddHandler MWSTTextBox.Validated, AddressOf MWSTTextBox_Validated
    End Sub


    Private Sub PreisATSTextBox_TextChanged(sender As Object, e As System.EventArgs) 'Handles PreisATSTextBox.TextChanged
        Try
            If IsNumeric(MWSTTextBox.Text) And IsNumeric(PreisATSTextBox.Text) Then
                PreisATS_BruttoTextBox.Text = FormatCurrency(PreisATSTextBox.Text * (100 + CInt(MWSTTextBox.Text)) / 100, 2)
            End If

        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub PreisATS_BruttoTextBox_TextChanged(sender As Object, e As EventArgs) 'Handles PreisATS_BruttoTextBox.Validated
        Try
            If IsNumeric(MWSTTextBox.Text) And IsNumeric(PreisATS_BruttoTextBox.Text) Then
                PreisATSTextBox.Text = FormatCurrency(PreisATS_BruttoTextBox.Text / ((100 + CInt(MWSTTextBox.Text)) / 100), PREIS_GENAUIGKEIT)
            End If

        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub


    Private Sub MWSTTextBox_Validated(sender As Object, e As EventArgs) ' Handles MWSTTextBox.Validated
        Try
            If IsNumeric(PreisATS_BruttoTextBox.Text) Then
                PreisATS_BruttoTextBox_TextChanged(sender, e)
            ElseIf IsNumeric(PreisATSTextBox.Text) Then
                PreisATSTextBox_TextChanged(sender, e)
            End If
            SetVarValue(ARTIKEL_ANLAGE_MWST, MWSTTextBox.Text)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub



End Class
