需要获取RDLC报告上的参数帧

发布于 2024-10-06 02:48:59 字数 329 浏览 6 评论 0原文

我正在构建一个 Winforms (.NET) 应用程序。

假设我有 10 个具有不同参数的 RDLC 报告。我是否需要创建 10 个屏幕(表单)来获取各个报告的参数,以便我可以执行基础数据集的 Fill 方法。

是否有任何(免费)工具可以使这项工作变得更容易。

或者我错过了一些已经存在的东西?

总而言之......我计划拥有一种带有报表查看器控件的表单,它可用于显示不同的报表,并且它可以负责收集参数和执行报表。这样我只需要传递带有报告名称的表格即可。

注意:我知道服务器报告(RDL)可以做到这一点,但我没有用于该项目的报告服务器。

请帮忙。

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

Suppose I have 10 RDLC Reports 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我纯我任性 2024-10-13 02:49:00

根据我的其他答案的评论,我不知道有任何这样的工具,因为很多报告可以有如此不同的标准,并且他们从中查询的表/列可能不实用。我已经用另一种语言完成了,我可以对诸如选择日期范围(从/到)之类的事情进行通用控制,并让它生成并返回 WHERE 子句的该部分。类似地,比如排序,有一个带有显示值的组合框,但内部键值将表示 where 子句中的 order by 子句。然后,拥有一个包含这些元素的通用用户控件容器将有助于标准化用户界面如何选择这些元素(也许还有其他常见元素)。然后在类上有一个通用的虚拟方法,例如“GetMyData()”,该控件可以根据需要为任意数量的实例/报告进行子类化,每个实例/报告都知道如何处理呈现给用户的查询组件,并且实际上获取最终输出的代表性数据。

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.

遥远的绿洲 2024-10-13 02:49:00

我实际上已经在应用程序中完成了此操作。但是,不必担心要传递哪些参数并超级重载我的报告类的构造函数对象。它只有一个“ReportViewer”实例作为我使用的对象。

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

   public MyReport()
   { InitializeComponent(); }

然后,我将公开一些公共方法,每个报告都需要一个公共方法,根据需要需要不同的参数,但如果通用则传递一个数据集,其中包含用于报告的一个或多个表。然后,我将动态循环遍历表格并添加到报表查看器控件

   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;
  }

}

现在,要实际调用它并将它们放在一起...

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

我已经剥离了一堆其他验证 try/catch 等,并剥离了特定的对象引用来自我的实际代码,但下面的模板应该会给您一个巨大的启动。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文