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

Public Class rptGestellungskontrolleEZOLL
    Public datVon As Date
    Public datBis As Date
    Public stat As String = "'F', 'FB'"
    Public operatorId As String = ""
    Public brg As String = "" 'default brg
    Public sqlStr As String = ""
    Public bestimmungszollstelleErreicht As Integer = -1

    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, "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

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


        Me.Name = "Auswertung offene Anträge mit Vorauszahlung"

        '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 sqlStrOLD As String = " SELECT  count(*) as [Anzahl Verz], max(veopos_stat) as Status, max(veoant_beznr) as Bezugsnummer,max(veoant_lfdnr) as LfdNr,max(veoant_anzpos)as Pos,max(veoant_arbnr)as ArbNr,max(veoant_mrn) as MRN,max(veoant_andat) as Antragsdatum,max(veoant_sb) as Sachbearbeiter,max(veoant_wgdat) as Gestellungsdatum,sum(veoerz_sicbtg) as [Sichertheits-Betrag], max(veoerz_sicbsc) as Buergschaft " &
        '" FROM tblZabis_Atlas_NCTS " &
        '" WHERE ( veoant_andat BETWEEN '" & datVon.ToShortDateString & "' AND '" & datBis.ToShortDateString & "') " &
        '" AND  veoant_stat IN (50,53,60) " &
        '" AND veoerz_sicbsc = '" & brg & "' " &
        '" AND  basman_nl='SUW' " &
        '" AND veoant_beznr LIKE 'DU%' " &
        '" GROUP BY veoant_beznr " &
        '" ORDER BY Antragsdatum "


        '   MsgBox(sqlStr)

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


        Label6.Text = "Zeitraum: von " & datVon.ToShortDateString & " bis " & datBis.ToShortDateString
        Label7.Text = "Bürgschaft: " & brg
    End Sub


    Dim dummycount As Integer = 0
    Dim anzLkw As Integer = 0
    Dim anzT As Integer = 0
    Dim summeSiBetr As Double = 0
    Private Sub Detail1_Format(sender As System.Object, e As System.EventArgs) Handles Detail.Format
        dummycount = dummycount + 1
        anzLkw += 1


        lblStatValue.Text = NullValueStr(Fields.Item("ErledigungsTypID").Value, True)
        lblLRN.Text = NullValueStr(Fields.Item("LRN").Value, True)
        lblCRNValue.Text = NullValueStr(Fields.Item("CRN").Value, True)
        lblAnDatValue.Text = NullValueStr(Fields.Item("AnmeldungsDatum").Value, True)
        lblGestDatValue.Text = NullValueStr(Fields.Item("Gestellungsfrist").Value, True)
        lblBstErreicht.Text = NullValueStr(Fields.Item("DatumBestimmungErreicht").Value, True)
        lblAgbZollst.Text = NullValueStr(Fields.Item("Abgangszollstelle").Value, True)
        lblBstZollst.Text = NullValueStr(Fields.Item("Bestimmungszollstelle").Value, True)
        lblSBValue.Text = NullValueStr(Fields.Item("AnmID").Value, True)
        lblBuergschaft.Text = NullValueStr(Fields.Item("GRN").Value, True)
        lblSiBetragValue.Text = "€ " & NullValueDbl(Fields.Item("GarantieWert").Value).ToString("N2", CultureInfo.InvariantCulture)


        '  anzT += CInt(lblAnzTValue.Text)
        summeSiBetr += CDbl(Fields.Item("GarantieWert").Value)

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

    End Sub

    Function NullValueStr(o As Object, Optional strich As Boolean = False) As String
        Try
            If Not o Is DBNull.Value Then Return CStr(o)
        Catch ex As Exception
        End Try
        If strich Then Return "-"
        Return ""
    End Function

    Function NullValueDbl(o As Object, Optional strich As Boolean = False) As Double
        Try
            If Not o Is DBNull.Value Then Return CDbl(o)
        Catch ex As Exception
        End Try
        If strich Then Return "-"
        Return ""
    End Function

    Private Sub ReportFooter1_Format(sender As Object, e As EventArgs) Handles ReportFooter1.Format
        lblSummeSiBetr.Text = "€ " & summeSiBetr.ToString("N2", CultureInfo.InvariantCulture)
        lblAnzAbf.Text = anzLkw
        lblAnzT.Text = anzT

    End Sub
End Class
