使用 C# 创建具有 3 个或更多级别的报告
Create a report with 3 or more levels with c#
public class ClassA{
public string Property1 { get; set; }
public string Property2 { get; set; }
List<ClassB> ListClassB { get; set; }
List<ClassC> ListClassC { get; set; }
}
public class ClassB{
public string Property3 { get; set; }
public string Property4 { get; set; }
List<ClassD> ListClassD { get; set; }
}
public class ClassC{
public string Property5 { get; set; }
public string Property6 { get; set; }
public string Property7 { get; set; }
}
public class ClassD{
public string Property8 { get; set; }
public string Property9 { get; set; }
public string Property10 { get; set; }
}
大家好,
这里的问题是我需要使用来自结构类似于 ClassA
的对象的 .rdlc
报告来创建报告。目前,我只能创建一个 'master-detail' 报告,只考虑 ClassA
和 ClassB
的属性
这是通过以下来源实现的:
https://www.c-sharpcorner.com/article/rdlc-subreport-using-c-sharp-and-wpf/
https://www.youtube.com/watch?v=2-YkNo1Os3Y
但是现在,我无法使用相同的方法包含来自 ClassC
的数据,因为无法为第 3 级设置数据源。
始终欢迎任何解决此问题的指导或来源。
杰西蒙
更新
我制作了一个快速的小型原型,它实现了一个具有两个级别的报告。对于第 2 级,我们唯一需要做的就是实现 SubreportProcessing
事件。这是代码。
private void LoadApplicationsCatalog()
{
using (IdentityDataContext context = new IdentityDataContext())
{
this.reportViewer1.LocalReport.DataSources.Clear();
var applicationsCatalog = context.spGetApplicationsCatalog().Select(a => new { a.IdentityApplicationCatalogId, a.Name, a.IdentityApplicationId }).ToList();
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ApplicationCatalog", applicationsCatalog));
this.reportViewer1.LocalReport.SubreportProcessing += LocalReport_SubreportProcessing;
this.reportViewer1.Refresh();
this.reportViewer1.RefreshReport();
}
}
private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
int identityApplicationId = Convert.ToInt32(e.Parameters[0].Values[0]);
using (IdentityDataContext context = new IdentityDataContext())
{
var applications = context.IdentityApplications.Where(a => a.IdentityApplicationId == identityApplicationId).ToList();
ReportDataSource datasource = new ReportDataSource("Application",applications);
e.DataSources.Add(datasource);
}
var applicationCatalogReport = (LocalReport)sender;
}
不幸的是,我还没有找到填充第三级数据源的方法。
几天后,我发现了这个 How to process subreport of a subreport in rdlc? 它帮助我解决了创建具有 3 个或更多级别的报告的问题。
public class ClassA{
public string Property1 { get; set; }
public string Property2 { get; set; }
List<ClassB> ListClassB { get; set; }
List<ClassC> ListClassC { get; set; }
}
public class ClassB{
public string Property3 { get; set; }
public string Property4 { get; set; }
List<ClassD> ListClassD { get; set; }
}
public class ClassC{
public string Property5 { get; set; }
public string Property6 { get; set; }
public string Property7 { get; set; }
}
public class ClassD{
public string Property8 { get; set; }
public string Property9 { get; set; }
public string Property10 { get; set; }
}
大家好,
这里的问题是我需要使用来自结构类似于 ClassA
的对象的 .rdlc
报告来创建报告。目前,我只能创建一个 'master-detail' 报告,只考虑 ClassA
和 ClassB
的属性
这是通过以下来源实现的:
https://www.c-sharpcorner.com/article/rdlc-subreport-using-c-sharp-and-wpf/
https://www.youtube.com/watch?v=2-YkNo1Os3Y
但是现在,我无法使用相同的方法包含来自 ClassC
的数据,因为无法为第 3 级设置数据源。
始终欢迎任何解决此问题的指导或来源。
杰西蒙
更新
我制作了一个快速的小型原型,它实现了一个具有两个级别的报告。对于第 2 级,我们唯一需要做的就是实现 SubreportProcessing
事件。这是代码。
private void LoadApplicationsCatalog()
{
using (IdentityDataContext context = new IdentityDataContext())
{
this.reportViewer1.LocalReport.DataSources.Clear();
var applicationsCatalog = context.spGetApplicationsCatalog().Select(a => new { a.IdentityApplicationCatalogId, a.Name, a.IdentityApplicationId }).ToList();
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ApplicationCatalog", applicationsCatalog));
this.reportViewer1.LocalReport.SubreportProcessing += LocalReport_SubreportProcessing;
this.reportViewer1.Refresh();
this.reportViewer1.RefreshReport();
}
}
private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
int identityApplicationId = Convert.ToInt32(e.Parameters[0].Values[0]);
using (IdentityDataContext context = new IdentityDataContext())
{
var applications = context.IdentityApplications.Where(a => a.IdentityApplicationId == identityApplicationId).ToList();
ReportDataSource datasource = new ReportDataSource("Application",applications);
e.DataSources.Add(datasource);
}
var applicationCatalogReport = (LocalReport)sender;
}
不幸的是,我还没有找到填充第三级数据源的方法。
几天后,我发现了这个 How to process subreport of a subreport in rdlc? 它帮助我解决了创建具有 3 个或更多级别的报告的问题。