public void OnInitReportOptions(ReportViewerOptions reportOption)
{
string basePath = _hostingEnvironment.WebRootPath;
if(reportOption.SubReportModel != null)
{
if (reportOption.SubReportModel.ReportPath == "SubReport1")
{
FileStream subReportStream1 = new FileStream(basePath + @"\ReportRDL\SubReport1.rdlc", FileMode.Open, FileAccess.Read);
reportOption.SubReportModel.Stream = subReportStream1;
}
else if (reportOption.SubReportModel.ReportPath == "SubReport2")
{
FileStream subReportStream2 = new FileStream(basePath + @"\ReportRDL\SubReport2.rdlc", FileMode.Open, FileAccess.Read);
reportOption.SubReportModel.Stream = subReportStream2;
}
}
else
{
FileStream reportStream = new FileStream(basePath + @"\ReportRDL\MainReport.rdlc", FileMode.Open, FileAccess.Read);
reportOption.ReportModel.Stream = reportStream;
reportOption.ReportModel.DataSources.Clear();
reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet", Value = MainReport.GetData() });
}
}
public void OnReportLoaded(ReportViewerOptions reportOption)
{
if (reportOption.SubReportModel != null)
{
if (reportOption.SubReportModel.ReportPath == "SubReport1")
{
reportOption.SubReportModel.DataSources = new ReportDataSourceCollection();
reportOption.SubReportModel.DataSources.Clear();
reportOption.SubReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet1", Value = SubReport.GetData() });
}
else if (reportOption.SubReportModel.ReportPath == "SubReport2")
{
reportOption.SubReportModel.DataSources = new ReportDataSourceCollection();
reportOption.SubReportModel.DataSources.Clear();
reportOption.SubReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet2", Value = SubReport.GetData() });
}
}
} |