Public Class frmKundenUebersichtZollRg
    Public kdNr As Integer
    Public jahr As Integer = Now.Year

    Dim SQL As New SQL
    Private Sub frmKundenUebersichtZollRg_Load(sender As Object, e As EventArgs) Handles Me.Load
        initDGVUmsatz()
        Me.Text = "Rechnungen - " & jahr
    End Sub
    Sub initDGVUmsatz()

        With dgvUmsatzbericht
            .Columns.Clear()
            .DataSource = SQL.loadDgvBySql("SELECT [RK_ID],RechnungsDatum, RechnungsNr, [Sammelrechnung],[BelegartenNr],Abfertigungsdatum, FilialenNr, AbfertigungsNr, UnterNr, KundenNrZentrale, RechnungsKundenNr, [RechnungsName 1], [SteuerpflichtigerGesamtbetrag]+[SteuerfreierGesamtbetrag]+([SteuerpflichtigerGesamtbetrag]*[Steuersatz %]) AS Gesamtbetrag " &
                                                " FROM Rechnungsausgang " &
                                          " WHERE Rechnungsausgang.Status Between 1 And 4 " &
                                                " AND RechnungsKundenNr='" & kdNr & "' " &
                                                " AND [RechnungsDatum] between '01.01." & jahr & "' AND '31.12." & jahr & "' " &
                                          " ORDER BY Rechnungsausgang.RechnungsDatum DESC , Rechnungsausgang.RechnungsNr, Rechnungsausgang.Abfertigungsdatum DESC , Rechnungsausgang.FilialenNr, Rechnungsausgang.AbfertigungsNr, Rechnungsausgang.UnterNr ", "FMZOLL")


            .Columns(1).DefaultCellStyle.ForeColor = Color.Red
            .Columns(2).DefaultCellStyle.ForeColor = Color.Red

            .Columns(5).DefaultCellStyle.ForeColor = Color.Blue
            .Columns(6).DefaultCellStyle.ForeColor = Color.Blue
            .Columns(7).DefaultCellStyle.ForeColor = Color.Blue
            .Columns(8).DefaultCellStyle.ForeColor = Color.Blue
            .Columns(12).DefaultCellStyle.Font = New Font(Me.Font.FontFamily, Me.Font.Size, FontStyle.Bold)


            .Columns(0).Visible = False
            .Columns(1).Width = 85
            .Columns(1).HeaderText = "Re/Gu.Datum"
            .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
            .Columns(2).Width = 75
            .Columns(2).HeaderText = "Re/Gu.Nr"
            .Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight
            .Columns(3).Width = 30
            .Columns(3).HeaderText = "E/S"
            .Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight
            .Columns(4).Width = 30
            .Columns(4).HeaderText = "BA"
            .Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight
            .Columns(5).Width = 75
            .Columns(5).HeaderText = "Abf.Datum"
            .Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
            .Columns(6).Width = 50
            .Columns(6).HeaderText = "Filiale"
            .Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
            .Columns(7).Width = 80
            .Columns(7).HeaderText = "Abf.Nr."
            .Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight
            .Columns(8).Width = 32
            .Columns(8).HeaderText = "U.Nr."
            .Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
            .Columns(9).Width = 60
            .Columns(9).HeaderText = "ZeKdNr"
            .Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
            .Columns(10).Width = 60
            .Columns(10).HeaderText = "ReKdNr"
            .Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
            .Columns(11).HeaderText = "Firma"
            .Columns(11).MinimumWidth = 150
            .Columns(11).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            .Columns(12).HeaderText = "Gesamtbetrag"
            .Columns(12).Width = 100
            .Columns(12).DefaultCellStyle.Format = "C2"
            .Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight
        End With

        Try
            If dgvUmsatzbericht.RowCount > 0 Then
                Dim m As Integer = CDate(dgvUmsatzbericht.Rows(0).Cells(1).Value).Month
                Dim c1 As Color = Color.FromArgb(210, 210, 210)
                Dim c2 As Color = Color.White
                Dim c As Color = c1
                For Each r As DataGridViewRow In dgvUmsatzbericht.Rows
                    If Not CDate(r.Cells(1).Value).Month = m Then
                        If c = c1 Then
                            c = c2
                        Else
                            c = c1
                        End If
                        m = CDate(r.Cells(1).Value).Month
                    End If
                    r.DefaultCellStyle.BackColor = c
                Next
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub dgvUmsatzbericht_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvUmsatzbericht.CellDoubleClick
        If dgvUmsatzbericht.SelectedRows.Count > 0 Then
            Dim f As New frmKundenUebersichtZollRgDetails(dgvUmsatzbericht.SelectedRows(0).Cells("RK_ID").Value)
            f.ShowDialog()
        End If
    End Sub
End Class