コード例 #1
0
        public static XtraReport CreateSampleMasterReport()
        {
            var report = new XtraReport();

            using (StreamWriter sw = new StreamWriter(new MemoryStream()))
            {
                sw.Write(ReportRepository.SampleMasterReportLayout);
                sw.Flush();
                report.LoadLayoutFromXml(sw.BaseStream);
            }
            var objectDataSource = new ObjectDataSource();

            objectDataSource.BeginInit();
            objectDataSource.Name        = "Query: Customers";
            objectDataSource.DataSource  = typeof(GenericDataRetriever <Customer>);
            objectDataSource.Constructor = new ObjectConstructorInfo();
            objectDataSource.DataMember  = nameof(GenericDataRetriever <Customer> .Execute);
            objectDataSource.Parameters.Add(new Parameter
            {
                Name  = "queryName",
                Type  = typeof(string),
                Value = typeof(Customer).Name
            });
            objectDataSource.EndInit();
            report.DataSource = objectDataSource;
            return(report);
        }
コード例 #2
0
        private void btnOpenDesigner_Click(object sender, EventArgs e)
        {
            XtraReport report = new XtraReport();

            report.LoadLayoutFromXml(fileName);
            new ReportDesignTool(report).ShowDesigner();
        }
コード例 #3
0
        public static XtraReport CreateSampleDetailReport()
        {
            var report = new XtraReport();

            using (StreamWriter sw = new StreamWriter(new MemoryStream()))
            {
                sw.Write(ReportRepository.SampleDetailReportLayout);
                sw.Flush();
                report.LoadLayoutFromXml(sw.BaseStream);
            }
            var objectDataSource = new ObjectDataSource();

            objectDataSource.BeginInit();
            objectDataSource.Name        = "Customer details";
            objectDataSource.DataSource  = typeof(GenericDataRetriever <CustomerDetail>);
            objectDataSource.Constructor = new ObjectConstructorInfo();
            objectDataSource.DataMember  = nameof(GenericDataRetriever <CustomerDetail> .Execute);
            objectDataSource.Parameters.Add(new Parameter
            {
                Name  = "queryName",
                Type  = typeof(string),
                Value = typeof(CustomerDetail).Name
            });
            objectDataSource.Parameters.Add(new Parameter
            {
                Name  = "arg1",
                Type  = typeof(DevExpress.DataAccess.Expression),
                Value = new DevExpress.DataAccess.Expression("?CustomerId", typeof(int))
            });
            objectDataSource.EndInit();
            report.DataSource = objectDataSource;
            return(report);
        }
コード例 #4
0
        private static byte[] ExportReport(ReportDataV2 reportData, IObjectSpaceProvider objectSpaceProvider, string CriteriaString, IObjectSpace objectSpace)
        {
            MyReportDataSourceHelper reportDataSourceHelper = new MyReportDataSourceHelper(objectSpaceProvider);

            ReportDataProvider.ReportObjectSpaceProvider = new MyReportObjectSpaceProvider(objectSpaceProvider);
            CriteriaOperator ReportCriteria = CriteriaOperator.Parse(CriteriaString);


            //XtraReport report = ReportDataProvider.ReportsStorage.LoadReport(reportData);
            XtraReport report = new XtraReport();

            byte[] content = reportData.Content;
            if (content != null && content.Length != 0)
            {
                int num = content.Length;
                while (content[num - 1] == 0)
                {
                    num--;
                }
                MemoryStream memoryStream = new MemoryStream(content, 0, num);

                report.LoadLayoutFromXml(memoryStream);

                // report.LoadLayout(memoryStream);


                memoryStream.Close();
            }

            DataSourceBase dataSourceBase = report.DataSource as DataSourceBase;

            if (dataSourceBase != null && reportData is IReportDataV2Writable)
            {
                ((IReportDataV2Writable)reportData).SetDataType(dataSourceBase.DataType);
            }
            report.DisplayName = reportData.DisplayName;

            //XtraReport report = reportData.LoadReport(objectSpace);



            report.Extensions["DataSerializationExtension"] = "XtraReport";
            report.Extensions["DataEditorExtension"]        = "XtraReport";
            report.Extensions["ParameterEditorExtension"]   = "XtraReport";

            reportDataSourceHelper.SetupBeforePrint(report, null, ReportCriteria, true, null, false);



            MemoryStream ReportStream = new MemoryStream();

            report.ExportToPdf(ReportStream);
            return(ReportStream.ToArray());
        }
 protected static XRControl[] DeserializeControls(byte[] bytes)
 {
     if (bytes != null && bytes.Length > 0)
     {
         XtraReport tempReport = new XtraReport();
         using (MemoryStream stream = new MemoryStream(bytes)) {
             tempReport.LoadLayoutFromXml(stream);
         }
         return(tempReport.Bands[BandKind.Detail].Controls.Cast <XRControl>().ToArray());
     }
     return(new XRControl[0]);
 }
コード例 #6
0
        private void loadReportfromFileButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfd = new OpenFileDialog();

            if (openfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            XtraReport report = new XtraReport();

            report.LoadLayoutFromXml(openfd.FileName);
            report.ShowDesignerDialog();
        }
        protected static byte[] SerializeControls(XRControl[] controls)
        {
            XtraReport tempReport = new XtraReport();
            DetailBand tempBand   = new DetailBand();

            tempReport.Bands.Add(tempBand);

            using (XtraReport cloneReport = new XtraReport()) {
                using (MemoryStream stream = new MemoryStream()) {
                    controls[0].RootReport.SaveLayoutToXml(stream);
                    stream.Position = 0;

                    cloneReport.LoadLayoutFromXml(stream);
                }
                foreach (XRControl control in controls)
                {
                    XRControl clone = cloneReport.FindControl(control.Name, true);
                    if (clone != null)
                    {
                        tempBand.Controls.Add(clone);
                    }
                }
            }

            float topMost  = float.MaxValue;
            float leftMost = float.MaxValue;

            foreach (XRControl control in tempBand.Controls)
            {
                topMost  = Math.Min(topMost, control.TopF);
                leftMost = Math.Min(leftMost, control.LeftF);
            }

            foreach (XRControl control in tempBand.Controls)
            {
                control.LocationF = new PointF(control.LeftF - leftMost, control.TopF - topMost);
            }

            byte[] layoutBytes = null;

            using (MemoryStream stream = new MemoryStream()) {
                tempReport.SaveLayoutToXml(stream);
                layoutBytes = stream.ToArray();
            }

            tempReport.Dispose();
            return(layoutBytes);
        }
コード例 #8
0
        public override byte[] GetData(string url)
        {
            // Returns report layout data stored in a Report Storage using the specified URL.
            // This method is called only for valid URLs after the IsValidUrl method is called.           
            string[] urlParts = url.Split('?');
            string reportName = urlParts[0];

            var data = EmbeddedResourceReportStorage.GetData(reportName);
            if (data == null)
            {
                ReportDetails details = null;
                if (Reports.TryGetValue(reportName, out details))
                    data = details.Layout;
            }



            if (data != null)
            {
                if (urlParts.Length == 2)
                {
                    XtraReport report = new XtraReport();
                    report.LoadLayoutFromXml(new MemoryStream(data));

                    string[] parameterDefinitions = urlParts[1].Split('&');
                    foreach (string parameterDefinition in parameterDefinitions)
                    {
                        string[] keyValue = parameterDefinition.Split('=');
                        DevExpress.XtraReports.Parameters.Parameter parameter = report.Parameters[keyValue[0]];
                        parameter.Value = Convert.ChangeType(keyValue[1], parameter.Type);
                    }

                    using (MemoryStream ms = new MemoryStream())
                    {
                        report.SaveLayoutToXml(ms);
                        return ms.ToArray();
                    }
                }
                else
                    return data;
            }


            throw new FaultException(new FaultReason(string.Format("Could not find report '{0}'.", url)), new FaultCode("Server"), "GetData");
        }
コード例 #9
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);
                        }
                    }
                }
            }
        }
        public static string ConvertReportWithMyUriJsonSourceTo191(string repxContent, out List <string> connectionString)
        {
            var report = new XtraReport();

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(repxContent))) {
                report.LoadLayoutFromXml(ms);
            }

            connectionString = new List <string>();

            int i = 0;

            foreach (var component in report.ComponentStorage)
            {
                var jsonDS     = (component as DevExpress.DataAccess.Json.JsonDataSource);
                var jsonSource = (jsonDS?.JsonSource as MyUriJsonSource);
                if (jsonSource != null)
                {
                    i++;
                    jsonDS.ConnectionName = string.Format("newJsonConnection_{0}{1}", report.Name, i.ToString());

                    var builder = new DbConnectionStringBuilder();
                    builder.Add("Uri", jsonSource.Uri.OriginalString);
                    builder.Add("UserName", jsonSource.UserName);
                    builder.Add("Password", jsonSource.Password);

                    connectionString.Add(string.Format("<add name=\"{0}\" connectionString=\"{1}\" providerName=\"JsonSourceProvider\" />",
                                                       jsonDS.ConnectionName, builder.ConnectionString));

                    jsonDS.JsonSource = null;
                }
            }
            using (var ms = new MemoryStream()) {
                report.SaveLayoutToXml(ms);
                ms.Position = 0;
                StreamReader reader = new StreamReader(ms);
                return(reader.ReadToEnd());
            }
        }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            var report = CreateReport();

            byte[] buffer = null;

            using (var stream = new MemoryStream())
            {
                report.SaveLayoutToXml(stream);
                buffer = stream.ToArray();
            }

            // Создаем новый отчет из сохраненного массива байт
            var rpt = new XtraReport();

            using (var stream = new MemoryStream(buffer))
            {
                rpt.LoadLayoutFromXml(stream);
            }

            // Отображаем новый отчет
            rpt.ShowPreview();
        }
コード例 #13
0
        private XtraReport GetReport(int ReportId, string name)
        {
            var report = new XtraReport();

            //defensive code for checking if the report is created or not
            if (Type.GetType(name) != null)
            {
                report = (XtraReport)Activator.CreateInstance(Type.GetType(name));

                var hreport = db.HReports.Find(ReportId);

                if (hreport != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        ms.Write(hreport.ReportData, 0, hreport.ReportData.Length);
                        ms.Flush();
                        report.LoadLayoutFromXml(ms);
                    }
                }
            }
            return(report);
        }