Пример #1
0
        public void GenerateReportData(DoSoEmail email, bool prevewOnly)
        {
            if (string.IsNullOrWhiteSpace(ReportDataXml))
            {
                return;
            }

            CreateDataSourceFromXml();
            ExcelDataSource?.Fill();
            SqlDataSource?.Fill();

            using (var report = new XtraReport())
            {
                AddDataSource2Report(report);

                using (var ms = new MemoryStream())
                {
                    using (var sr = new StreamWriter(ms, Encoding.Default))
                    {
                        var doc = new XmlDocument();
                        doc.LoadXml(ReportDataXml);
                        var definitionXml = doc.OuterXml;
                        sr.Write(definitionXml);
                        sr.Flush();
                        ms.Position = 0;
                        report.LoadLayoutFromXml(ms);
                        report.FilterString = $"{ObjectKeyExpression} == {email.ObjectKey}";
                        report.ApplyFiltering();
                        //report.FillDataSource();

                        if (prevewOnly)
                        {
                            using (ReportPrintTool printTool = new ReportPrintTool(report))
                                printTool.ShowRibbonPreviewDialog(UserLookAndFeel.Default);
                        }
                        else
                        {
                            ExportRportData(email, report);
                        }
                    }
                }
            }
        }
        private void simpleAction_PrevewReport_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            var email    = View.CurrentObject as DoSoEmail;
            var schedule = email?.DoSoReportSchedule;
            var xml      = email?.DoSoReportSchedule?.ReportDataXml;

            if (string.IsNullOrWhiteSpace(xml))
            {
                return;
            }

            var report = new XtraReport();

            schedule.CreateDataSourceFromXml();
            schedule.ExcelDataSource?.Fill();
            schedule.SqlDataSource?.Fill();
            schedule.AddDataSource2Report(report);

            using (var ms = new MemoryStream())
            {
                using (var sr = new StreamWriter(ms, Encoding.Default))
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(xml);
                    var definitionXml = doc.OuterXml;
                    sr.Write(definitionXml);
                    sr.Flush();
                    ms.Position = 0;
                    report.LoadLayoutFromXml(ms);
                    report.FilterString = $"{schedule.ObjectKeyExpression} == {email.ObjectKey}";
                    report.ApplyFiltering();
                    //report.FillDataSource();

                    using (ReportPrintTool printTool = new ReportPrintTool(report))
                        printTool.ShowRibbonPreviewDialog(UserLookAndFeel.Default);
                }
            }
        }