Imports GrapeCity.ActiveReports 
Imports GrapeCity.ActiveReports.Document

Public Class rptSDLBrief
    Public sdlNr As Integer = -1
    Public KdNr As Integer = -1
    Public KUNDE As cKundenFMZOLL
    Public archiviert = False

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


        Dim kundenSQL As New kundenSQL
        'Me.DataSource = kundenSQL.loadDgvBySql(sqlStr, "SDL")
        KUNDE = kundenSQL.getKundeFMZOLLByKdNr(KdNr)

        lblKunde.Text = KUNDE.KundenNr & "  " & KUNDE.Ordnungsbegriff
        lblFirma.Text = KUNDE.Name_1 & vbNewLine &
                        KUNDE.Name_2 & vbNewLine &
                        KUNDE.Straße & vbNewLine & vbNewLine &
                        KUNDE.LandKz & " " & KUNDE.PLZ & " " & KUNDE.Ort
        lblOrtDatum.Text = "Suben, " & Now.ToShortDateString
        lblSDLLeistung.Text = kundenSQL.getValueTxtBySql("SELECT cast ([SDLNr] as varchar(3)) + ' ' + [SDLBez]  FROM [Speditionsdienstleistungen]  where SDLNr=" & sdlNr, "SDL")
    End Sub

    Private Sub Detail1_Format(sender As System.Object, e As System.EventArgs) Handles Detail.Format
        Dim sqlStr As String = " SELECT SDL.[KundenNr],SDL.[KfzKennzeichen],SDL.[SDLNr],SDL.[History],SDL.[RefKundenNr],SDL.[MSE-Kd-Nr],SDL.[TELEPASS-Kd-Nr],SDL.[CLIENT-Nr],SDL.[BestellNr],SDL.[Bestelldatum],SDL.[Lieferdatum],SDL.[Ausstellungsdatum],SDL.[Umstellungsdatum],SDL.[KartenNr],SDL.[PAN-Nr],SDL.[VIACARD],SDL.[MOTORWAY-CARD-Nr],SDL.[CARD-Nr],SDL.[KartenSchlüsselNr],SDL.[FREJUS-CARD-Nr],SDL.[ECO],SDL.[GültigBis],SDL.[OBUID],SDL.[SERIE-Nr],SDL.[TELEPASS-Nr],SDL.[Vermerk],SDL.[Partner],SDL.[BenutzerNr],SDL.[PIN],SDL.[FlottenPIN],SDL.[MasterPIN],SDL.[VertragsNr],SDL.[Vertragsabschlussdatum],SDL.[Kategorie],SDL.[Schadstoffklasse],SDL.[Status],SDL.[Ersatzkarte],SDL.[Gesperrt],SDL.[Defekt],SDL.[Verloren],SDL.[Gestohlen],SDL.[Erfassungsdatum],SDL.[Änderungsdatum],SDL.[Sachbearbeiter] "
        sqlStr &= " FROM SDL INNER JOIN LKW ON (LKW.KfzKennzeichen = sdl.KfzKennzeichen  AND lkw.KundenNr=sdl.KundenNr)  "
        sqlStr &= " WHERE sdl.KundenNr= '" & KdNr & "' "
        If archiviert Then
            sqlStr &= " AND isnull([archiviert] ,0)=1 "
        Else
            sqlStr &= " AND isnull([archiviert] ,1)=0 "
            '  sqlStr &= " AND  isnull(lkw.KZAenderung ,0)=0 AND isnull(lkw.Verkauft  ,0)=0 AND isnull(lkw.Abgemeldet  ,0)=0  AND isnull([Gesperrt],0)=0 AND isnull([Defekt] ,0)=0 AND isnull([Verloren] ,0)=0 AND isnull([Gestohlen] ,0)=0 "
            sqlStr &= "/* AND  isnull(lkw.KZAenderung ,0)=0 AND isnull(lkw.Verkauft  ,0)=0 AND isnull(lkw.Abgemeldet  ,0)=0 */  AND isnull([Gesperrt],0)=0 AND isnull([Defekt] ,0)=0 AND isnull([Verloren] ,0)=0 AND isnull([Gestohlen] ,0)=0 "
        End If
        Dim order As String = " ORDER BY SDLNr, Bestelldatum, BestellNr,Ausstellungsdatum,KartenNr,OBUID"


        Select Case sdlNr
            Case 200 : SubReport.Report = New subrptBriefSDL_AT(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 203 : SubReport.Report = New subrptBriefSDL_CZ(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 201 : SubReport.Report = New subrptBriefSDL_DE(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 207 : SubReport.Report = New subrptBriefSDL_FREJUS(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 204 : SubReport.Report = New subrptBriefSDL_FR(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 100 : SubReport.Report = New subrptBriefSDL_IDS(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 202 : SubReport.Report = New subrptBriefSDL_IT(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 208 : SubReport.Report = New subrptBriefSDL_MSE(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 211 : SubReport.Report = New subrptBriefSDL_MULTIBOX(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 209 : SubReport.Report = New subrptBriefSDL_PL(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 210 : SubReport.Report = New subrptBriefSDL_SI(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 212 : SubReport.Report = New subrptBriefSDL_UTA(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 101 : SubReport.Report = New subrptBriefSDL_WOELFL(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 213 : SubReport.Report = New subrptBriefSDL_HUGO(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 214 : SubReport.Report = New subrptBriefSDL_PLOSE(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 215 : SubReport.Report = New subrptBriefSDL_PLOSE_IT(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 216 : SubReport.Report = New subrptBriefSDL_PLOSE_CZ(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 217 : SubReport.Report = New subrptBriefSDL_PLOSE_MEDPASS(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 218 : SubReport.Report = New subrptBriefSDL_PLOSE_truckmaster(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case 501, 502 : SubReport.Report = New subrptBriefSDL_VERAGCARD(sqlStr & " AND SDLNr=" & sdlNr & " " & order)
            Case Else : MsgBox("Für diese Leistung kann kein Bericht erstellt werden!")
        End Select
    End Sub
End Class
