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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Interface for different Reports

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
Hi Guys,
I'm developing a web site that allows clients to print from a variety of reports. I may have about 15 different reports, and based on what the client selects, only one of them is displayed.

As you know, when you create a Report, the Crystal Reports engine creates a class for such report. At run time, what I do is I (1)instantiate objects of the appropriate report type (based on what the user selects), (2) set a couple of its properties based on what the client has selected, and (3) assign the object to the ReportViewer so that clients can view the report. Since I have 15 different reports, the code I have to write is very lengthy and inefficient.
Code:
[COLOR=green]// Create a varible for each report[/color]
ReportType1 rpt1;
ReportType2 rpt2;
ReportType3 rpt3;
[COLOR=green]// ... 
// All the way to 15 or more

// Now see which report the user wants[/color]
if (selectedRprt == 1)
   rpt1 = [COLOR=blue]new[/color] ReportType1();
[COLOR=green]   // Do other stuff[/color]
else if (selectedRprt == 2)
   rpt2 = [COLOR=blue]new[/color] ReportType2();
[COLOR=green]   // Do other stuff[/color]
else if [COLOR=green]// and on and on and on...[/color]

It's a nightmare!!! I know I could use a switch statement instead of all the if's above but that's not the issue. I was hoping to see if I could create an interface which all my reports could implement so that the above code could be reduced. Can anybody tell me how to do this?

Thanks!

JC

We don't see things as they are; we see them as we are. - Anais Nin
 
Any one?

JC

We don't see things as they are; we see them as we are. - Anais Nin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top