Exemple #1
0
        public async Task <string> GenerateSequenceReport(string template, CaseSequenceData dataSource)
        {
            string filePath = System.Configuration.ConfigurationManager.AppSettings["ReportTempLocation"].ToString() + "\\" + Guid.NewGuid().ToString() + "_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + ".trdx";

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;

            Telerik.Reporting.Report report = null;

            byte[] templateBytes = Convert.FromBase64String(template);
            File.WriteAllBytes(filePath, templateBytes);

            using (XmlReader xmlReader = XmlReader.Create(filePath, settings))
            {
                ReportXmlSerializer xmlSerializer = new ReportXmlSerializer();
                report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
            }

            report.DataSource = dataSource;

            ReportProcessor      reportProcessor      = new ReportProcessor();
            InstanceReportSource instanceReportSource = new InstanceReportSource();

            instanceReportSource.ReportDocument = report;
            RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

            return(Convert.ToBase64String(result.DocumentBytes));
        }
        public static void ReplaceReportConnectionStrings(string filePath)
        {
            var xmlSerializer = new ReportXmlSerializer();
            Report reportDocument;

            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                var settings = new XmlReaderSettings { IgnoreWhitespace = true };

                using (var reader = XmlReader.Create(stream, settings))
                    reportDocument = (Report)xmlSerializer.Deserialize(reader);
            }

            if (reportDocument == null)
                return;

            var dataSourcesProp = reportDocument.GetType().GetProperty("DataSources", BindingFlags.Instance | BindingFlags.NonPublic);

            if (dataSourcesProp != null)
            {
                var dataSources = dataSourcesProp.GetValue(reportDocument) as IEnumerable;

                if (dataSources != null)
                    foreach (var sqlDataSource in dataSources.OfType<SqlDataSource>())
                        sqlDataSource.ConnectionString = ConfigurationManager.ConnectionStrings[Constants.RuntimeDatabase].Return(s => s.ConnectionString, string.Empty);
            }

            xmlSerializer.Serialize(filePath, reportDocument);
        }
Exemple #3
0
        //public async Task<string> GetAccessToken()
        //{
        //    UserPasswordCredential creds = new UserPasswordCredential("*****@*****.**", "Welcome@123");
        //    AuthenticationResult authenticationResult = null;
        //    var authenticationContext = new AuthenticationContext("https://login.windows.net/common/oauth2/token/");

        //    authenticationResult = await authenticationContext.AcquireTokenAsync("https://analysis.windows.net/powerbi/api", "c565eea1-4938-468e-8d5f-35b74ac5e8e5", creds);// new ClientCredential(Secrets.ClientID,Secrets.ClientSecret));
        //    return authenticationResult.AccessToken.ToString();

        //}

        public async Task <string> CreatePGXCaseReport(PGXCaseReportData dataSource)
        {
            string filePath = System.Configuration.ConfigurationManager.AppSettings["ReportTemplateLocation"].ToString() + "\\" + dataSource.TemplateName;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;

            Telerik.Reporting.Report report = null;

            using (XmlReader xmlReader = XmlReader.Create(filePath, settings))
            {
                ReportXmlSerializer xmlSerializer = new ReportXmlSerializer();
                report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
            }

            report.DataSource = dataSource;


            ReportProcessor      reportProcessor      = new ReportProcessor();
            InstanceReportSource instanceReportSource = new InstanceReportSource();

            instanceReportSource.ReportDocument = report;
            RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

            return(Convert.ToBase64String(result.DocumentBytes));
        }
Exemple #4
0
        public async Task <string> GenerateReport(string template, CaseQualitativeData dataSource)
        {
            //Reference:http://www.telerik.com/forums/programmatically-use-of-trdp-report
            //sample reports:C:\Program Files (x86)\Telerik\Reporting R1 2017\Report Designer\Examples


            string filePath = System.Configuration.ConfigurationManager.AppSettings["ReportTempLocation"].ToString() + "\\" + Guid.NewGuid().ToString() + "_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + ".trdx";

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;

            Telerik.Reporting.Report report = null;

            byte[] templateBytes = Convert.FromBase64String(template);
            File.WriteAllBytes(filePath, templateBytes);

            using (XmlReader xmlReader = XmlReader.Create(filePath, settings))
            {
                ReportXmlSerializer xmlSerializer = new ReportXmlSerializer();
                report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
            }

            report.DataSource = dataSource;

            ReportProcessor      reportProcessor      = new ReportProcessor();
            InstanceReportSource instanceReportSource = new InstanceReportSource();

            instanceReportSource.ReportDocument = report;
            RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

            return(Convert.ToBase64String(result.DocumentBytes));
        }
Exemple #5
0
        public async Task <string> CreateToxicologyAccessionReport(ReportCaseData dataSource, string templateName)
        {
            int seriesCount    = dataSource.PreviousHistoryChartData.Select(x => x.Name).Distinct().Count();
            int xAxisDataCount = dataSource.PreviousHistoryChartData.Select(x => x.DateCollected).Distinct().Count();

            //dataSource.ChartData = await this.GenerateChartImageFromXlsxFile("", "", dataSource.PreviousHistoryExcelChartData, seriesCount, xAxisDataCount);
            Console.Write(dataSource.ToString());
            Console.WriteLine(templateName);
            //string templateName = "ToxicologyAccessionCaseReport";
            string filePath = System.Configuration.ConfigurationManager.AppSettings["ReportTemplateLocation"].ToString() + "\\" + templateName + ".trdx";

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;

            Telerik.Reporting.Report report = null;

            using (XmlReader xmlReader = XmlReader.Create(filePath, settings))
            {
                ReportXmlSerializer xmlSerializer = new ReportXmlSerializer();
                report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
            }

            report.DataSource = dataSource;


            ReportProcessor      reportProcessor      = new ReportProcessor();
            InstanceReportSource instanceReportSource = new InstanceReportSource();

            instanceReportSource.ReportDocument = report;
            RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

            //var reportLocation = ConfigurationManager.AppSettings["ReportTempLocation"];
            //string reportName = templateName+"_" + Guid.NewGuid().ToString() + "_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + ".pdf";
            //string reportDestination = Path.Combine(reportLocation, reportName);

            //using (FileStream fs = new FileStream(reportDestination, FileMode.Create))
            //{
            //    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            //}
            //string reportUrl = dataSource.ServerUrl + "/" + reportName;
            ////byte[] bytes = result.DocumentBytes;
            //string response = Convert.ToBase64String(bytes);

            return(Convert.ToBase64String(result.DocumentBytes));
        }
Exemple #6
0
        public async Task <string> CreateToxLabOrderRequisitionReport(ToxLabOrderReportData dataSource, string templateName = "ToxLabOrderRequisitionReport.trdx")
        {
            string filePath = System.Configuration.ConfigurationManager.AppSettings["ReportTemplateLocation"].ToString() + "\\" + templateName;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;

            Telerik.Reporting.Report report = null;

            using (XmlReader xmlReader = XmlReader.Create(filePath, settings))
            {
                ReportXmlSerializer xmlSerializer = new ReportXmlSerializer();
                report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
            }

            report.DataSource = dataSource;


            ReportProcessor      reportProcessor      = new ReportProcessor();
            InstanceReportSource instanceReportSource = new InstanceReportSource();

            instanceReportSource.ReportDocument = report;
            RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

            //var reportLocation = ConfigurationManager.AppSettings["ReportTempLocation"];
            //string reportName = dataSource.Id + "_ToxLabOrderRequisition_" + Guid.NewGuid().ToString() + "_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + ".pdf";
            //string reportDestination = Path.Combine(dataSource.FolderPath, reportName);

            //using (FileStream fs = new FileStream(reportDestination, FileMode.Create))
            //{
            //    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            //}
            //string reportUrl = dataSource.ServerUrl + "/" + reportName;
            //byte[] bytes = result.DocumentBytes;
            //string response = Convert.ToBase64String(bytes);

            return(Convert.ToBase64String(result.DocumentBytes));
        }
        /// <summary>
        /// Retrieves report source for report name.
        /// </summary>
        /// <param name="report">
        /// The report name.
        /// </param>
        /// <returns>
        /// Report source.
        /// </returns>
        public ReportSource GetReportSource(string report)
        {
            var reportInfo = report.ToReportInfo();

            if (reportInfo != null)
                _reportCache = reportInfo;
            else
                reportInfo = _reportCache;

            if (reportInfo != null && !IsCustomReport(reportInfo.ReportName))
            {
                var reportType = Type.GetType(reportInfo.ReportName);

                if (reportType != null)
                {
                    var reportDocument = reportType.GetConstructors()[0].Invoke(null) as ICustomReport;

                    if (reportDocument == null)
                        return null;

                    foreach (var parameter in reportDocument.ReportParameters.Where(parameter => reportInfo.ReportParametres.ContainsKey(parameter.Name)))
                        parameter.Value = reportInfo.ReportParametres[parameter.Name];

                    if (reportDocument.IsDetailReport)
                    {
                        ReportHelper.BuildDetailReport(reportDocument);
                        ReportHelper.GetDetailReportData(reportDocument);
                    }
                    else
                    {
                        ReportHelper.BuildReport(reportDocument);                        
                        ReportHelper.GetReportData(reportDocument);
                    }

                    Observable.FromEventPattern<ErrorEventHandler, Telerik.Reporting.ErrorEventArgs>(
                        handler => reportDocument.Reports.First().Error += handler,
                        handler => reportDocument.Reports.First().Error -= handler
                        ).Subscribe(pattern => ReportHelper.SaveError(pattern.Sender as Report, pattern.EventArgs.Exception));

                    return new InstanceReportSource { ReportDocument = reportDocument };
                }

                return null;
            }

            if (reportInfo == null && !IsCustomReport(report))
                return null;

            var reportStr = reportInfo == null ? report : reportInfo.ReportName;

            var reportDefinition = CustomReportDefinition.Parse(XElement.Parse(reportStr.Substring(1, reportStr.Length - 1)));
            var cusotmReport = CustomReport.GetCustomReport(reportDefinition.FileName);

            var stream = new MemoryStream(cusotmReport.SerializedReport.ToArray());
            
            var settings = new XmlReaderSettings { IgnoreWhitespace = true };

            using (var reader = XmlReader.Create(stream, settings))
            {
                var xmlSerializer = new ReportXmlSerializer();

                var reportDocument = (Report)xmlSerializer.Deserialize(reader);

                if (!reportDocument.ReportParameters.Contains(ProcessNameParam))
                    reportDocument.ReportParameters.Add(ProcessNameParam, ReportParameterType.String, string.Empty);

                if (!reportDocument.ReportParameters.Contains(ReportTypeParam))
                    reportDocument.ReportParameters.Add(ReportTypeParam, ReportParameterType.String, string.Empty);

                if (!reportDocument.ReportParameters.Contains(ItemIdParam))
                    reportDocument.ReportParameters.Add(ItemIdParam, ReportParameterType.Integer, 0);

                if (!reportDocument.ReportParameters.Contains(UserRightsParam))
                    reportDocument.ReportParameters.Add(UserRightsParam, ReportParameterType.String, string.Empty);

                if (!reportDocument.ReportParameters.Contains(FilterDefinition))
                    reportDocument.ReportParameters.Add(FilterDefinition, ReportParameterType.String, string.Empty);

                if (!reportDocument.ReportParameters.Contains(Sorting))
                    reportDocument.ReportParameters.Add(Sorting, ReportParameterType.String, string.Empty);

                if (!reportDocument.ReportParameters.Contains(GlobalFilter))
                    reportDocument.ReportParameters.Add(GlobalFilter, ReportParameterType.String, string.Empty);

                if (reportInfo != null)
                {
                    if (!reportDocument.ReportParameters.Contains(AccountId))
                    {
                        reportDocument.ReportParameters.Add(AccountId, ReportParameterType.Integer, reportInfo.ReportParametres["accountId"]);
                    }
                    else
                    {
                        reportDocument.ReportParameters["AccountId"].Value = reportInfo.ReportParametres["accountId"];
                    }
                }

                if (reportInfo != null)
                    foreach (var parameter in reportDocument.ReportParameters.Where(parameter => reportInfo.ReportParametres.ContainsKey(parameter.Name)))
                        parameter.Value = reportInfo.ReportParametres[parameter.Name];

                reportDocument.NeedDataSource += ReportNeedDataSource;
                reportDocument.ItemDataBinding += ReportOnItemDataBinding;

                EventHandler reportDisposedEventHandler = null;
                reportDisposedEventHandler = (sender, args) =>
                {
                    reportDocument.NeedDataSource -= ReportNeedDataSource;
                    reportDocument.ItemDataBinding -= ReportOnItemDataBinding;
                    reportDocument.Disposed -= reportDisposedEventHandler;
                };

                reportDocument.Disposed += reportDisposedEventHandler;

                return new InstanceReportSource { ReportDocument = reportDocument };
            }
            
        }