5

我有一个 RDLC 报告,其中包含一些子报告。我正在使用 LocalReport_SubreportProcessing 事件处理所有这些子报告。现在,在这些子报表中,一个报表又具有它的子报表。我不知道如何处理这个子报告?

对于主要报告,我添加了一个事件。

viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
    viewer.LocalReport.Refresh();

事件代码

void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{      
    if (e.ReportPath == "rpt_PSRUserHoursDetail")
    {
        //Code
    }
    else if (e.ReportPath == "rpt_BEnchMiscDetails")
    {

        System.Data.DataTable dtBenchMiscSubReport =DataTable
        ReportDataSource subRptSource = new ReportDataSource("DataSource", dtBenchMiscSubReport);
        e.DataSources.Add(subRptSource);

        (sender as Microsoft.Reporting.WebForms.LocalReport).SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessingBench);

        CommonHelper.DisposeOf(dtBenchMiscSubReport);
    }
}

子报表的子报表处理代码如下:

void LocalReport_SubreportProcessingBench(object sender, SubreportProcessingEventArgs e)
{
    int intProjectID = 0;
    int int_UserID = 0;

    if (e.Parameters.Count > 0 && e.ReportPath=="SubMiscellaneousTaskReport")
    {
        //get parameter

    }

    DateTime dtCurrentMonth = clsCheckDBNull.ToDate(string.Format("{0}-{1}-{2}", drpYear.SelectedValue, drpMonth.SelectedValue, "01"));
    if (e.ReportPath == "SubMiscellaneousTaskReport")
    {
        System.Data.DataTable dt = DataTable
        ReportDataSource subRptSource = new ReportDataSource("Dataset1", dt);
        e.DataSources.Add(subRptSource);
    }
}
4

2 回答 2

1

@chirag Fanse:子报告本身是一份报告。当您有子报告(例如 B)的子报告(例如 A)时,现在 B 将成为您的主报告,A 将成为子报告。所以你可以检查子报告

if (e.ReportPath == "A")

其余的事情都是一样的。

于 2013-07-18T06:18:37.723 回答
1

我找到了将参数传递给子报表的子报表的方法:

public partial class FormReportViewerAsnDetailed : Form
{
    private readonly int PoID;

    public FormReportViewerAsnDetailed(int PoID)
    {
        this.PoID = PoID;
        InitializeComponent();
        reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", bindingSource1));
        reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", bindingSource2));
        reportViewer1.LocalReport.SubreportProcessing += LocalReport_SubreportProcessing;
    }

    private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
    {
        if (e.Parameters.Any(k => k.Name == "AsnID")) //is it asn subreport?
        {
            var asn = int.Parse(e.Parameters["AsnID"].Values.First());

            asn_Details_ReportTableAdapter1.Fill(viewAsnDetailsDataSet1.Asn_Details_Report, asn);
            e.DataSources.Add(new ReportDataSource("DataSet2",
                new BindingSource(viewAsnDetailsDataSet1, "Asn_Details_Report")));

            inbound_By_AsnTableAdapter1.Fill(inboundsReportDataSet1.Inbound_By_Asn, asn);
            e.DataSources.Add(new ReportDataSource("DataSet1",
                new BindingSource(inboundsReportDataSet1, "Inbound_By_Asn")));
        }
        else // subreport of subreport
        {
            inbound_Items_ReportTableAdapter1.Fill(inboundItemsReportDataSet1.Inbound_Items_Report,
                int.Parse(e.Parameters["InboundID"].Values.First()));
            BindingSource src = new BindingSource(inboundItemsReportDataSet1, "Inbound_Items_Report");
            e.DataSources.Add(new ReportDataSource("DataSet1", src));
        }
    }

    private void FormReportViewer_Load(object sender, EventArgs e)
    {
        this.purchase_Order_Details_ReportTableAdapter1.Fill(
            purchaseOrderDetialsReport1.Purchase_Order_Details_Report, PoID);
        asn_Select_By_POTableAdapter1.Fill(asnDetailedList1.Asn_Select_By_PO, PoID);
        reportViewer1.LocalReport.SetParameters(new ReportParameter("po", PoID.ToString()));
        this.reportViewer1.RefreshReport();
    }
}

在这里,我有两个用于主报告的数据集。它们在构造函数方法中传递,并与主报告参数一起填写在加载方法中。

在子报表处理中,您需要发现谁在调用子报表:subreport 还是 subreport-of-subreport?然后,您需要将数据源传递给每个。

于 2016-06-09T12:33:41.283 回答