Site Feedback Thread

2 posts

Oracle, Crystal Reports and visual Studio 2010

Back to Forum: Site Feedback
  • kevin4

    Can anyone help me with the code for this application?

    My aim is to display reports, created with crystal reports, on a webpage after users enter a date range(generated by a sql form). The data for the report is stored in a query in an Oracle database.

    Note:

    1.  the report is expected to generate new data based on the date range entered or if the data in the tables, that were used to create the query, changes.

    2.  the report is activated by a button click on the web form.

     

  • Hometoy

    The date ranges should be made in Crystal Reports as parameters and the Record Selector to apply these parameters as a filter for your records.

    Once you have the Crystal Report so you can run it, apply your criteria and get back what you want then you can set up the display page.

    I use 2 pages; one to collect the parameters and one to display the page.

    The process I use, as an overview, is

    1. Create the object
    2. Create and apply the parameters
    3. Export the report to a temporary location (as a .pdf)
    4. Display the report to the user
    5. Remove the .pdf file

    Imports CrystalDecisions.Shared
    Imports CrystalDecisions.CrystalReports.Engine
    Dim crpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    
    Dim paramFields As New CrystalDecisions.Shared.ParameterFields
    Dim paramField As New CrystalDecisions.Shared.ParameterField
    Dim dVal As New CrystalDecisions.Shared.ParameterDiscreteValue
    
    ' I use a session variable to store the object
    crpt.Load(objReport.ReportFullName, OpenReportMethod.OpenReportByDefault)
    
    'Parameters
    Dim pvParamValues As ParameterValues
    Dim dvDiscreteValue As New ParameterDiscreteValue
    
    pvParamValues = crpt.DataDefinition.ParameterFields(<<parametername>>).CurrentValues
    dvDiscreteValue.Value = <<parametervalue>>
    pvParamValues.Add(dvDiscreteValue)
    crpt.DataDefinition.ParameterFields(<<paramtername>>).ApplyCurrentValues(pvParamValues)
    
    'Log in
    Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
    Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
    For Each myTable In crpt.Database.Tables
        myLogin = myTable.LogOnInfo
        myLogin.ConnectionInfo.ServerName=<<servername>>
        myLogin.ConnectionInfo.DatabaseName=<<database>>
        myLogin.ConnectionInfo.Password=<<password>>
        myLogin.ConnectionInfo.UserId=<<userid>>
        myTable.ApplyLogOnInfo(myLogin)
    Next
    
    'Export
    Dim crExportOptions As New ExportOptions
    Dim crDiskFileDestinationOptios As New DiskFileDestinationOptions
    Dim fname As String = ""
    Dim gFileId As New Guid
    
    fname=<<wheretosavefile>> + gFileId.ToString + ".pdf"
    crDiskFileDestinationOptions.DiskFileName=fname
    
    crExportOptions = crpt.ExportOptions
    crpt.ExportOptions.DestinationOptions = crDiskFileDestinationOptios
    crpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
    crpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
    
    crpt.Export()
    
    'Display and Cleanup (comment out to debug)
    Response.ClearContent()
    Response.ClearHeaders()
    Response.ContentType = "application/pdf"
    Response.WriteFile(fname)    'writes out PDF if created
    
    'Cleanup
    Response.Flush()
    Response.Close()
    System.IO.File.Delete(fname)
    
    
    
    

    Unfortunately I have to leave until tomorrow. Have fun!

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.