Imports IntraSell_DLL
Imports IntraSell_Net_Base
Public Class PreisKalkulator
    Inherits AbstractForm

    Private Sub Form_Verlassen() Handles MyBase.Verlassen
        Me.Close()
    End Sub

    Private Sub PreisKalkulator_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            FillComboBox(PreislisteComboBox, SQL_PREISLISTEN, "PreislisteName")
            FillComboBox(LandComboBox, "SELECT ISO2, Name FROM grLand ORDER By Name", "Name", "ISO2")
            Me.GrartikelPreiskalkulatorTableAdapter.Fill(Me.DsPreise.grartikelPreiskalkulator)

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

    Sub BerechnePreise()
        Try
            Me.Cursor = Cursors.WaitCursor
            For Each r As dsPreise.grartikelPreiskalkulatorRow In Me.DsPreise.grartikelPreiskalkulator.Rows
                Try
                    Dim vkPreisNetto = intrasell.preise.GetPreis(IdNr:=Me.AdressenControl1.IDNR, ArtNr:=r.ArtNr, Stk:=1, Preisliste:=Me.PreislisteComboBox.Text, LieferLandISO2:=Me.LandComboBox.SelectedValue)
                    Dim preis = intrasell.preise.CalculateBruttoPreisMitMwSt(vkPreisNetto, ArtNr:=r.ArtNr, IdNr:=Me.AdressenControl1.IDNR, LieferLandISO2:=Me.LandComboBox.SelectedValue)
                    r.PreisNetto_Berechnet = preis.NettoPreis
                    r.PreisBrutto_Berechnet = preis.BruttoPreis
                    r.MWST_Berechnet = preis.MwstSatz
                Catch ex As Exception
                    HandleAppError(ex, Silent:=True)
                End Try
            Next
        Catch ex As Exception
            HandleAppError(ex, Silent:=True)
        Finally
            Me.Cursor = Cursors.Default
        End Try

    End Sub

    Private Sub ButtonBerechne_Click(sender As Object, e As EventArgs) Handles ButtonBerechne.Click
        Try
            BerechnePreise()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub DataGridView1_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError

    End Sub
End Class