This is a migrated thread and some comments may be shown as answers.

Subreport data not showing up

2 Answers 266 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jordan
Top achievements
Rank 1
Jordan asked on 02 Oct 2015, 04:45 PM

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

2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 07 Oct 2015, 08:50 AM
Hello Jordan,

After the sub-report has been deserialized:
var reportPatDiag = DeserializeReport(subReportPatDiagReportsource);

you need to assign the deserialized report object to the SubReport item in the main report and then add any report parameters:
var subReportIrs = new Telerik.Reporting.InstanceReportSource();
subReportIrs.ReportDocument = reportPatDiag;
subReportIrs.Parameters.Add("ApptID", telerikReportSource.Encounter1Data.FirstOrDefault().AppointID);
 
subReportPatDiag.ReportSource = subReportIrs;


Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jordan
Top achievements
Rank 1
answered on 09 Oct 2015, 03:24 PM

Thanks Its quite ok now, hoping it ​could be shorter I mean just adding a datasource for subreports not to mention you need to undergo a lot of casting and deserialization. In my humble it seems the http://www.telerik.com/help/reporting/report-sources-subreport.html is quite lacking a lot and did not even help at all.

Tags
General Discussions
Asked by
Jordan
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Jordan
Top achievements
Rank 1
Share this question
or