Click to See Complete Forum and Search --> : Is it safe to pass ParameterFields objects? How can I check it's content?


JamesMitchell
December 5th, 2006, 07:15 AM
I am having problems displaying a Report.

I have a viewer which used to take a CrystalContrl.CryRepControl as its arguement but I have found that there is something of a memory leak in this. I have found code to efectively manually free the memory if I use a ReportDocument but I need to change the way my report viewer works.

I wanted to pass in the location of the rpt file and the parameter fields but the method I've chosen seems a bit hit and miss. I seem to be able to generate my Sales Ledger but when I try to generate the Purchase Ledger it asks me to put the parameters in, even though I am using the same method to enter them...

Code to call the viewer:

Dim ParamFields As New CrystalDecisions.Shared.ParameterFields
Dim ParamField As New CrystalDecisions.Shared.ParameterField
Dim paramDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
ParamField.ParameterFieldName = "@ReservationID"
paramDiscreteValue.Value = reservation.ReservationId
ParamField.CurrentValues.Add(paramDiscreteValue)
ParamFields.Add(ParamField)
ParamField.ParameterFieldName = "ChargeBackFee"
paramDiscreteValue.Value = ChargeFee
ParamField.CurrentValues.Add(paramDiscreteValue)
ParamFields.Add(ParamField)
ParamField.ParameterFieldName = "BookingFee"
paramDiscreteValue.Value = BookingFee
ParamField.CurrentValues.Add(paramDiscreteValue)
ParamFields.Add(ParamField)
If SalesLedger Then
sbStatus.Text = "Generating Sales Ledger"
pbProgress.Value = 1
Dim ReportFileName As String
If reservation.Personnel.CustomerId = 279 Then
' The customer is ABC
ReportFileName = "\\ReportMachine\" & "ABCHotelAccountsSheet.rpt"
Else
ReportFileName = "\\ReportMachine\" & "NewHotelAccountsSheet.rpt"
End If
sbStatus.Text = "Setting Sales Ledger Parameters"
pbProgress.Value = 2
sbStatus.Text = "Launching Sales Ledger Viewer"
pbProgress.Value = 3
Dim viewer As New ReportViewer(ReportFileName, ParamFields)
viewer.ShowDialog()
End If
If PurchaseLedger Then
sbStatus.Text = "Generating Purchase Ledger"
pbProgress.Value = 1 + bothDiff
Dim ReportFileName As String
ReportFileName = "\\ReportMachine\" & "PurchaseLedgerSheet.rpt"
sbStatus.Text = "Setting Purchase Ledger Parameters"
pbProgress.Value = 2 + bothDiff
sbStatus.Text = "Launching Purchase Ledger Viewer"
pbProgress.Value = 3 + bothDiff
Dim viewer As New ReportViewer(ReportFileName, ParamFields)
viewer.ShowDialog()
End If

Viewer New call:

Public Sub New(ByVal docstring As String, ByVal pf As CrystalDecisions.Shared.ParameterFields)

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
ControlNotDoc = False
rdReportDocument = New ReportDocument
rdReportDocument.Load(docstring)
myParameterFields = pf
End Sub


Is it safe to pass ParameterFields ByVal or ByRef (I've tried both)
How could I display the parameter fields and values of pf to check this?

Thanks in advance for any advice anyone may be able to give me.