Public Class frmKtoStandAkt
    Dim brg_DE_VeragAG As String = "1" ' aus eigener DB
    Dim brg_AT_VeragAG_Aufschub As String = "2"
    Dim brg_AT_VeragZS_Aufschub As String = "4"
    Dim brg_AT_VeragCS_Aufschub As String = "3"

    Dim brg_AT_VeragAG As String = "3025365"
    Dim brg_AT_VeragZS As String = "3026400"
    Dim brg_AT_VeragCS As String = "3517233"

    Private BRG As New cBrgDb

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

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If Not IsNumeric(txtKto.Text) Then MsgBox("Betrag Kontostand im falschem Format!") : Exit Sub
        If Not IsDate(datKto.Value) Then MsgBox("Datum im falschem Format!") : Exit Sub
        If cboBrg.SelectedIndex > 0 Then
            ' Dim oItem As MyListItem = CType(cboBrg.SelectedItem, MyListItem)
            'If BRG.insertBrgAufschubZuBelastung(Now.ToString("dd.MM.yyyy hh:mm:ss"), CDbl(txtKto.Text), oItem.Value, "", txtArt.Text) Then
            ' txtKto.Text = ""
            '' lblSaved.Visible = True
            ' initDgv()
            ' End If
        End If
        Dim von As New Date(2015, 1, 1)
        Dim bis As Date = CDate(datKto.Value)
        Dim betrag As Double = 0.0
        Dim oItem As MyListItem = CType(cboBrg.SelectedItem, MyListItem)



        If BRG.deleteBrgAufschubAusgleichsbetrag(oItem.Value) Then
            Select Case DirectCast(cboBrg.SelectedItem, MyListItem).Value
                Case 1
                Case 2
                    betrag = CDbl(BRG.getBrgSumFromZolaris(von.ToShortDateString, bis.ToShortDateString, brg_AT_VeragAG, True)) _
                                                       + CDbl(BRG.getBrgSumFromBrgKto(von.ToShortDateString, bis.ToShortDateString, brg_AT_VeragAG_Aufschub))
                Case 3

                    betrag = CDbl(BRG.getBrgSumFromZolaris(von.ToShortDateString, bis.ToShortDateString, brg_AT_VeragCS, True)) _
                      + CDbl(BRG.getBrgSumFromBrgKto(von.ToShortDateString, bis.ToShortDateString, brg_AT_VeragCS_Aufschub))

                Case 4
                    betrag = CDbl(BRG.getBrgSumFromZolaris(von.ToShortDateString, bis.ToShortDateString, brg_AT_VeragZS, True)) _
                                                                    + CDbl(BRG.getBrgSumFromBrgKto(von.ToShortDateString, bis.ToShortDateString, brg_AT_VeragZS_Aufschub))

            End Select

            '  Dim ausgleichsbetrag = 25000 - CDbl(txtKto.Text) - betrag
            Dim ausgleichsbetrag = -1 * (CDbl(txtKto.Text) + betrag)


            If BRG.insertBrgAufschubAusgleichsbetrag(Now.ToString("dd.MM.yyyy hh:mm:ss"), ausgleichsbetrag, oItem.Value, "", "") Then
                Me.Close()
            End If
        End If
    End Sub

    Private Sub frmKtoStandAkt_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
    End Sub
End Class