
Imports GrapeCity.ActiveReports
Imports GrapeCity.ActiveReports.Document
Imports System.Globalization

Public Class subrptKontrolleLKW
    Public kennzeichen As String
    Public veoant_lfdnr As String
    Public veoant_korant As String
    Public veoant_andat As String
    Public datVon As Date
    Public FIRMA = "DURMAZ"
    Public datBis As Date
    Public AnzT = 0
    Private Sub PageFooter1_Format(sender As System.Object, e As System.EventArgs) Handles PageFooter.Format
    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, "Druck Aviso-Auswertung")
        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

        '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
        If False Then

            Dim brg_AT As String = "05AT510000G000FP7"
            Dim brg_DE As String = "05DE0000000009345"
            Dim brg_DE_NEU As String = "17DE0000000071678"

            Dim sqlStr As String = "  SELECT    max(ant.veoant_beznr) as BezugsNr, max(ant.veoant_arbnr) as ArbNr, max(ant.veoant_mrn) as MRN, max(ant.veoant_anzpos) as Pos, min(ant.veoant_andat) as AnDat, max(ant.veoant_wgdat) as GestllungsDat, max(ant.veoant_sb) as Sachbearbeiter, sum(erz.veoerz_sicbtg) as Sicherheitsbetrag, max(erz.veoerz_sicbsc) as Brg " &
                                    " FROM    dbo.veoant AS ant INNER JOIN " &
                                            " dbo.veopos AS pos ON ant.basman_nr = pos.basman_nr AND ant.basman_nl = pos.basman_nl AND ant.veoant_beznr = pos.veoant_beznr AND ant.veoant_lfdnr = pos.veoant_lfdnr AND  " &
                                            " ant.veoant_korant = pos.veoant_korant LEFT OUTER JOIN " &
                                            " dbo.veoerz AS erz ON pos.basman_nr = erz.basman_nr AND pos.basman_nl = erz.basman_nl AND pos.veoant_beznr = erz.veoant_beznr AND pos.veoant_lfdnr = erz.veoant_lfdnr AND  " &
                                            " pos.veopos_posnr = erz.veopos_posnr And pos.veoant_korant = erz.veoant_korant " &
                                    " WHERE   ant.basman_nr ='VERA' " &
                                        " AND ant.basman_nl ='SUW' " &
                                        " AND ant.veoant_bfabkz='" & kennzeichen & "' " &
                                        " AND ant.veoant_lfdnr='" & veoant_lfdnr & "' " &
                                        " AND ant.veoant_korant='" & veoant_korant & "' " &
                                        " AND ant.veoant_andat='" & veoant_andat & "' " &
                                        " AND erz.veoerz_sicbsc IN ( '" & brg_AT & "' , '" & brg_DE & "'  , '" & brg_DE_NEU & "' ) " &
                                        " and erz.veoerz_typ=2 " &
                                        " AND ( ant.veoant_andat BETWEEN '" & datVon.ToShortDateString & "' AND '" & datBis.ToShortDateString & "') " &
                                        " AND  ant.veoant_stat IN (50,53,60) "
            If FIRMA = "DURMAZ" Then
                sqlStr &= " AND ant.veoant_beznr LIKE 'DU%' "
            ElseIf FIRMA = "ATILLA" Then
                sqlStr &= " AND ant.veoant_beznr NOT LIKE 'DU%' "
            End If
            sqlStr &= " group by veoant_mrn"

            Dim kundenSQL As New kundenSQL
            Me.DataSource = kundenSQL.loadDgvBySql(sqlStr, "ATLAS", 1000)
        End If

    End Sub

    Dim dummycount As Integer = 0
    Private Sub Detail1_Format(sender As System.Object, e As System.EventArgs) Handles Detail.Format
        dummycount = dummycount + 1
        lblBezugsnrValue.Text = nullStr(Fields.Item("BezugsNr").Value)
        'lblArbNrValue.Text = nullStr(Fields.Item("ArbNr").Value)
        lblMRNValue.Text = nullStr(Fields.Item("MRN").Value)
        '.Text = nullStr(Fields.Item("Pos").Value)
        lblAnDatValue.Text = nullStr(Fields.Item("AnDat").Value)
        lblGestDatValue.Text = nullStr(Fields.Item("GestllungsDat").Value)
        lblSBValue.Text = nullStr(Fields.Item("Sachbearbeiter").Value)
        lblBuergschaft.Text = nullStr(Fields.Item("Brg").Value)
        If Not Fields.Item("Sicherheitsbetrag").Value Is DBNull.Value Then
            lblSiBetragValue.Text = "€ " & CDbl(Fields.Item("Sicherheitsbetrag").Value).ToString("N2", CultureInfo.InvariantCulture)
        End If

        AnzT += 1

        'Abwechselnd grauen und weißen Hintergrund
        If (dummycount Mod 2) = 0 Then
            '     Detail.BackColor = Drawing.Color.White
        Else
            '     Detail.BackColor = Drawing.Color.WhiteSmoke
        End If
    End Sub

    Function nullStr(o As Object) As String
        Try
            If o Is DBNull.Value Then Return ""
            Return CStr(o)
        Catch ex As Exception
            Return ""
        End Try
    End Function

End Class
