Skip to content

Instantly share code, notes, and snippets.

@feliperomero3
Created October 21, 2016 14:23
Show Gist options
  • Save feliperomero3/813659807a20e23f30170003582bf5ae to your computer and use it in GitHub Desktop.
Save feliperomero3/813659807a20e23f30170003582bf5ae to your computer and use it in GitHub Desktop.
Helper class to load Crystal Report's report
Imports CrystalDecisions.CrystalReports.Engine
Imports SAPBusinessObjects.WPF.Viewer
Imports CrystalDecisions.Shared
Public Class ReportHelper
Private _pageTitle As String
Private _reportPage As Page
Private _reportViewer As CrystalReportsViewer
Private _reportFilePath As String
Private _report As ReportDocument
Private _parameters As Dictionary(Of String, String)
Public Property PageTitle As String
Get
Return _pageTitle
End Get
Set(value As String)
_pageTitle = value
End Set
End Property
Public Property ReportPage As Page
Get
Return _reportPage
End Get
Set(ByVal value As Page)
_reportPage = value
End Set
End Property
Public Property ReportFilePath As String
Get
Return _reportFilePath
End Get
Set(ByVal value As String)
_reportFilePath = value
End Set
End Property
Public Property Report As ReportDocument
Get
Return _report
End Get
Set(ByVal value As ReportDocument)
_report = value
End Set
End Property
Public Property Parameters As Dictionary(Of String, String)
Get
Return _parameters
End Get
Set(value As Dictionary(Of String, String))
_parameters = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(viewer As CrystalReportsViewer, filePath As String, _
parameters As Dictionary(Of String, String))
_reportViewer = viewer
_reportFilePath = filePath
_report = New ReportDocument()
_parameters = parameters
End Sub
Public Sub New(title As String, viewer As CrystalReportsViewer, filePath As String)
_pageTitle = title
_reportViewer = viewer
_reportFilePath = filePath
_report = New ReportDocument()
End Sub
Public Sub LoadReport()
_report.Load(_reportFilePath)
If _parameters.Count > 0 Then
Dim parameterName As String
Dim parameterValue As String
For Each param As KeyValuePair(Of String, String) In _parameters
parameterName = String.Format("@{0}", param.Key)
parameterValue = param.Value
_report.SetParameterValue(parameterName, parameterValue)
Next
End If
_reportViewer.ViewerCore.ReportSource = _report
_reportViewer.ShowToggleSidePanelButton = False
_reportViewer.ShowRefreshButton = False
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment