Hi,
Been trying to set the figure out how to properly set the data of my sub report, thru searching on the threads I managed to come up with this code but testing it still does not show the data of my subreport. For the main report its seems fine, it there anything I miss out?
Below is the code
private
void
Form1_Load(
object
sender, EventArgs e)
{
var service =
new
TelerikReportDatasource.Service.ReportServiceEncounter();
var reportParameter =
new
TelerikReportDatasource.ParameterModel.ViewReportEncounter1ParameterModel
{
ProviderId = 1,
PatientId = 0,
PatientCaseId = 0,
ApptDate = Convert.ToDateTime(
"9/28/2015"
),
EncounterDate = Convert.ToDateTime(
"9/28/2015"
),
IgnoreMainSettings =
false
,
IsTimeCheck =
false
,
IsPrintedCheck =
true
,
IsSortByAlpha =
false
,
ConnectionString =
"some connection string"
,
IsMandatoryNPExam =
false
,
OnePerAppt =
false
,
ShowCTytd =
true
,
PastVisit =
true
,
FutureAppt =
true
,
NumberFutureAppts = 0,
SetCPTList =
true
,
DiagCount = 12,
SetEncMemo =
true
,
SetEncSpec =
true
,
SystemTimeZone = 2,
UserTimeZone = 2
};
var telerikReportSource = service.GetReportData(reportParameter);
var reportObjectDatasource =
new
ObjectDataSource();
reportObjectDatasource.DataSource = telerikReportSource.Encounter1Data;
reportObjectDatasource.DataMember =
"GetEncounter1"
;
var uriReportSource =
new
UriReportSource();
uriReportSource.Uri =
"rptEncounter.trdx"
;
var report = DeserializeReport(uriReportSource);
report.DataSource = reportObjectDatasource;
//Set the subreport datasource
var subReportPatDiag = (SubReport)report.Items.Find(
"PatDiag"
,
true
).FirstOrDefault();
var subReportPatDiagReportsource = (UriReportSource)subReportPatDiag.ReportSource;
subReportPatDiagReportsource.Parameters.Add(
"ApptID"
, telerikReportSource.Encounter1Data.FirstOrDefault().AppointID);
var reportPatDiag = DeserializeReport(subReportPatDiagReportsource);
var reportPatDiagSource = (ObjectDataSource)reportPatDiag.DataSource;
reportPatDiagSource.DataSource = telerikReportSource.Encounter4Data;
reportPatDiagSource.DataMember =
"GetEncounter4"
;
reportPatDiag.DataSource = reportPatDiagSource;
var reportSource =
new
InstanceReportSource();
reportSource.ReportDocument = report;
reportViewer1.ReportSource = reportSource;
reportViewer1.RefreshReport();
}
/// <summary>
/// Deserialize the TRDX report file from uri report to be able to use it as a report
/// </summary>
/// <param name="uriReportSource"></param>
/// <returns></returns>
Report DeserializeReport(UriReportSource uriReportSource)
{
var settings =
new
System.Xml.XmlReaderSettings();
settings.IgnoreWhitespace =
true
;
using
(var xmlReader = System.Xml.XmlReader.Create(uriReportSource.Uri, settings))
{
var xmlSerializer =
new
Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
var report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
return
report;
}
}
Help is greatly appreciated