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

Public Class rptTGestellungskontrolleDY
    Public datVon As Date
    Public datBis As Date
    Public FIRMA As String
    Public statVon As String = "50"
    Public statBis As String = "53"
    Public brg As String = "" 'default brg
    Public nl As String = ""
    Public sqlStr As String = ""

    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 = "Gestellungskontrolle Dakosy"

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

      
        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
        lblAnDatValue.Text = If(Fields.Item("Antragsdatum").Value Is DBNull.Value, "", CStr(Fields.Item("Antragsdatum").Value))
        '  lblAnzTValue.Text = CStr(Fields.Item("Anzahl Verz").Value)
        Label10.Text = CStr(Fields.Item("Niederlassung").Value)
        ' lblEmpfaenger.Text = CStr(Fields.Item("ArbNr").Value)
        lblEmpfaenger.Text = CStr(Fields.Item("Empfaenger").Value)
        lblBezugsnrValue.Text = CStr(Fields.Item("Bezugsnummer").Value)
        If Fields.Item("Gestellungsdatum").Value IsNot Nothing AndAlso Fields.Item("Gestellungsdatum").Value Is DBNull.Value Then
            lblGestDatValue.Text = ""
        Else
            lblGestDatValue.Text = CStr(Fields.Item("Gestellungsdatum").Value)
        End If

        lblMRNValue.Text = CStr(Fields.Item("MRN").Value)
        lblSBValue.Text = CStr(Fields.Item("Sachbearbeiter").Value)
        lblBuergschaft.Text = CStr(Fields.Item("Buergschaft").Value)
        lblSiBetragValue.Text = "€ " & CDbl(Fields.Item("Sichertheits-Betrag").Value).ToString("N2", CultureInfo.InvariantCulture)
        lblStatValue.Text = CStr(Fields.Item("Status").Value)

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

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

    End Sub

    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
