开发者

Need to Get Parameters Frame on RDLC Report

I'm building a Winforms (.NET) application.

Suppose I have 10 RDLC Repo开发者_Go百科rts with different parameters. Do I need to create 10 Screens (Forms) to get parameters for respective reports so that I can execute the underlying DataSet's Fill method.

Is there any (free) tool that is available to make this job easier.

Or am I missing something, that is out there already ?

To sum up... I'm planning to have one form with reportviewer control which can be used to show different reports and it can take care of collecting the params and executing the reports. So that all I need to pass the form with just the report name.

Note: I know a server report (RDL) could do this, but I dont have a Report Server for this project.

Please help.


Per comment from my other answer, I don't know of any such tool as so many reports can have such diverse criteria and table/columns they query from it might not be practical. I have done in another language where I would have common controls for things like picking date range (from/to), and having it generate and return that portion of my WHERE clause. Similarly, such as sorting, having a combobox built with a display value, but the internal key value would represent the order by clause in the where clause. Then, having a common user control container with these elements would help standardize how the user interface would be able to pick these (and maybe others that are common). Then have a generic virtual method on the class, such as "GetMyData()", the control can be sub-classed for as many instances / reports as you need, each of them knowing how to handle the querying components presented to the user and actually getting the representative data for final output.


I've actually done this in an app. However, Instead of worrying about which parameters to pass and super overloading a Constructor object of my reporting class. It just has an instance of the "ReportViewer" as an object on it that I work with.

public partial class MyReport : Form
{
   protected ReportViewer reportViewer = new ReportViewer();

   public MyReport()
   { InitializeComponent(); }

Then, I'll expose some public methods, one for each report that requires different parameters as needed, but if generic being passed a data set with one or more tables within it for the report. I'll then dynamically cycle through the tables and add to the report viewer control

   public Boolean GenerateCommonReport( DataSet oDS, 
           String NameOfReport, String[] SubReports)
   {
      // Set Processing Mode.
      reportViewer.ProcessingMode = ProcessingMode.Local;

      reportViewer.LocalReport.LoadReportDefinition(GetRDLC( NameOfReport ));

      // I've actually an extended version that includes subreports with an array
      // of separate .RDLC file names in case the report is nested... if so, those
      // would need to be added too.
      if( ! (SubReports == null ))
      {
         // the hitch here, is that in my case, any sub-reports are named by the same
         // name as the .RDLC in the report just in case thee's any object renaming 
         // when you add one sub-report into the main report.  Such as when adding 
         // textboxes, it will create textbox1, textbox2, textbox3, etc...  So, you
         // may have to wiggle with this some to match the actual name of the sub-report
         // object in your main report.
         foreach( String ar in SubReports )
            reportViewer.LocalReport.LoadSubreportDefinition( ar, GetRDLC( ar ));
      }

      // Next load the dataset into the report before finally showing.
      foreach (DataTable oTbl in oDS.Tables)
         // likewise with the datasets.  If you look at your RDLC of the schema's
         // used, it will reference an outer Dataset name, then force an "_" before
         // the actual table it uses WITHIN that dataset.  Don't worry, internally 
         // it splits it up and finds correct correlation.
         reportViewer.LocalReport.DataSources.Add(
                new ReportDataSource(oDS.DataSetName + "_" + oTbl.TableName, oTbl));


      // Finally, add the report viewer control to your displaying form control
      reportViewer.Dock = DockStyle.Fill;
      this.Controls.Add(reportViewer);

      reportViewer.SetDisplayMode(DisplayMode.PrintLayout);
      reportViewer.RefreshReport();

      // This is actually showing your form as a modal dialog window to the user
      this.ShowDialog();
  }


  // get embedded reports directly from this DLL/project
  private Stream GetRDLC(String RptRDLC)
  {
     // Ex: we want the report "FirstReport" within the "MyReports.dll" 
     // assembly "MyReports.FirstReport.rdlc"
     Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "MyReports." + RptRDLC + ".rdlc" );
     return stream;
  }

}

Now, to actually CALL this and put it all together...

DataSet oDS = YourObject.HoweverYouQueryToGetADataset();
MyReport oRpt = new MyReport();
oRpt.GenerateCommonReport( oDS, "MyFirstReport", null );

I've stripped a bunch of other validation try/catch, etc and stripped specific object references from my actual code, but the template below should give you a tremendous jumpstart.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜