Skip to Content
0
Former Member
May 21, 2007 at 10:07 PM

Help with report persistence in asp.net

43 Views

This is my first crystal report for asp.net 2 and I'm having trouble with persistence of it. I have a crystalreportviewer object and crystalreportsource with an external report file attached as the source. The first record of the report shows fine, but when I click on the page next button I get prompted for parameters. I then realized I need to persist the parameters so they are reloaded each time the report is navigated. Now all that happens after the first report is the parameters of the report are displayed as they should (title, prepared by, date,etc.), but the rest of the entire report and subreports are nonexistent. I cant figure out how to properly persist the actual report. Any help would be great. Thanks. Do I persist the report viewer or report document. Attached is the code that would matter I think:

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

Dim str As String = ""

Dim decryptStr As String = ""

Dim es As New Encryption64

If Not Page.IsPostBack Then

myConnectionInfo = New ConnectionInfostr = Request.QueryString("x")

decryptStr = es.DecryptQueryString(str)

End If

LoadSettings(decryptStr)

End Sub

Private Sub LoadSettings(ByVal query As String)

Dim records() As String

Dim suppliers As String = ""

Dim userid As String = ""

If query <> "" Then

records = query.Split("^")

rptKi = records(0)

rptBegDate = Format(CDate(records(1)), "MM/dd/yyyy")rptEndDate = Format(CDate(records(2)), "MM/dd/yyyy")

rptPreparedBy = records(3)

userid = records(4)

Session("Params") = rptKi & "" & rptPreparedBy & "" & CDate(rptBegDate.ToString("d")) & "^" & CDate(rptEndDate.ToString("d")) Session("USERID") = userid

Else

If Not IsNothing(Session("Params")) Then

records = Session("Params").ToString.Split("^")

rptKi = records(0)

rptBegDate = Format(CDate(records(2)), "MM/dd/yyyy")rptEndDate = Format(CDate(records(3)), "MM/dd/yyyy")

rptPreparedBy = records(1)

userid = Session("USERID").ToString

End If

End If

LoadReport(rptKi, rptBegDate, rptEndDate, rptPreparedBy)

End Sub

Public Sub LoadReport(ByVal reportKi As Integer, _

ByVal begDate As Date, ByVal endDate As Date, _

ByVal preparedBy As String)

rptKi = reportKi

rptBegDate = begDate

rptEndDate = endDate

rptPreparedBy = preparedBy

Try

ConfigureCrystalReports()

Catch ex As Exception MsgBox("Error loading data for report. Please contact IT Dept.", MsgBoxStyle.Critical, "Error")

Finally

End Try

End Sub

rivate Sub ConfigureCrystalReports() Dim pFields As New ParameterFields()

Dim pField As New ParameterField()

Dim disVal As New ParameterDiscreteValue()

Dim params() As String

Dim edate As Date

Dim bdate As Date

If Not IsNothing(Session("Params")) Then

params = Session("Params").ToString.Split("^")

edate = params(3)

bdate = params(2)

Else

edate = rptEndDate

bdate = rptBegDate

End If

myConnectionInfo.DatabaseName = ...

myConnectionInfo.UserID = ...

myConnectionInfo.Password = ...

myConnectionInfo.ServerName = ...

'setup db connection for report

If Not Page.IsPostBack Then

LoadDataSources()

crs.ReportDocument.SetDataSource(dsOcc)

crs.ReportDocument.Subreports("FailOcc").SetDataSource(dsFailOcc)

crs.ReportDocument.Subreports("IndexByFailure").SetDataSource(dsIndexFail)crs.ReportDocument.Subreports("FailByRank").SetDataSource(dsIndexFail) crs.ReportDocument.Subreports("FailureType").SetDataSource(dsFailureType)crs.ReportDocument.Subreports("SupplierRank").SetDataSource(dsSupplierRanking) 'crs.ReportDocument.Subreports("ComRank").SetDataSource(dsSupplierCommodRank)crs.ReportDocument.Subreports("ResponseTime").SetDataSource(dsResponseTime)

'Load parameters for report

'SetDBLogonForReport(myConnectionInfo)SetParameters()

ApplyParams()

End If

End Sub

Private Sub SetParameters()

Dim params() As String

If Not Page.IsPostBack Then

Parameters("kiPerformance") = rptKi

Parameters("PreparedBy") = rptPreparedByParameters(

"kiBegRange") = CDate(rptBegDate.ToString("d"))

Parameters("kiEndRange") = CDate(rptEndDate.ToString("d"))

Else

If Not IsNothing(Session("Params")) Then

params = Session("Params").ToString.Split("^")

Parameters("kiPerformance") = params(0)

Parameters("PreparedBy") = params(1)

Parameters("kiBegRange") = Format(CDate(params(2)), "MM/dd/yyyy")

Parameters("kiEndRange") = Format(CDate(params(3)), "MM/dd/yyyy")

End If

End If

End Sub

'Sets the parameter fields of the report and pushes down parameters to subreports where needed.

Public Function ApplyParams()

Dim rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument

rpt = crs.ReportDocument

If (rpt Is Nothing OrElse _Parameters Is Nothing) Then Return False

Dim crParameterFieldDefinitions As ParameterFieldDefinitions = _

rpt.DataDefinition.ParameterFields

If (crParameterFieldDefinitions Is Nothing) Then Return False

For Each crParameterFieldDefinition As ParameterFieldDefinition In crParameterFieldDefinitions

'IsLInked has known bug issue, so checking for Pm- instead in parameter name

'for linked params

If ((Not crParameterFieldDefinition.Name.LastIndexOf("Pm-") = 0) And _

_Parameters.ContainsKey(crParameterFieldDefinition.Name)) Then

Dim crParameterValues As ParameterValues = _

crParameterFieldDefinition.CurrentValues

If Not (crParameterValues Is Nothing) Then

Dim crParameterDiscreteValue As New ParameterDiscreteValue

crParameterDiscreteValue.Value = _

_Parameters.Item(crParameterFieldDefinition.Name)

crParameterValues.Add(crParameterDiscreteValue)

'Console.WriteLine(crParameterFieldDefinition.ReportName & ": " & crParameterFieldDefinition.Name & ": " & crParameterDiscreteValue.Value)

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

End If

End If

Next

crv.ReportSource = rpt

Return Nothing

End Function