Hi.
My report class looks like this:
public partial class SystemReport<
THeader
, TBody> : Report
where THeader : Report, new()
where TBody : Report, new()
{
public THeader ReportHeader { get; private set; }
public TBody ReportBody { get; private set; }
public SystemReport()
{
InitializeComponent();
InitializeSubReportHeader();
InitializeSubReportBody();
}
private void InitializeSubReportHeader()
{
ReportHeader = new THeader();
headerReportSource = new InstanceReportSource { ReportDocument = ReportHeader };
InitSubReport(ReportHeader, subReportHeader, headerReportSource);
}
private void InitializeSubReportBody()
{
ReportBody = new TBody();
bodyReportSource = new InstanceReportSource { ReportDocument = ReportBody };
InitSubReport(ReportBody, subReportBody, bodyReportSource);
}
private void InitSubReport(Report report, SubReport subReport, ReportSource reportSource)
{
((ISupportInitialize)(report)).BeginInit();
subReport.ReportSource = reportSource;
}
}
The way I create the report where OperationHeader and OperationBody are seperate subReports:
var report = new SystemReport<
OperationHeader
, OperationBody> {DataSource = model};
report.ReportBody.DataSource = model;
report.ReportHeader.DataSource = model;
After assigning above created report to reportViewer.ReportSource everything is displayed correctly.
Now I want to serialize this report. It seems to be possible using ReportXmlSerializer class. The think is that when the report is deserialized, type of report is no longer SystemReport but Report base type.
As I understood it correctly when report is deserialized I have to assign once again data sources. I'm doing it in this way:
foreach (var item in systemReport.Items.OfType<
Telerik.Reporting.DetailSection
>())
{
var subReport = item.Items.OfType<
Telerik.Reporting.SubReport
>().Single();
subReport.Report.DataSource = model;
}
foreach (var item in systemReport.Items.OfType<
Telerik.Reporting.ReportHeaderSection
>())
{
var subReport = item.Items.OfType<
Telerik.Reporting.SubReport
>().Single();
subReport.Report.DataSource = model;
}
systemReport.DataSource = model;
But actually after assigning report to reportViewer.ReportSource, subReports are not rendered at all.
Do you have any idea what I'm doing wrong? Or is there any other way to solve this?