Imports GrapeCity.ActiveReports 
Imports GrapeCity.ActiveReports.Document

Public Class subRptAbfertigungen
    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
    Dim AbfKostKdnr As Integer
    'Dim ABF_ART As Integer
    Sub New(AbfKostKdnr As Integer)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.AbfKostKdnr = AbfKostKdnr
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
    End Sub

    Private Sub Detail_Format(sender As Object, e As EventArgs) Handles Detail.Format
        Try
            If Me.DataSource IsNot Nothing AndAlso DirectCast(Me.DataSource, DataTable).Rows.Count > 0 AndAlso Me.Fields IsNot Nothing Then

                If Me.Fields.Item("Abfertigungsart") IsNot Nothing AndAlso Me.Fields.Item("Abfertigungsart").Value IsNot Nothing Then txtLeistungsNr.Text = Me.Fields.Item("Abfertigungsart").Value.ToString
                If Me.Fields.Item("Anzahl") IsNot Nothing AndAlso Me.Fields.Item("Anzahl").Value IsNot DBNull.Value Then txtLeistungsBez.Text = (Me.Fields.Item("Anzahl").Value).ToString
            End If
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try

    End Sub
    Private Sub rptAuswertung_ReportStart(sender As System.Object, e As System.EventArgs) Handles MyBase.ReportStart
        If AbfKostKdnr <= 0 Then Exit Sub

        Dim d_von As Date = CDate(Now.AddMonths(-1).ToString("01.MM.yyyy"))
        Dim d_bis As Date = d_von.AddMonths(1).AddDays(-1)

        d_von = d_von.AddYears(-1).AddMonths(1) ' VON 1 JAHR zurück -> Auswertungszeitraum 1 Jahr!

        Dim sqlStr = "SELECT cast([Speditionsbuch].Abfertigungsart as varchar(3)) + ' - ' + aa.Abfertigungsbezeichnung as Abfertigungsart, count (*) as Anzahl"
        sqlStr &= " FROM [Speditionsbuch] INNER JOIN Abfertigungsarten AA ON AA.Abfertigungsart=Speditionsbuch.Abfertigungsart "
        sqlStr &= " where (EmpfängerKundenNr =  '" & AbfKostKdnr & "' OR AbsenderKundenNr =  '" & AbfKostKdnr & "' OR AvisiererKundenNr = '" & AbfKostKdnr & "') and Abfertigungsdatum between '" & d_von & "' and '" & d_bis & "' "
        sqlStr &= " group by [Speditionsbuch].Abfertigungsart,aa.Abfertigungsbezeichnung "
        sqlStr &= " order by count(*) DESC "

        Me.DataSource = SQL.loadDgvBySql(sqlStr, "FMZOLL")

        txtVonBis.Text = d_von.ToShortDateString & "-" & d_bis.ToShortDateString

    End Sub

    'Private Sub GroupHeader1_Format(sender As Object, e As EventArgs) Handles GroupHeader1.Format
    '    'Dim OffertenNr = Me.Fields.Item("OffertenNr").Value
    '    'If OffertenNr IsNot Nothing Then
    '    '    lbl1Zollabfertigung.Text = OffertenNr & " - " & SQL.getValueTxtBySql("SELECT [OffertenBez]  FROM [Offertenstamm] WHERE OffertenNr=" & OffertenNr, "FMZOLL")
    '    'End If
    'End Sub
End Class