Imports GrapeCity.ActiveReports 
Imports GrapeCity.ActiveReports.Document 

Public Class subRptOfferte
    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
    Dim AbfKostKdnr As Integer
    Dim ABF_ART As Integer
    Sub New(ABF_ART As Integer, AbfKostKdnr As Integer)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.ABF_ART = ABF_ART
        Me.AbfKostKdnr = AbfKostKdnr
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
    End Sub

    Private Sub Detail_Format(sender As Object, e As EventArgs) Handles Detail.Format
        If Me.DataSource IsNot Nothing AndAlso DirectCast(Me.DataSource, DataTable).Rows.Count > 0 AndAlso Me.Fields IsNot Nothing Then
            If Me.Fields.Item("LeistungsNr") IsNot Nothing AndAlso Me.Fields.Item("LeistungsNr").Value IsNot Nothing Then txtLeistungsNr.Text = Me.Fields.Item("LeistungsNr").Value.ToString
            If Me.Fields.Item("LeistungsBez") IsNot Nothing AndAlso Me.Fields.Item("LeistungsBez").Value IsNot Nothing Then txtLeistungsBez.Text = Me.Fields.Item("LeistungsBez").Value.ToString
            If Me.Fields.Item("Preis") IsNot Nothing AndAlso Me.Fields.Item("Preis").Value IsNot Nothing And CDbl(Me.Fields.Item("Preis").Value) <> 0 Then
                txtPreis.Text = If(IsNumeric(Me.Fields.Item("Preis").Value.ToString), CDbl(Me.Fields.Item("Preis").Value.ToString).ToString("C2"), Me.Fields.Item("Preis").Value.ToString)
            Else
                txtPreis.Text = ""
            End If
            If Me.Fields.Item("Datum") IsNot Nothing AndAlso Me.Fields.Item("Datum").Value IsNot DBNull.Value Then txtGeaendertAm.Text = CDate(Me.Fields.Item("Datum").Value).ToShortDateString
        End If
    End Sub
    Private Sub rptAuswertung_ReportStart(sender As System.Object, e As System.EventArgs) Handles MyBase.ReportStart
         If AbfKostKdnr <= 0 Then Exit Sub
        If ABF_ART > 0 Then
            Me.DataSource = SQL.loadDgvBySql("select OffertenNr, isnull(LeistungsNr,'') as LeistungsNr,isnull(LeistungsBez,'' ) as LeistungsBez,isnull(Preis,'') as Preis,isnull([Geändert am],[Eingegeben am]) as Datum  FROM [Offertenpositionen] where KundenNr=" & AbfKostKdnr & " AND OffertenNr=(SELECT ISNULL(AO.ao_OffertenNr,-1) FROM tblAbfertigungsartOffertenstamm as AO WHERE AO.ao_Abfertigungsart='" & ABF_ART & "') /*and preis is not null*/ order by OffertenNr,LeistungsNr, Preis desc", "FMZOLL")
        Else
            Me.DataSource = SQL.loadDgvBySql("select OffertenNr, isnull(LeistungsNr,'') as LeistungsNr,isnull(LeistungsBez,'' ) as LeistungsBez,isnull(Preis,'') as Preis,isnull([Geändert am],[Eingegeben am]) as Datum FROM [Offertenpositionen] where KundenNr=" & AbfKostKdnr & " /*and preis is not null*/ order by OffertenNr,LeistungsNr, Preis desc", "FMZOLL")
        End If

        Me.GroupHeader1.DataField = "OffertenNr" 'Gruppierung

    End Sub

    Private Sub GroupHeader1_Format(sender As Object, e As EventArgs) Handles GroupHeader1.Format
        Dim OffertenNr = Me.Fields.Item("OffertenNr").Value
        If OffertenNr IsNot Nothing Then
            lbl1Zollabfertigung.Text = OffertenNr & " - " & SQL.getValueTxtBySql("SELECT [OffertenBez]  FROM [Offertenstamm] WHERE OffertenNr=" & OffertenNr, "FMZOLL")
        End If
    End Sub
End Class
