Public Class frmEinzahlung

    Private BRG As New cBrgDb
    Private Sub frmEinzahlung_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.Items.Add(New MyListItem("Aufschub IMEX Customs Service GmbH", "8"))
        cboBrg.Items.Add(New MyListItem("Aufschub IMEX Customs Service GmbH  (Österreich)", "13"))
        cboBrg.Items.Add(New MyListItem("Aufschub KARACA  (Deutschland)", "27"))
        cboBrg.SelectedIndex = 0
        initDgv()

    End Sub
    Sub initDgv()
        dgvEinzahlungen.DataSource = BRG.loadDgv("SELECT brgak_id, brgakto_bez as Aufschubkonto,brgak_datum as Datum, brgak_betrag as Betrag FROM tblBrgAufschub,tblBrgAufschubKonten WHERE brgakto_id=brgak_brgaktoId AND brgak_art='einzahlung' ")
        dgvEinzahlungen.Columns(0).Visible = False
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If isDouble(cbotxtBetrag.Text) And IsDate(txtFealligkeit._value) Then
            Dim oItem As MyListItem = CType(cboBrg.SelectedItem, MyListItem)
            If BRG.insertBrgAufschubEinzahlung(Now.ToString("dd.MM.yyyy hh:mm:ss"), CDbl(cbotxtBetrag.Text) * -1, oItem.Value, "", "", CDate(txtFealligkeit._value)) Then
                cbotxtBetrag.Text = ""
                lblSaved.Visible = True
                initDgv()
            End If
        Else
            MsgBox("Bitte alle Felder angeben!")
        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 ComboBox1_GotFocus(sender As Object, e As EventArgs) Handles cboBrg.GotFocus, cbotxtBetrag.GotFocus, btnSave.LostFocus
        lblSaved.Visible = False
    End Sub

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

   

    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



End Class