147 lines
5.5 KiB
VB.net
147 lines
5.5 KiB
VB.net
Imports System.IO
|
|
Imports DevExpress.Xpf.Core
|
|
Imports DevExpress.Xpf.Grid.Printing
|
|
Imports DevExpress.XtraPrinting
|
|
Imports DevExpress.XtraReports.UI
|
|
|
|
Public Class tsXtraReport
|
|
Public Shared Sub ExportarAPDF(Plantilla() As Byte, Datos As Object, FicheroPDF As String)
|
|
Dim xr As DevExpress.XtraReports.UI.XtraReport
|
|
Dim s As String = System.Text.Encoding.UTF8.GetString(Plantilla)
|
|
Using sw As New StreamWriter(New MemoryStream())
|
|
sw.Write(s)
|
|
sw.Flush()
|
|
|
|
xr = DevExpress.XtraReports.UI.XtraReport.FromStream(sw.BaseStream, True)
|
|
End Using
|
|
Try
|
|
Dim pr As Global.DevExpress.XtraReports.Parameters.Parameter = (From p As DevExpress.XtraReports.Parameters.Parameter In xr.Parameters Where p.Name = "Fecha").First
|
|
pr.Value = Now
|
|
pr.Visible = False
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
xr.DataSource = Datos
|
|
xr.CreateDocument()
|
|
xr.ExportToPdf(FicheroPDF)
|
|
End Sub
|
|
|
|
Public Shared Sub ExportarAxls(Plantilla() As Byte, Datos As Object, Ficheroxls As String)
|
|
Dim xr As DevExpress.XtraReports.UI.XtraReport
|
|
Dim s As String = System.Text.Encoding.UTF8.GetString(Plantilla)
|
|
Using sw As New StreamWriter(New MemoryStream())
|
|
sw.Write(s)
|
|
sw.Flush()
|
|
xr = DevExpress.XtraReports.UI.XtraReport.FromStream(sw.BaseStream, True)
|
|
End Using
|
|
Try
|
|
Dim pr As Global.DevExpress.XtraReports.Parameters.Parameter = (From p As DevExpress.XtraReports.Parameters.Parameter In xr.Parameters Where p.Name = "Fecha").First
|
|
pr.Value = Now
|
|
pr.Visible = False
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
xr.DataSource = Datos
|
|
xr.CreateDocument()
|
|
xr.ExportToXls(Ficheroxls)
|
|
|
|
End Sub
|
|
Public Shared Sub ExportarAxlsx(Plantilla() As Byte, Datos As Object, Ficheroxlsx As String)
|
|
Dim xr As DevExpress.XtraReports.UI.XtraReport
|
|
Dim s As String = System.Text.Encoding.UTF8.GetString(Plantilla)
|
|
Using sw As New StreamWriter(New MemoryStream())
|
|
sw.Write(s)
|
|
sw.Flush()
|
|
xr = DevExpress.XtraReports.UI.XtraReport.FromStream(sw.BaseStream, True)
|
|
End Using
|
|
Try
|
|
Dim pr As Global.DevExpress.XtraReports.Parameters.Parameter = (From p As DevExpress.XtraReports.Parameters.Parameter In xr.Parameters Where p.Name = "Fecha").First
|
|
pr.Value = Now
|
|
pr.Visible = False
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
xr.DataSource = Datos
|
|
xr.CreateDocument()
|
|
xr.ExportToXlsx(Ficheroxlsx)
|
|
|
|
End Sub
|
|
Public Shared Sub ExportarAcsv(Plantilla() As Byte, Datos As Object, Ficherocsv As String)
|
|
Dim xr As DevExpress.XtraReports.UI.XtraReport
|
|
Dim s As String = System.Text.Encoding.UTF8.GetString(Plantilla)
|
|
Using sw As New StreamWriter(New MemoryStream())
|
|
sw.Write(s)
|
|
sw.Flush()
|
|
xr = DevExpress.XtraReports.UI.XtraReport.FromStream(sw.BaseStream, True)
|
|
End Using
|
|
Try
|
|
Dim pr As Global.DevExpress.XtraReports.Parameters.Parameter = (From p As DevExpress.XtraReports.Parameters.Parameter In xr.Parameters Where p.Name = "Fecha").First
|
|
pr.Value = Now
|
|
pr.Visible = False
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
xr.DataSource = Datos
|
|
xr.CreateDocument()
|
|
xr.ExportToCsv(Ficherocsv)
|
|
|
|
End Sub
|
|
|
|
|
|
Public Shared Function ExportarAPDF(Plantilla() As Byte, Datos As Object) As MemoryStream
|
|
Dim xr As DevExpress.XtraReports.UI.XtraReport
|
|
Dim s As String = System.Text.Encoding.UTF8.GetString(Plantilla)
|
|
Using sw As New StreamWriter(New MemoryStream())
|
|
sw.Write(s)
|
|
sw.Flush()
|
|
|
|
xr = DevExpress.XtraReports.UI.XtraReport.FromStream(sw.BaseStream, True)
|
|
End Using
|
|
Try
|
|
Dim pr As Global.DevExpress.XtraReports.Parameters.Parameter = (From p As DevExpress.XtraReports.Parameters.Parameter In xr.Parameters Where p.Name = "Fecha").First
|
|
pr.Value = Now
|
|
pr.Visible = False
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
xr.DataSource = Datos
|
|
xr.CreateDocument()
|
|
Dim ms As New MemoryStream
|
|
xr.ExportToPdf(ms)
|
|
Return ms
|
|
End Function
|
|
Private Shared NumeroCopias As Integer
|
|
Friend Shared Sub ImprimeInforme(xr As XtraReport, ImpresoraPredeterminada As Boolean, Copias As Integer, Fecha As Date, Datos As Object)
|
|
Try
|
|
For Each pr In xr.Parameters
|
|
pr.Visible = False
|
|
If pr.Name = "Fecha" Then
|
|
pr.Value = Fecha
|
|
End If
|
|
Next
|
|
xr.DataSource = Datos
|
|
xr.CreateDocument(True)
|
|
If ImpresoraPredeterminada Then
|
|
If Copias < 2 Then
|
|
NumeroCopias = 1
|
|
xr.Print()
|
|
Else
|
|
NumeroCopias = Copias
|
|
AddHandler xr.PrintingSystem.StartPrint, AddressOf xr_StartPring
|
|
xr.Print()
|
|
End If
|
|
Else
|
|
PrintHelper.Print(xr)
|
|
'xr.PrintDialog()
|
|
End If
|
|
Catch ex As Exception
|
|
DXMessageBox.Show(ex.Message, "Error")
|
|
End Try
|
|
End Sub
|
|
|
|
Private Shared Sub xr_StartPring(sender As Object, e As PrintDocumentEventArgs)
|
|
e.PrintDocument.PrinterSettings.Copies = NumeroCopias
|
|
End Sub
|
|
|
|
|
|
End Class |