Imports GrapeCity.ActiveReports 
Imports GrapeCity.ActiveReports.Document

Public Class subRptVM

    Dim Kdnr As Integer

    Sub New(Kdnr As Integer)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.Kdnr = Kdnr
        ' 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 Me.Fields IsNot Nothing Then
            If Me.Fields.Item("kdvma_Bezeichnung") IsNot Nothing AndAlso Me.Fields.Item("kdvma_Bezeichnung").Value IsNot Nothing Then txtBez.Text = Me.Fields.Item("kdvma_Bezeichnung").Value.ToString
            'If Me.Fields.Item("kdvm_erhalten_Datum") IsNot Nothing AndAlso Me.Fields.Item("kdvm_erhalten_Datum").Value IsNot Nothing Then txtDatum.Text = Me.Fields.Item("kdvm_erhalten_Datum").Value.ToString
            If Me.Fields.Item("kdvm_erhalten_Datum") IsNot Nothing AndAlso Me.Fields.Item("kdvm_erhalten_Datum").Value IsNot Nothing Then
                txtDatum.Text = If(IsDate(Me.Fields.Item("kdvm_erhalten_Datum").Value.ToString), CDate(Me.Fields.Item("kdvm_erhalten_Datum").Value.ToString).ToShortDateString, Me.Fields.Item("kdvm_erhalten_Datum").Value.ToString)
            End If
        End If
    End Sub
    Private Sub rptAuswertung_ReportStart(sender As System.Object, e As System.EventArgs) Handles MyBase.ReportStart
        If Kdnr <= 0 Then Exit Sub

        Dim where = ""
        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "IMEX" : where = " AND art.kdvma_Firma='IMEX' "
            Case Else : where = " AND art.kdvma_Firma<>'IMEX' "
        End Select

        Me.DataSource = (New VERAG_PROG_ALLGEMEIN.SQL).loadDgvBySql("SELECT abf.kdvm_Id,art.kdvma_Id,  art.kdvma_Bezeichnung, abf.[kdvm_KundenNr], abf.[kdvm_erhalten],abf.[kdvm_erhalten_Datum], abf.kdvm_datenarchivId,abf.kdvm_Info " &
                                                    "  FROM [tblKundenVollmachtenArt] as art LEFT  JOIN (select * from [tblKundenVollmachten] where [kdvm_KundenNr]='" & Kdnr & "' ) as abf on art.[kdvma_Id]=abf.[kdvm_kdvmaId] WHERE art.kdvma_visible=1 AND abf.[kdvm_erhalten]=1 " & where &
                                                    " ORDER BY art.kdvma_id", "FMZOLL")

    End Sub

End Class
