Imports IntraSell_DLL
Imports IntraSell_Net_Base

Public Class VorgangBar
    Inherits AbstractVorgangBar
    Implements InterfacePrintable


    ''' <summary>
    ''' Die Datensätze filtern
    ''' </summary>
    ''' <param name="Expression"></param>
    ''' <remarks></remarks>
    Public Sub FilterBy(Expression As String)
        Try
            BuchvorgangBindingSource.Filter = Expression
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    ''' <summary>
    ''' post message am screen
    ''' </summary>
    ''' <param name="Msg"></param>
    ''' <remarks></remarks>
    Private Sub PostMsg(Msg As String, Style As MsgBoxStyle)
        LabelMessage.Text = Msg & " " & LabelMessage.Text
        If Style = MsgBoxStyle.Information Then
            LabelMessage.ForeColor = Color.Green
        Else
            LabelMessage.ForeColor = Color.Red
        End If
    End Sub


    ''' <summary>
    ''' Save edits
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub BuchvorgangBindingNavigatorSaveItem_Click(sender As Object, e As System.EventArgs) Handles MyBase.Save
        Call SaveEdits()
    End Sub

    Public Sub ArtNr_Changed(newArtNr As Object) Handles ArtikelControl1.ArtNrChanged
        Try
            ArtNr_Changed_Base(newArtNr)
            StkTextBox.Focus()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Sub VorgangGeladenHandler()
        Dim vorgang As dsVorgaenge.buchvorgangRow = GetVorgang() '  Me.DsVorgaenge.buchvorgang.Rows(0)
        If vorgang Is Nothing Then
            Exit Sub
        End If
        KundNrAdressenControl.IDNR = KundNr
        MitarbeiterNrComboBox.IDNR = MitarbeiterID
        NummerTextBox.Text = vorgang.Nummer
        TypComboBox.SelectedValue = vorgang.Typ
        AbgeschlossenCheckBox.Checked = vorgang.Abgeschlossen
        AusgedrucktCheckBox.Checked = vorgang.Ausgedruckt
        BezahltCheckBox.Checked = vorgang.Bezahlt
        Dim v = intrasell.vorgang.GetVorgangEigenschaft(vorgang.Typ, vorgang.Nummer, BARGELD_GEGEBEN)
        GegebenBarTextbox.Text = Replace(v, "€", "")
        RestgeldTextbox.Text = "" 'clear last input
    End Sub

    ''' <summary>
    ''' Alte Rechnungen mit dem selben Datum laden
    ''' </summary>
    ''' <remarks></remarks>
    Sub AlteBarRechnungenLaden()
        BuchvorgangTableAdapter.FillByKundNrDatum(DsVorgaenge.buchvorgang, KundNr, Date.Today)
        Buchvorgang_artikelTableAdapter.FillByKundNrDatum(DsVorgaenge._buchvorgang_artikel, KundNr, Date.Today)
    End Sub


    ''' <summary>
    ''' Form Load
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Sub VorgangBar_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
        Laden()
    End Sub

    Public Sub Laden()
        Try
            LadenBase()

            AddHandler VorgangGeladen, AddressOf VorgangGeladenHandler
            AddHandler SetButtonsEvent, AddressOf SetButtons
            AddHandler PostMsgEvent, AddressOf PostMsg
            DsArtikel.EnforceConstraints = False
            GrArtikellisteTableAdapter.Fill(DsArtikel.grArtikelliste)

            'FillComboBox(Me.StatusComboBox, "select Status from buchVorgaengeStatus Group by Status", "Status")
            FillComboBox(TypComboBox, "select Typ, Bezeichnung FROM buchVorgangTyp ORDER By Bezeichnung", "Bezeichnung", "Typ")
            FillComboBox(WaehrungComboBox, "select zeichen from grWaehrung Group by zeichen", "zeichen")

            'LadeKundenSpezifischeDaten()
            'CheckAbgeschlossen()
            Loading = False

            SetButtons(True)

            CheckBoxPrintAmBildschirm.Checked = VarValue_Default(PRINT_AM_BILDSCHIRM, False)

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


    Public Sub btnNeu_Click(sender As Object, e As System.EventArgs) Handles btnNeu.Click
        BeginNewVorgang(VorgangTypen.AU, KundNr)
    End Sub

    Private Sub NeuerVorgangToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles NeuerVorgangToolStripMenuItem.Click
        BeginNewVorgang(VorgangTypen.AU, KundNr)
    End Sub

    ''' <summary>
    ''' Vorgang Form schliessen
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Sub btnStorno_Click(sender As Object, e As System.EventArgs) Handles btnStorno.Click
        btnStorno.Enabled = False
        StornoGeladenerVorgang(False)
    End Sub

    ''' <summary>
    ''' Vorgang abschliessen
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Sub btnAbschliessen_Click(sender As Object, e As System.EventArgs) Handles btnAbschliessen.Click
        Dim v = GetVorgang()
        btnAbschliessen.Enabled = False
        Abschliessen()
        btnNeu.Focus()
    End Sub

#Region "Drucken"
    ''' <summary>
    ''' Zweiten ausdruck starten
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnZweiterAusdruck_Click(sender As Object, e As System.EventArgs) Handles btnZweiterAusdruck.Click
        PrintVorgangBarOhneUeberleitung(GetVorgang().Typ, GetVorgang().Nummer)
    End Sub

#End Region

#Region "Menu"

    Private Sub AusdruckenToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles AusdruckenToolStripMenuItem.Click
        PrintVorgangBarOhneUeberleitung(GetVorgang().Typ, GetVorgang().Nummer)
    End Sub

#End Region

#Region "Position Tab"
    Private Sub AddNewButton_Click(sender As Object, e As System.EventArgs) 'Handles AddNewButton.Click
        Try
            If IsNull(KundNr) Or KundNr <= 0 Then Exit Sub
            'Kundenform öffnen um weitere zu definieren
            Dim k As New Kunden
            k.LadeKunde(IDNR:=KundNr)
            k.FilterBy("IDNR=" & KundNr)
            k.ShowDialog()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub


    ''' <summary>
    ''' Neue Position einfügen 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Sub btnNeuePosition_Click(sender As Object, e As System.EventArgs) Handles btnNeuePosition.Click
        Try
            AddNewPos()
            SetButtons(False)
            ArtikelControl1.ArtNr = Nothing
            ArtikelControl1.Focus()
            SetzeStandardArtNR()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Sub SetzeStandardArtNR()
        If ExistsVarValue(BARRECHNUNG_STANDARD_ARTNR) Then
            ArtikelControl1.ArtNr = VarValue(BARRECHNUNG_STANDARD_ARTNR)
            Dim newPositionRow As dsVorgaenge._buchvorgang_artikelRow = Buchvorgang_artikelBindingSource.Current.row
            newPositionRow.ArtNr = VarValue(BARRECHNUNG_STANDARD_ARTNR)
            StkTextBox.Focus()
        End If
    End Sub

    Private Sub btnPositionLoeschen_Click(sender As Object, e As EventArgs) Handles btnPositionLoeschen.Click
        Try
            If (Buchvorgang_artikelBindingSource.Current IsNot Nothing) Then
                Buchvorgang_artikelBindingSource.Remove(Buchvorgang_artikelBindingSource.Current)
                BerechneVorgangSummen(GetVorgang())
                ArtikelControl1.Focus()
            Else
                btnPositionLoeschen.Enabled = False
            End If
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub NeuePositionButton_Click(sender As Object, e As System.EventArgs) 'Handles NeuePositionButton.Click
        Try
            Buchvorgang_artikelBindingSource.AddNew()
            Buchvorgang_artikelBindingSource.Current.row.ID = Buchvorgang_artikelDataGridView.RowCount - 1
            ArtikelControl1.ArtNr = Nothing
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub ArtikelControl1_SerialNrErkannt(SerialNr As Object) Handles ArtikelControl1.SerialNrErkannt
        Try
            Dim pos As dsVorgaenge._buchvorgang_artikelRow = Buchvorgang_artikelBindingSource.Current.row
            pos.ArtikelIdentifikation = SerialNr

            If ExistsVarValue(BARRECHNUNG_BARCODE_SCAN_SOFORT_NEUE_POSITION) Then
                Dim neuePos As Boolean = VarValue(BARRECHNUNG_BARCODE_SCAN_SOFORT_NEUE_POSITION)
                If neuePos Then
                    btnNeuePosition.Focus()
                    btnNeuePosition.PerformClick()
                End If
            End If
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Dim StkChangedFlag = False
    Private Sub StkTextBox_Validating(sender As Object, e As System.EventArgs) Handles StkTextBox.Validating
        If IsNull(Buchvorgang_artikelBindingSource.Current) Then
            Exit Sub
        End If
        Dim pos As dsVorgaenge._buchvorgang_artikelRow = Buchvorgang_artikelBindingSource.Current.row
        If pos IsNot Nothing Then
            If IsNumeric(StkTextBox.Text) Then
                StkChangedFlag = pos.Stk <> StkTextBox.Text
            End If
        End If
    End Sub

    Private Sub StkTextBox_Validated(sender As Object, e As System.EventArgs) Handles StkTextBox.Validated
        If Not StkChangedFlag Then Exit Sub
        StkChanged()
        StkChangedFlag = False
    End Sub

    ''' <summary>
    ''' MWST und Preis_Brutto berechnen
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Shadows Sub Preis_NettoTextBox_Validated(sender As Object, e As System.EventArgs) Handles Preis_NettoTextBox.Validated
        MyBase.Preis_NettoTextBox_Validated()
    End Sub

    ''' <summary>
    ''' Berechne MWST+Netto aus Brutto 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Shadows Sub Preis_BruttoTextBox_Validated(sender As Object, e As EventArgs) Handles Preis_BruttoTextBox.Validated
        MyBase.Preis_BruttoTextBox_Validated()
    End Sub

    Private Sub ArtikelControl1_Validated(newArtNr As String) Handles ArtikelControl1.ArtNrAdded
        Try
            'Reload der Liste mit Artikeln
            DsArtikel.EnforceConstraints = False
            GrArtikellisteTableAdapter.Fill(DsArtikel.grArtikelliste)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub
#End Region


    ''' <summary>
    ''' Buttons aktivieren / deaktivieren je nach Rechnungsstatus
    ''' </summary>
    ''' <param name="neu">Button Neu aktivieren oder nicht</param>
    ''' <remarks></remarks>
    Sub SetButtons(neu As Boolean)

        ButtonSchliessenBar.BringToFront()
        ButtonTouch.BringToFront()
        ButtonEinstellungen.BringToFront()

        If BARRECHNUNG_KASSA_SIMPEL Then
            SummeLabel.Visible = False
            SummeTextBox.Visible = False
            SummeMWSTLabel.Visible = False
            SummeMWSTTextBox.Visible = False
            WaehrungComboBox.Visible = False
            WaehrungLabel.Visible = False
            ButtonSchliessen.Visible = False
            LabelMessage.Visible = False
        End If

        If BARRECHNUNG_NUR_BRUTTO_PREISE And Not Preis_BruttoTextBox.Enabled Then
            Preis_BruttoTextBox.Enabled = True
        End If


        btnSkonto.Visible = Not BARRECHNUNG_DEAKTIVIERE_RABATT

        Preis_NettoTextBox.Visible = Not BARRECHNUNG_NUR_BRUTTO_PREISE
        Preis_NettoLabel.Visible = Not BARRECHNUNG_NUR_BRUTTO_PREISE
        If BARRECHNUNG_NUR_BRUTTO_PREISE Then
            Preis_BruttoTextBox.BackColor = Preis_NettoTextBox.BackColor
            Preis_BruttoTextBox.TabStop = True
        End If


        KundNrAdressenControl.Visible = Not BARRECHNUNG_DEAKTIVIERE_KUNDE
        KundNrLabel.Visible = Not BARRECHNUNG_DEAKTIVIERE_KUNDE

        MitarbeiterNrComboBox.Visible = Not BARRECHNUNG_DEAKTIVIERE_MITARBEITER
        MitarbeiterNrLabel.Visible = Not BARRECHNUNG_DEAKTIVIERE_MITARBEITER

        Dim vorgang As dsVorgaenge.buchvorgangRow = Nothing
        If BuchvorgangBindingSource.Current IsNot Nothing Then vorgang = BuchvorgangBindingSource.Current.row()
        btnNeu.Enabled = neu Or AbgeschlossenCheckBox.Checked

        btnStorno.Enabled = False
        btnAbschliessen.Enabled = False
        btnZweiterAusdruck.Enabled = AbgeschlossenCheckBox.Checked
        btnNeuePosition.Enabled = Not AbgeschlossenCheckBox.Checked
        btnPositionLoeschen.Enabled = Buchvorgang_artikelBindingSource.Current IsNot Nothing
        PanelPosition.Enabled = Not AbgeschlossenCheckBox.Checked
        GegebenBarTextbox.Enabled = Not AbgeschlossenCheckBox.Checked
        If AbgeschlossenCheckBox.Checked Or vorgang Is Nothing Then
            Ziffernblock1.Enabled = False
        End If

        If vorgang IsNot Nothing Then
            Dim istAbgeschlossen As Boolean = GetVorgang.Abgeschlossen
            btnStorno.Enabled = istAbgeschlossen
            If Not (vorgang.IsSummeBruttoNull) Then
                If IsNumeric(GegebenBarTextbox.Text) And IsNumeric(vorgang.SummeBrutto) Then
                    If (Decimal.Parse(GegebenBarTextbox.Text) >= vorgang.SummeBrutto) Then
                        btnAbschliessen.Enabled = Not vorgang.Abgeschlossen
                    End If
                End If
            End If

            KundNrAdressenControl.Enabled = Not istAbgeschlossen
            MitarbeiterNrComboBox.Enabled = Not istAbgeschlossen

        Else 'kein vorgang exisitert
            btnStorno.Enabled = False
            btnAbschliessen.Enabled = False
            btnZweiterAusdruck.Enabled = False
            btnNeuePosition.Enabled = False
            PanelPosition.Enabled = False
            GegebenBarTextbox.Enabled = False

            KundNrAdressenControl.Enabled = False
            MitarbeiterNrComboBox.Enabled = False
        End If
    End Sub

    ''' <summary>
    ''' Event abfangen und prüfen ob dieEingabe mehr als die Rechnungssumme ist
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub GegebenBarTextbox_TextChanged(sender As Object, e As System.EventArgs) Handles GegebenBarTextbox.TextChanged
        If GegebenBarTextbox.Text = "" Then Exit Sub
        If BuchvorgangBindingSource.Current Is Nothing Then Exit Sub

        'BuchvorgangBindingSource.EndEdit()
        Dim vorgang As dsVorgaenge.buchvorgangRow = BuchvorgangBindingSource.Current.row
        If Not (vorgang.IsSummeBruttoNull) Then
            If IsNumeric(GegebenBarTextbox.Text) And IsNumeric(vorgang.SummeBrutto) Then
                RestgeldTextbox.Text = FormatCurrency(Decimal.Parse(GegebenBarTextbox.Text) - vorgang.SummeBrutto, 2)
            End If
        End If
        SetButtons(False)
    End Sub

    ''' <summary>
    ''' mit ENTER abschliessen
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub GegebenBarTextbox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles GegebenBarTextbox.KeyPress
        If e.KeyChar = ChrW(Keys.Return) Then
            If btnAbschliessen.Enabled Then
                btnAbschliessen.PerformClick()
            End If
        End If
    End Sub

    ''' <summary>
    ''' kopiert von msaccess intrasell
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub GegebenBar_AfterUpdate() Handles GegebenBarTextbox.Validated
        Try

            Dim vorgang As dsVorgaenge.buchvorgangRow = GetVorgang()
            If Not IsNumeric(GegebenBarTextbox.Text) Then Exit Sub
            Dim gegebenBar = Decimal.Parse(GegebenBarTextbox.Text)
            Dim summeATSPlusMWST As Decimal = vorgang.SummeBrutto
            Dim Restgeld As Decimal

            If gegebenBar >= summeATSPlusMWST Then
                'Me.Restgeld = RoundUp(Me.GegebenBar - summeATSPlusMWST, 2)' bereits getan
                GetVorgang().GegebenBar = FormatNumber(gegebenBar, 2)
                If IsNumeric(gegebenBar) Then
                    SetVorgangEigenschaft(BARGELD_GEGEBEN, FormatNumber(gegebenBar, 2))
                End If

                If IsNumeric(RestgeldTextbox.Text) Then
                    SetVorgangEigenschaft(BARGELD_RESTO, FormatNumber(RestgeldTextbox.Text, 2) & "")
                End If
            Else
                Restgeld = RoundUp(gegebenBar - summeATSPlusMWST, 2)
                Dim msg = "Gegeben Bar Betrag muss höher als die Rechnungssumme sein! Es fehlt: " & Math.Abs(Restgeld)
                If Silent Then
                    PostMsg(msg, MsgBoxStyle.Information)
                Else
                    MsgBox(msg, vbInformation)
                End If
            End If
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub StkTextBox_Enter(sender As Object, e As EventArgs) Handles StkTextBox.Enter
        StkTextBox.SelectAll()
    End Sub

    Private Sub Preis_NettoTextBox_Enter(sender As Object, e As EventArgs) Handles Preis_NettoTextBox.Enter
        Preis_NettoTextBox.SelectAll()
    End Sub

    Private Sub btnSkonto_Click(sender As Object, e As EventArgs) Handles btnSkonto.Click
        Dim skonto As Decimal
        Dim skontoText As String = InputBox("Skonto in Prozent vom Netto Preis", "Skontoeingabe", 0)
        Try
            skonto = Decimal.Parse(skontoText)
            Dim pos1 As dsVorgaenge._buchvorgang_artikelRow = Buchvorgang_artikelBindingSource.Current.row
            SkontoAnwenden(pos1, skonto, 0, skontoText)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub


    ''' <summary>
    ''' mit ENTER neue Position
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub StkTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles StkTextBox.KeyPress
        If e.KeyChar = ChrW(Keys.Return) Or e.KeyChar = ChrW(Keys.Enter) Then
            btnNeuePosition.Focus()
            btnNeuePosition.PerformClick()
        End If
    End Sub

    ''' <summary>
    ''' nothing to do, please do not remove otherwise errors as msgbox 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Buchvorgang_artikelDataGridView_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles Buchvorgang_artikelDataGridView.DataError

    End Sub


    Private Sub CheckBoxPrintAmBildschirm_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBoxPrintAmBildschirm.CheckedChanged
        SetVarValue(PRINT_AM_BILDSCHIRM, CheckBoxPrintAmBildschirm.Checked.ToString)
    End Sub

    Private Sub EinstellungenBarToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EinstellungenBarToolStripMenuItem.Click
        Einstellungen.ShowDialog()
    End Sub

    Private Sub ButtonEinstellungen_Click(sender As Object, e As EventArgs)
        Einstellungen.ShowDialog()
    End Sub

    Private Sub VorlageeditierenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles VorlageeditierenToolStripMenuItem.Click
        Try
            Dim ve As New VorlageEditor(VORLAGE_RECHNUNG) With {
                .MdiParent = MdiParent
            }
            ve.Show()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

#Region "Ziffernblock"
    Private Sub StkTextBox_Enter1(sender As Object, e As EventArgs) Handles StkTextBox.Enter
        RemoveAllHandlers()
        AddHandler Ziffernblock1.AmountChanged, AddressOf StkTextBox_AmountChanged
    End Sub

    Private Sub Preis_BruttoTextBox_Enter1(sender As Object, e As EventArgs) Handles Preis_BruttoTextBox.Enter
        RemoveAllHandlers()
        AddHandler Ziffernblock1.AmountChanged, AddressOf Preis_BruttoTextBox_AmountChanged
    End Sub

    Private Sub GegebenBarTextbox_Enter(sender As Object, e As EventArgs) Handles GegebenBarTextbox.Enter
        RemoveAllHandlers()
        AddHandler Ziffernblock1.AmountChanged, AddressOf GegebenBarTextbox_AmountChanged
    End Sub

    Private Sub StkTextBox_AmountChanged(amount As Decimal)
        Try
            Dim pos As dsVorgaenge._buchvorgang_artikelRow = Buchvorgang_artikelBindingSource.Current.row
            pos.Stk = amount
            StkTextBox.Text = amount
            StkChangedFlag = True
            StkTextBox_Validated(Nothing, Nothing)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Preis_BruttoTextBox_AmountChanged(amount As Decimal)
        Try
            Dim pos As dsVorgaenge._buchvorgang_artikelRow = Buchvorgang_artikelBindingSource.Current.row
            pos.Preis_Brutto = amount
            Preis_BruttoTextBox.Text = amount
            Preis_BruttoTextBox_Validated(Nothing, Nothing)
            btnNeuePosition_Click(Nothing, Nothing)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub GegebenBarTextbox_AmountChanged(amount As Decimal)
        Try
            GegebenBarTextbox.Text = amount
            GegebenBar_AfterUpdate()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Zifferblock_Control_Leave(sender As Object, e As EventArgs) ' Handles StkTextBox.Leave, Preis_BruttoTextBox.Leave, GegebenBarTextbox.Leave
        'RemoveAllHandlers()
        Ziffernblock1.Enabled = False
    End Sub

    Private Sub RemoveAllHandlers()
        Try
            RemoveHandler Ziffernblock1.AmountChanged, AddressOf StkTextBox_AmountChanged
            RemoveHandler Ziffernblock1.AmountChanged, AddressOf Preis_BruttoTextBox_AmountChanged
            RemoveHandler Ziffernblock1.AmountChanged, AddressOf GegebenBarTextbox_AmountChanged
            Ziffernblock1.Enabled = True
        Catch ex As Exception
        End Try
    End Sub
#End Region

    Private Sub KundNrAdressenControl_IDNRChanged(IDNR As Integer) Handles KundNrAdressenControl.IDNRChanged
        Try
            Dim vorgang = GetVorgang()
            If vorgang IsNot Nothing Then
                vorgang.KundNr = IDNR
            End If
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

End Class