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

Public Class subrptAuswertungMWSTOffeneAntraegeMitVorauszahlungDetails
    Public kdnr As String
    Public datVon As Date
    Private Sub PageFooter1_Format(sender As System.Object, e As System.EventArgs)
    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 sqlStr As String = " SELECT  [Länderverzeichnis für die Außenhandelsstatistik].LandKz as Land,UStVAn_ReDatVon as von,UStVAn_ReDatBis as bis,([UStVAn_USteuerbetragEUR]-[UStVAn_ErstattungsbetragEUR]) as Betrag" &
                                    " FROM tblUStVAntrag INNER JOIN [Länderverzeichnis für die Außenhandelsstatistik] ON tblUStVAntrag.UStVAn_LandNr = [Länderverzeichnis für die Außenhandelsstatistik].LandNr" &
                                    " INNER JOIN Adressen on Adressen.AdressenNr=tblUStVAntrag.UStVAn_KuNr " &
                                " WHERE tblUStVAntrag.UStVAn_KuNr = '" & kdnr & "' " &
                                    " and UStVAn_ReDatVon >='" & datVon.ToShortDateString & "'  " &
                                    " and UStVAn_ReDatBis <=GETDATE() " &
                                    " and ([UStVAn_USteuerbetrag]-[UStVAn_Erstattungsbetrag])>0 " &
                                    " and Adressen.MWSTVorauszahlung is not null " &
                                    " and Adressen.MWSTVorauszahlung = 1 " &
                                    " and UStVAn_VZBetrag is null "

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

    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
        txtDetailsLand.Text = nullStr(Fields.Item("Land").Value)
        txtDetailsVon.Text = nullStr(Fields.Item("von").Value)
        txtDetailsBis.Text = nullStr(Fields.Item("bis").Value)
        If Not Fields.Item("Betrag").Value Is DBNull.Value Then
            txtDetailsBetrag.Text = "€ " & CDbl(Fields.Item("Betrag").Value).ToString("N2", CultureInfo.InvariantCulture)
        End If



        '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
