Public Class frmZusBelast
    Private BRG As New cBrgDb

    Private Sub frmZusBelast_Load(sender As Object, e As EventArgs) Handles Me.Load
        cboBrg.Items.Add(New MyListItem("Aufschub VERAG Spedition AG (Deutschland)", "1"))
        cboBrg.Items.Add(New MyListItem("Aufschub VERAG Spedition AG (Österreich)", "2"))
        cboBrg.Items.Add(New MyListItem("Aufschub VERAG Customs Service GmbH (Österreich)", "3"))
        cboBrg.Items.Add(New MyListItem("Aufschub VERAG Zollservice GmbH (Österreich)", "4"))
        cboBrg.SelectedIndex = 0
        initDgv()
    End Sub

    Sub initDgv()
        dgvEinzahlungen.DataSource = BRG.loadDgv("SELECT brgak_id, brgakto_bez as Aufschubkonto,brgak_datum as Datum,brgak_atc,brgak_betrag as Betrag FROM tblBrgAufschub,tblBrgAufschubKonten WHERE brgakto_id=brgak_brgaktoId AND brgak_art='belastung' ")
        dgvEinzahlungen.Columns(0).Visible = False
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If isDouble(cbotxtBetrag.Text) Then
            Dim oItem As MyListItem = CType(cboBrg.SelectedItem, MyListItem)
            If BRG.insertBrgAufschubZuBelastung(Now.ToString("dd.MM.yyyy hh:mm:ss"), CDbl(cbotxtBetrag.Text), oItem.Value, "", txtArt.Text) Then
                cbotxtBetrag.Text = ""
                lblSaved.Visible = True
                initDgv()
            End If
        End If
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles cbotxtBetrag.TextChanged
        If isDouble(sender.text) Then
            sender.ForeColor = Color.DarkGreen
        Else
            sender.ForeColor = Color.DarkRed
        End If
    End Sub
    Function isDouble(s)
        Try : Dim d = CDbl(s) : Return True
        Catch : Return False : End Try
    End Function

    Private Sub dgvEinzahlungen_KeyDown(sender As Object, e As KeyEventArgs) Handles dgvEinzahlungen.KeyDown
        If e.KeyCode = Keys.Delete Then
            If vbYes = MsgBox("Möchten Sie den Eintrag löschen?", vbYesNo) Then
                If BRG.delBrgAufschubEinzahlung(dgvEinzahlungen.CurrentRow.Cells(0).Value) Then
                    initDgv()
                End If
            End If
        End If
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub txtArt_TextChanged(sender As Object, e As EventArgs) Handles txtArt.TextChanged

    End Sub

    Private Sub Label5_Click(sender As Object, e As EventArgs) Handles Label5.Click

    End Sub

    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

    End Sub

    Private Sub dgvEinzahlungen_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvEinzahlungen.CellContentClick

    End Sub

    Private Sub cboBrg_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboBrg.SelectedIndexChanged

    End Sub

    Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click

    End Sub

    Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click

    End Sub

    Private Sub lblSaved_Click(sender As Object, e As EventArgs) Handles lblSaved.Click

    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub
End Class