2010-12-06 30 views
1

我正在構建Winforms(.NET)應用程序。需要在RDLC報告上獲取參數幀

假設我有10個具有不同參數的RDLC報告。我是否需要創建10個屏幕(窗體)來獲取各個報告的參數,以便我可以執行基礎DataSet的填充方法。

是否有任何(免費)工具可用於使這項工作更容易。

或者我錯過了一些東西,那已經在那裏了?

總結...我計劃使用reportviewer控件的一種形式,它可以用來顯示不同的報告,它可以負責收集參數並執行報告。所以我需要通過報表名稱來傳遞表單。

注:我知道一個服務器報告(RDL)可以做到這一點,但我沒有這個項目的報告服務器。

請幫忙。

回答

0

從我的其他答案的評論我不知道任何這樣的工具,因爲許多報告可以有這樣不同的標準和他們查詢表/列可能不實際。我在另一種語言中完成了一些操作,例如選擇日期範圍(從/到),並讓它生成並返回WHERE子句的那部分。類似地,如排序,使用顯示值構建組合框,但內部鍵值將表示where子句中的order by子句。然後,擁有一個包含這些元素的公共用戶控件容器將有助於標準化用戶界面如何挑選這些元素(也可能是其他常見元素)。然後在類上有一個通用的虛擬方法,如「GetMyData()」,控件可以根據需要分類爲儘可能多的實例/報告,每個人都知道如何處理呈現給用戶的查詢組件,實際獲得最終產出的代表性數據。

+0

謝謝......我會給你的方式嘗試... – 2011-01-24 05:27:25

0

我已經在應用程序中實際完成了此操作。但是,不要擔心要傳遞哪些參數,並且會超出我的報告類的構造函數對象。它只是一個「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等,並從我的實際代碼中剝離了特定的對象引用,但下面的模板應該會給你一個巨大的啓動。

+0

@DRapp。感謝您的代碼..但我正在尋找一些工具來生成TextBoxes,ComboBox,DateTime選擇器,用於生成傳遞給報告的DataSet所需的參數... – 2011-01-20 06:36:39