Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Display Various Crystal Reports 1

Status
Not open for further replies.

cupcakesrule

Programmer
Feb 6, 2007
35
US
I have multiple Crystal Reports created in my Web Project. I want the user to be able to select the report they desire and then display the up to date report. Is there anything I can do with the following statement:
Code:
CrystalReport3 crReportDocument = new CrystalReport3 ();
So that when the user selects the desired report the crReportDocument gets set to that new report. In other words is there anyway to replace the CrystalReport3 definition with a variable?
 
That's not really what I am looking for, I want to be able to create multiple Crystal Reports within the web application. There will then be a drop down list of all of the reports that have been created. When the user selects the report from the drop down list that report, 1 of the multiple that have been created, will be refreshed and displayed.
 
this is a very broad question with no 'right' answer. In it's simplist form you need a page containing a crystalreportviewer bound to a crystalreportdatasource.

* you will then need to programatically assign the user selected report to the crystalreportdatasource.
* programatically configure the report parameters.
* programatically configure the data parameters, if data is pushed to the report (dataset/table, bll objects).

what this model looks like and how to program it is completely up to you, depends on what your requirements are, and how your form(s)/control(s) interact with one another.

I have a setup similar to what you describe. I create a ListDictionary (hashtable would work too) of the information I require. essentially it's a crude interface for generating reports.

The object contains:
the report ID
the path to the report file
a list of key/value pairs for report paramters
a list of key/value pairs for data retrieval paramters (I push data to the reports).

Then I persist this information to session. call my report page. configure a ReportDocument object. remove the object from session. export the report to PDF format for viewing in the browser.

other information that my be crucial for your application is authentication, sub-report information, logging information. anything else that may vary.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Currently I am using the following code to get an updated report. All of the information is being stored in a database, is there a way to change the line in red to a report on the fly?
Code:
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
		private Database crDatabase;
		private Tables crTables;
		private CrystalDecisions.CrystalReports.Engine.Table crTable;
		private TableLogOnInfo crTableLogOnInfo;
		private ConnectionInfo crConnectionInfo = new ConnectionInfo ();
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (Session["UserID"] == null || Session["ReportToView"] == null)
			{
				Response.Redirect("WebForm2.aspx");
			}
			//ReportDocument getReport;
			//getReport = Session["ReportToView"] as ReportDocument;
			//Convert.ChangeType(Session["ReportToView"], 
			[COLOR=red]CrystalReport3 crReportDocument = new CrystalReport3 ();[/color]
			crConnectionInfo.ServerName = "*****";
			crConnectionInfo.DatabaseName = "*****";
			crConnectionInfo.UserID = "sa";
			crConnectionInfo.Password = "*****";
			crDatabase = crReportDocument.Database;
			crTables = crDatabase.Tables;
			for (int i = 0; i < crTables.Count; i++)
			{
				crTable = crTables [i];
				crTableLogOnInfo = crTable.LogOnInfo;
				crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
				crTable.ApplyLogOnInfo(crTableLogOnInfo);
				crTable.Location = "Dealer Quoter Dev.dbo." +
					crTable.Location.Substring(crTable.Location.LastIndexOf
					(".") + 1);
			}
			crReportDocument.PrintOptions.PaperSize = PaperSize.PaperA3;
			crReportDocument.RecordSelectionFormula = "{CrystalHolder.UserID}=" + Convert.ToInt32(Session["UserID"]);
			CrystalReportViewer1.ReportSource = crReportDocument; 
		}
 
Code:
ReportDocument crReportDocument = new ReportDocument();
crReportDocument.Load([full path to report])
//examples: @"C:\reports\myreport.rpt" or @"\\myserver\c$\reports\myreport.rpt"

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top