This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
ReportService.vb
76 lines (59 loc) · 2.59 KB
/
ReportService.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Reflection
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Parameters
Namespace HostApp
Public Class ReportService
Implements IReportService
Public Function GetReportNames() As String() Implements IReportService.GetReportNames
Dim types() As Type = System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
Dim reportTypes As New List(Of String)()
For i As Integer = 0 To types.Length - 1
If GetType(XtraReport).IsAssignableFrom(types(i)) Then
reportTypes.Add(types(i).FullName)
End If
Next i
Return reportTypes.ToArray()
End Function
Public Function GetReportLayout(ByVal reportName As String) As Byte() Implements IReportService.GetReportLayout
Dim report As XtraReport = CreateReportByName(reportName)
Dim memoryStream As New MemoryStream()
report.SaveLayout(memoryStream)
Return memoryStream.ToArray()
End Function
Public Function GetReportDocument(ByVal reportName As String) As Byte() Implements IReportService.GetReportDocument
Dim report As XtraReport = CreateReportByName(reportName)
Dim memoryStream As New MemoryStream()
' Disable report parameters' visibility to prevent the 'Parameters' dialog from popping up in the WCF host process
For i As Integer = 0 To report.Parameters.Count - 1
report.Parameters(i).Visible = False
Next i
report.CreateDocument()
report.PrintingSystem.SaveDocument(memoryStream)
Return memoryStream.ToArray()
End Function
Public Function GetParametrizedReportDocument(ByVal reportName As String, ByVal parameters() As ReportParameterInfo) As Byte() Implements IReportService.GetParametrizedReportDocument
Dim report As XtraReport = CreateReportByName(reportName)
Dim memoryStream As New MemoryStream()
' Disable report parameters' visibility to prevent the 'Parameters' dialog from popping up in the WCF host process
For i As Integer = 0 To report.Parameters.Count - 1
report.Parameters(i).Visible = False
Next i
For i As Integer = 0 To parameters.Length - 1
Dim repPar As Parameter = report.Parameters(parameters(i).Name)
If repPar IsNot Nothing Then
repPar.Value = parameters(i).Value
End If
Next i
report.CreateDocument()
report.PrintingSystem.SaveDocument(memoryStream)
Return memoryStream.ToArray()
End Function
Private Function CreateReportByName(ByVal reportName As String) As XtraReport
Return CType(Activator.CreateInstance(Nothing, reportName).Unwrap(), XtraReport)
End Function
End Class
End Namespace