Imports GrapeCity.ActiveReports 
Imports GrapeCity.ActiveReports.Document

Public Class rptAuswertungUeberfaelligeBestellungen
    Public SDLNr = ""
    Public von As New Date
    Public bis As New Date
    Public kdnr = -1
    Public datVon As Date
    Public erstelltVon As String = ""

    Private Sub PageFooter1_Format(sender As System.Object, e As System.EventArgs) Handles PageFooter.Format
        lblDetails.Text = String.Format("erstellt am {0} um {1} von {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), erstelltVon)

    End Sub

    Private Sub rptAuswertung_NoData(sender As Object, e As System.EventArgs) Handles Me.NoData
        MsgBox("Es wurden keine Daten zum Drucken gefunden.", vbInformation, "Fehler")
        Me.Cancel()  'ev. abbrechen, falls noch aufgebaut wird
    End Sub

    '''''''' ADD AT RUNTIME:
    'Dim d As New GrapeCity.ActiveReports.SectionReportModel.TextBox
    Private Sub rptAuswertung_ReportStart(sender As System.Object, e As System.EventArgs) Handles MyBase.ReportStart

        '''''''' ADD AT RUNTIME:
        'd.Location = New Point(2, 0)
        'd.Text = "asd"
        'Me.Detail.Controls.Add(d)


        '   Me.Name = ""

        'lblHeader.Text = Me.Name

        'Format + Ränder setzen
        '  Me.PageSettings.Orientation = Section.PageOrientation.Portrait
        '  Me.PageSettings.Margins.Left = 0.3
        '  Me.PageSettings.Margins.Right = 0.3
        '  Me.PageSettings.Margins.Top = 0.5
        '  Me.PageSettings.Margins.Bottom = 0.4

        Dim sdlStr = ""
        If IsNumeric(SDLNr) AndAlso SDLNr > 0 Then
            sdlStr = " AND KundenSDL.SDLNr = '" & SDLNr & "'"
        End If
        Dim kdnrtxt = ""
        If IsNumeric(kdnr) AndAlso kdnr > 0 Then
            kdnrtxt = " AND KundenNr='" & kdnr & "'"
        End If
        ' If SDLNr = "-1" Then SDLNr = ""


        Dim sqlStr As String = " SELECT distinct(KundenSDL.[SDLNr]),[SDLBez]  FROM KundenSDL INNER JOIN [Speditionsdienstleistungen] as s ON  KundenSDL.[SDLNr]=s.[SDLNr] where [SDLTypNr]<=2  " & kdnrtxt & " " & sdlStr & " ORDER BY KundenSDL.SDLNr"


        Dim kundenSQL As New kundenSQL
        Me.DataSource = kundenSQL.loadDgvBySql(sqlStr, "SDL")

    End Sub

    '   Dim dummycount As Integer = 0
    Private Sub Detail1_Format(sender As System.Object, e As System.EventArgs) Handles Detail.Format
        lblLeistung.Text = CStr(Fields.Item("SDLNr").Value) & " " & CStr(Fields.Item("SDLBez").Value)

        '   MsgBox("A")
        Dim kd = If(IsNumeric(kdnr) AndAlso kdnr > 0, " AND KundenNr = " & kdnr, "")
        Dim sdlStr = If(IsNumeric(SDLNr) AndAlso SDLNr > 0, " AND SDLNr = '" & CStr(Fields.Item("SDLNr").Value) & "'", "")
        Dim sqlStr As String = " SELECT [KundenNr],Ordnungsbegriff,[KfzKennzeichen],[SDLNr],[History],[Bestelldatum] " &
                             "   FROM [SDL].[dbo].[SDL] INNER JOIN VERAG.dbo.Adressen ON VERAG.dbo.Adressen.AdressenNr=[SDL].[dbo].[SDL].KundenNr " &
                             "   WHERE Bestelldatum BETWEEN '" & von & "' AND '" & bis & "' " &
                                  "   AND Lieferdatum is NULL " &
                                      sdlStr &
                                      kd &
                             "   ORDER BY SDLNr ASC, Bestelldatum ASC, Ordnungsbegriff ASC "
        subrpt.Report = New subrptAuswertungUeberfaelligeBestellungen(sqlStr)


    End Sub
End Class 
