Imports IntraSell_DLL

Public Class KundenPreise

    Property KundNr As Integer
    Property ArtNr As Integer

    Private Sub KundenPreise_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim eAC = New EANAutoComplete(DataGridViewPreise,
                              EANColIndex:=2,
                              ArtNrColIndex:=0,
                              BezeichnungColIndex:=3,
                              SpezifikationColIndex:=-1)
        eAC.MakeEANColumnAutocomplete()
    End Sub

    Public Sub Lade()
        Try
            FillComboBoxInDG(ArtNrColumn, ArtikelControl.SQL, "Art", "ArtNr")
            Grartikel_vkpreisperselectionTableAdapter.FillByIdNr(DsPreise._grartikel_vkpreisperselection, KundNr)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Public Sub Lade(ArtNr As Integer)
        Try
            WriteLog("Lade ArtNr " & ArtNr)
            FillComboBoxInDG(ArtNrColumn, ArtikelControl.SQL, "Art", "ArtNr")
            Grartikel_vkpreisperselectionTableAdapter.FillByIdnrAndArtNr(DsPreise._grartikel_vkpreisperselection, KundNr, ArtNr)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Public Sub Save()
        Try
            Try
                Dim current As dsPreise._grartikel_vkpreisperselectionRow = GrartikelvkpreisperselectionBindingSource.Current.Row
                Dim artnr = current.ArtNr
            Catch ex As Exception
                'cancel not finished row
                GrartikelvkpreisperselectionBindingSource.CancelEdit()
            End Try

            Validate()
            GrartikelvkpreisperselectionBindingSource.EndEdit()
            Grartikel_vkpreisperselectionTableAdapter.Update(DsPreise)
            If ArtNr > 0 Then
                Lade(ArtNr)
            Else
                Lade()
            End If
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub GrartikelvkpreisperselectionBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles GrartikelvkpreisperselectionBindingSource.AddingNew
        Try

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

    Private Sub DataGridViewPreise_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles DataGridViewPreise.RowsAdded

    End Sub

    Private Sub DataGridViewPreise_UserAddedRow(sender As Object, e As DataGridViewRowEventArgs) Handles DataGridViewPreise.UserAddedRow


    End Sub

    Private Sub DataGridViewPreise_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridViewPreise.CellValueChanged
        Try
            If GrartikelvkpreisperselectionBindingSource.Current Is Nothing Then
                Exit Sub
            End If
            Dim row As dsPreise._grartikel_vkpreisperselectionRow = GrartikelvkpreisperselectionBindingSource.Current.row
            If row IsNot Nothing Then
                row.IDNR = KundNr
            End If

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

    Private Sub DataGridViewPreise_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridViewPreise.DataError
        'DO NOT REMOVE
    End Sub
End Class
