Imports System.IO
Imports Microsoft.Reporting.WinForms
Imports DevExpress.XtraPrinting
Imports Microsoft.SqlServer
Imports DevExpress.XtraReports.UI
Imports DevExpress.Utils
Imports DevExpress.XtraPrinting.Caching

Public Class frmDruckansicht

    Public Sub BefüllenAbrechnung(ByVal titel As String, ByVal ds As IList(Of cParkzeitDruck), ByVal tarif As String, ByVal hAuswahl As String,
                                ByVal hGesamtdauer As String, ByVal hGesamtkosten As String)
        '     Dim rdlcName As String = "Parkzeit.rptAbrechnung.rdlc"
        Dim rdlcName = "Parkzeit.rptAbrechnungVERAG2.rdlc"
        'Dim rdlcName As String = "Parkzeit.rptAbrechnung.rdlc"

        'Select Case tarif
        '    Case "WABERERS"
        '        rdlcName = "Parkzeit.rptAbrechnungWABERERS.rdlc"
        '    Case Else

        '        rdlcName = "Parkzeit.rptAbrechnungVERAG.rdlc"
        'End Select

        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = rdlcName


        'Select Case hAuswahl
        '    Case "WABERERS"
        '    Case Else
        '        Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Image1", hGesamtkosten))
        'End Select
        Try

            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Titel", titel))
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("SelektionText", hAuswahl))
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Firmenname", "VERAG Spedition AG"))
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Gesamtdauer", hGesamtdauer))
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Gesamtkosten", hGesamtkosten))
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("KostenJeStunde", "0"))
            'Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Anwender", SystemInformation.UserName.ToString))
            'Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("SelektionText", "Selektion: angeforderte, aber nicht erhaltene Bilanzen; Sortierung nach Sachbearbeiter, Kundennr"))
            'Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("GruppierungNachBetreuer", boolToJaNein(True)))
            Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", ds))


        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
        Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
        Me.ReportViewer1.RefreshReport()



    End Sub


    Public Function genPDF(pathTo As String, Optional closeMe As Boolean = False) As Boolean
        Try
            Dim mybytes As Byte() = Me.ReportViewer1.LocalReport.Render("PDF")

            If mybytes IsNot Nothing AndAlso mybytes.Length > 0 Then

                Using fs As FileStream = File.Create(pathTo)
                    fs.Write(mybytes, 0, mybytes.Length)
                End Using

            End If
            If closeMe Then Me.Close()
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
            Return False
        End Try
        Return True
    End Function
    'Private Sub reportVorbereiten(ByVal gruppierungNachBetreuer As Boolean, ByRef reportPath As String)
    '  Dim doc As XDocument = XDocument.Parse(My.Resources.rptBilanzenAuswertung)

    '  If Not gruppierungNachBetreuer Then
    '    Const ns As String = "{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}"  'namespace
    '    'GroupExpression entfernen
    '    For Each groupNode As XElement In doc.Descendants(ns & "Group")
    '      If groupNode.HasAttributes AndAlso groupNode.Attributes("Name").Count = 1 AndAlso groupNode.Attributes("Name")(0).Value = "GroupBetreuer" Then
    '        groupNode.Elements(ns & "GroupExpressions")(0).Elements(ns & "GroupExpression")(0).Value = ""
    '        Exit For
    '      End If
    '    Next

    '    'Inhalt der Gruppe entfernen
    '    For Each groupNode As XElement In doc.Descendants(ns & "Rectangle")
    '      If groupNode.HasAttributes AndAlso groupNode.Attributes("Name").Count = 1 AndAlso groupNode.Attributes("Name")(0).Value = "GroupBetreuerRectangle" Then
    '        groupNode.Elements(ns & "ReportItems").Remove()
    '        Exit For
    '      End If
    '    Next

    '    'Höhe der Gruppe auf 0 setzen
    '    Dim row As XElement = doc.Descendants(ns & "TablixRow").First
    '    row.Elements(ns & "Height").First.Value = "0.01625in"
    '  End If

    '  reportPath = Path.GetTempPath() & "BilanzenAuswertung.rdlc"
    '  doc.Save(reportPath)
    'End Sub

    'Public Sub BefüllenSerienbrief(ByVal ds As IList(Of cSerienbriefdruck), ByVal hBearbeiter As String, ByVal hOrt As String, ByVal hTyp As Integer)
    '  'Optionen laden
    '  Dim myOptionen As New cOptionenDAL
    '  myOptionen.OpenConnection(frmMain.connStr)
    '  Dim optionen As cOptionen = myOptionen.LesenOptionen()
    '  myOptionen.CloseConnection()


    '  Dim rdlcName As String = "Bilanzen.SerienbriefAuswertung.rdlc"
    '  Me.ReportViewer1.LocalReport.ReportEmbeddedResource = rdlcName
    '  Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Text_Schriftart", "Arial"))
    '  Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Text_Größe", optionen.Text_Größe & "pt"))
    '  Dim fontWeight As String = "Default"
    '  If (optionen.Auflistung_Fett) Then
    '    fontWeight = "Bold"
    '  End If

    '  Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Auflistung_fett", fontWeight))
    '  Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("BriefpartnerUndDurchwahl", hBearbeiter))
    '  Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("GeschäftsstelleUndDatum", hOrt))
    '  'Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Kopf_Bilanz", "Kopf"))
    '  'Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Fuss_Bilanz", "Fuß"))
    '  Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Kopf_Bilanz", "")) 'convertToHTML(hKopf)))
    '  Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter("Fuss_Bilanz", "")) 'convertToHTML(hFuß)))
    '  Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("SerienbriefDataSet", ds))
    '  Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
    '  Me.ReportViewer1.RefreshReport()
    '  Me.ReportViewer1.Focus()

    'End Sub




    Private Function boolToJaNein(ByVal wert As Boolean) As String
        If wert Then
            Return "ja"
        Else
            Return "nein"
        End If
    End Function

    Private Sub frmDruckansicht_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class