C# 多次使用RDLC子报表

C# 多次使用RDLC子报表,c#,rdlc,subreport,C#,Rdlc,Subreport,我有一份报告列出了给定storeID、fromDate和toDate的商店的税费。我想在同一父报表中多次将此报表用作子报表。例如,如果使用storeID的1,2,3,4,5,则此子报表将显示5次,第一次显示store 1的数据,第二次显示store 2的数据,以此类推 这可能吗?我发现一些论坛上,人们会问如何在一个报告中使用同一个子报告两次,但在找到内容之前,线程总是会消失。我还看到您可以使用参数,但我不确定这些参数是如何工作的(对于RDLC中的子报告来说有点新) 谢谢 如果我理解正确,您可能可

我有一份报告列出了给定storeID、fromDate和toDate的商店的税费。我想在同一父报表中多次将此报表用作子报表。例如,如果使用storeID的1,2,3,4,5,则此子报表将显示5次,第一次显示store 1的数据,第二次显示store 2的数据,以此类推

这可能吗?我发现一些论坛上,人们会问如何在一个报告中使用同一个子报告两次,但在找到内容之前,线程总是会消失。我还看到您可以使用参数,但我不确定这些参数是如何工作的(对于RDLC中的子报告来说有点新)


谢谢

如果我理解正确,您可能可以使用一个子报表,其中包含一个表,显示按存储区分组的税收。

在主报表中,使用子报表的5个实例。 更改每个子报表的(Name)属性,但保持子报表路径不变(与您之前所做的相同)

处理主报表时,根据找到的子报表的实例数多次调用方法
LocalReport\u SubReportProcessing

您将使一个全局变量保持当前存储Id,如下面的代码示例所示

    public class TaxDetailsOfStore
    {
        public int StoreId { get; set; }

        // Your other details here...
    }

    // This global property be filled for all stores before displaying the main report.
    private List<TaxDetailsOfStore> TaxDetailsOfAllStores { get; set; }

    private int _storeId = 1; // To start with.
    private const int _maxStoreId = 5;

    private void LocalReport_SubReportProcessing(object sender, SubreportProcessingEventArgs e)
    {
        string reportDataSourceName = string.Empty;
        object reportDataSourceValue = null;

        switch (e.ReportPath)
        {
            case "SubRprtTaxDetailsOfStore":
                int storeId = Convert.ToInt32(e.Parameters["storeId"].Values[0]);
                var lstTaxDetailsOfStore = TaxDetailsOfAllStores.FindAll(x => x.StoreId == storeId);

                //-------------------------------------------------------------------------------------
                // Increment the variable _storeId till reaches _maxStoreId and then back again from 1.
                _storeId = _storeId++ % _maxStoreId;
                //-------------------------------------------------------------------------------------

                reportDataSourceName = "TaxDetailsOfStoreDataSet";
                reportDataSourceValue = lstTaxDetailsOfStore;
                break;

            // Handle other sub reports like this.
            //case "SubRprtAnother1":
            //    object dsSubRprtAnother1 = null;
            //    reportDataSourceName = "AnotherDataSetName1";
            //    reportDataSourceValue = dsSubRprtAnother1;
            //    break;

            //case "SubRprtSummary":
            //    object dsSubRprtSummary = null;
            //    reportDataSourceName = "SubRprtSummaryDataSet";
            //    reportDataSourceValue = dsSubRprtSummary;
            //    break;
        }

        ReportDataSource reportDataSource = new ReportDataSource
        {
            Name = reportDataSourceName,
            Value = reportDataSourceValue
        };

        e.DataSources.Add(reportDataSource);
    }
公共类TaxDetailsOfStore
{
public int StoreId{get;set;}
//你的其他细节在这里。。。
}
//在显示主报告之前,必须为所有存储填写此全局属性。
私有列表TaxDetailsOfAllStores{get;set;}
私有int _storeId=1;//一开始
私有常量int_maxStoreId=5;
私有void LocalReport_SubReportProcessing(对象发送方,SubreportProcessingEventArgs e)
{
string reportDataSourceName=string.Empty;
对象reportDataSourceValue=null;
交换机(如ReportPath)
{
案例“SubRPRTAXdetailsofstore”:
int storeId=Convert.ToInt32(例如参数[“storeId”].Values[0]);
var lstTaxDetailsOfsStore=TaxDetailsOfAllStores.FindAll(x=>x.StoreId==StoreId);
//-------------------------------------------------------------------------------------
//递增变量_storeId,直到达到_maxStoreId,然后从1返回。
_storeId=\u storeId++%\u maxStoreId;
//-------------------------------------------------------------------------------------
reportDataSourceName=“TaxDetailsOfsStoreDataSet”;
reportDataSourceValue=lstTaxDetailsOfsStore;
打破
//像这样处理其他子报表。
//案例“SubRprtAnother1”:
//对象DSSUBRPTANOTHER1=null;
//reportDataSourceName=“AnotherDataSetName1”;
//reportDataSourceValue=DSSUBRPTANOTHER1;
//中断;
//案例“SubRprtSummary”:
//对象dsSubRprtSummary=null;
//reportDataSourceName=“subrprtsmarydataset”;
//reportDataSourceValue=DSSUBRPTSUMMARY;
//中断;
}
ReportDataSource ReportDataSource=新的ReportDataSource
{
名称=reportDataSourceName,
Value=reportDataSourceValue
};
e、 添加(reportDataSource);
}

这正是我尝试过的,但问题是,由于我使用的是本地报告,所以我不能使用参数,因此如果我有一个SuperportProcessingEventHandler,它将为表中的每个子报告处理相同的存储。。。如果我使用“foreach store”,那么它将只使用最后一个store selecteds数据源。在.LocalReport.SubreportProcessing中,您必须传递整个数据集,但您可以通过在子报表属性中设置参数对其进行过滤。但是,只有当我有一组子报表时,这难道不起作用吗?我可能有一家商店,或者8家,或者任何数字。如果我使用参数,我不需要指定哪个子报表使用哪个storeID吗?我不能说第一个子报表使用第一个StoreID,第二个子报表使用第二个StoreID,等等?您可以在运行时设置子报表参数。我又读了一遍你的问题:也许你可以简单地用一个按商店分组的Tablix来解决你的问题,而不用子报表。是的,这看起来似乎是我唯一的选择了。。。这在这份报告中并不重要,但如果我能做到的话,这对以后的报告会有很大帮助。不过谢谢你的帮助,如果我有其他想法,我会更新这个。