2010-12-06 24 views
1

私はWinforms(.NET)アプリケーションを構築しています。RDLCレポートのパラメータフレームを取得する必要があります

異なるパラメータを持つ10個のRDLCレポートがあるとします。基になるDataSetのFillメソッドを実行できるように、それぞれのレポートのパラメータを取得するために10個のScreens(Forms)を作成する必要がありますか?

この作業をより簡単にするツールがありますか?

私は何かが不足していますか、それは既にありますか?

要約...私は、さまざまなレポートを表示するために使用できるreportviewerコントロールを持つ1つのフォームを用意する予定で、パラメータを収集してレポートを実行することができます。私はレポート名だけでフォームを渡す必要があります。

注:私はサーバーレポート(RDL)がこれを行うことができると知っていますが、このプロジェクトのレポートサーバーはありません。

助けてください。

答えて

0

私の他の回答からのコメントによると、多くのレポートでそうした多様な基準やテーブル/カラムを持つことができるようなツールは実用的でない可能性があります。私は日付範囲(from/to)を選び、それを生成してWHERE節のその部分を返すようなものに共通のコントロールを持つ別の言語で行っています。同様に、並べ替えなどのコンボボックスは表示値で作成されますが、内部キー値はwhere節のorder by句を表します。次に、これらの要素を持つ共通のユーザーコントロールコンテナを持つことは、ユーザーインターフェイスがこれらを選択できるようにする方法を標準化するのに役立ちます。次に、GetMyData()などのクラスに汎用の仮想メソッドを持たせ、必要な数のインスタンス/レポートをサブクラス化することができます。それぞれは、ユーザーに提示されるクエリコンポーネントをどのように扱うかを知っています。実際に最終出力のための代表的なデータを得る。

+0

ありがとう...私はあなたの方法は試してみてください... –

0

私は実際にアプリでこれを実行しました。ただし、どのパラメータを渡すか心配するのではなく、自分のレポートクラスのConstructorオブジェクトをスーパーオーバーロードするのではなく、それは私が扱っているオブジェクトとして "ReportViewer"のインスタンスを持っています。

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

    public MyReport() 
    { InitializeComponent(); } 

その後、私はいくつかのパブリックメソッド、必要に応じて異なるパラメータを必要とする各レポートの1を公開しますが、一般的なビーイングは、レポートのためにその中の1つまたは複数のテーブルで設定されたデータを渡された場合。私は、テーブルを通じて動的サイクルとは...実際にこれを呼び出し、すべて一緒にそれを置くために、レポートビューアーコントロール

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

Iを追加しますtry/catchなどの他のバリデーションを取り除き、実際のコードから特定のオブジェクト参照を削除しましたが、下のテンプレートはすばらしいジャンプスタートを与えるはずです。

+0

@DRapp。コードをありがとう。しかし、レポートに渡すDataSetを生成するために必要なパラメータのTextBoxes、ComboBox、DateTimeピッカーを生成するツールを探しています... –

関連する問題