You're basically wanting to create a ReportingFramework ... where you can
dynamically add in new CR's.
First check this out:
12/1/2005
Understanding the Simple Factory Pattern
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!126.entry
Look especially at "Reflection"
You need to code to house "how am I going to show this report?".
public class ReportViewArgs : System.EventArgs
-- ReportAssembly (string)
--ReportFullyQualifiedObjectName (string)
--SourceDataSet (DataSet)
If you do this, you can create what you want.
HOWEVER, you will need to **abandon** writing reports which talk directly to
the database. (which is a good idea of its own right), and go to a dataset
model.
Read this post:
http://groups.google.com/group/micr...stal+Reports+CR+sloan&rnum=1#d9059b979636e53e
Read this article:
http://support.businessobjects.com/communityCS/TechnicalPapers/rtm_reportingoffadonetdatasets.pdf
Here is your code:
private void Go(ReportViewArgs args)
{
CrystalReport rpt = this.LoadUsingReflectionTheReport (args ) ;
rpt.SetDataSource (args.SourceDataSet);
CrystalReportViewer1.ReportSource = rpt;
}
private CrystalReport LoadUsingReflectionTheReport ( ReportViewArgs args )
{
//use the blog code to figure out how to reflectively create your CR
object.
//
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!126.entry
return rpt;
}
Here is mocked example:
ReportViewArgs : System.EventArgs
-- ReportAssembly (string)
--ReportFullyQualifiedObjectName (string)
--SourceDataSet (DataSet)
ReportViewArgs args = new ReportViewArgs ();
args.ReportAssembly "MyReports";// usually you'll have a file called
MyReports.dll, which is a net assembly with your CR defs in it
args.ReportFullyQualifiedObjectName "MyReports.EmployeeSalariesReports";
//full name of the objects, including namespaces
args.SourceDataSet = DAL.SomeMethodToGetTheDataSet();
//then call it
X.Go (args);
If you want to be able to add in reports later, on the fly, this is a good
architecture.
How do I know? I've already done one of these.
Go with datasets with Crystal Reports. And months later when you decide CR
sucks and you want something else, you still have the datasets, and not a
bunch of hidden CR code that you can't reuse.