コード例 #1
0
        Report DeserializeReport(XmlReportSource xmlReportSource)
        {
            var settings = new System.Xml.XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            var textReader = new System.IO.StringReader(xmlReportSource.Xml);

            using (var xmlReader = System.Xml.XmlReader.Create(textReader, settings))
            {
                var xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
                var report        = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
                return(report);
            }
        }
コード例 #2
0
    public static void PrintPackingList(Order order)
    {
      ConfigurationValue oConVal = Configuration.GetValue(new string[] { order.ClientCode, "PackingList" });
      if (oConVal == null || oConVal.Value == null)
      {
        return;
      }

      XmlReportSource oReport = new XmlReportSource();
      oReport.Xml = (string)oConVal.Value;

      // Adding the initial parameter values
      oReport.Parameters.Add(new Telerik.Reporting.Parameter("OrderNumber", order.ClientOrderNo));

      ReportViewer oReportViewer = new ReportViewer();
      oReportViewer.ReportSource = oReport;

      Form oForm = new Form();
      oForm.Controls.Add(oReportViewer);
      oReportViewer.Dock = DockStyle.Fill;

      oReportViewer.RefreshReport();

      oForm.StartPosition = FormStartPosition.CenterScreen;
      oForm.WindowState = FormWindowState.Maximized;

      oForm.ShowDialog();
    }
コード例 #3
0
        /// <summary>
        /// Возвращает источник для отчета.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="reportFile"></param>
        /// <param name="parentOid"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        ReportSource GetReportSource(
            ReportDbContext context
            , DAL.Entities.ReportFileDB reportFile
            , Guid?parentOid
            , ParameterCollection parameters = null)
        {
            ReportSource reportSource   = null;
            var          reportPackager = new ReportPackager();

            using (var sourceStream = new MemoryStream(reportFile.Content))
            {
                switch (reportFile.Extension?.Split('.')?.Last()?.ToUpper())
                {
                case "TRDX":
                    reportSource = new XmlReportSource()
                    {
                        Xml = System.Text.Encoding.UTF8.GetString(reportFile.Content)
                    };
                    break;

                case "TRBP":     //книга
                    var reportBook = (ReportBook)reportPackager.UnpackageDocument(sourceStream);
                    var pOid       = parentOid.HasValue ? parentOid.Value : reportFile.GuidId;
                    SetReportBookSorces(context, pOid, ref reportBook);
                    reportSource = new InstanceReportSource()
                    {
                        ReportDocument = reportBook
                    };
                    break;

                case "TRDP":
                default:
                    var report = (Report)reportPackager.UnpackageDocument(sourceStream);

                    //установка источника для вложенных секций отчета
                    var prOid = parentOid.HasValue ? parentOid.Value : reportFile.GuidId;
                    report.Items.Flatten(f => f.Items)
                    .Where(i => (i.GetType().GetProperty(nameof(ReportSource)) != null) ||
                           (i.Action != null && i.Action.GetType().GetProperty(nameof(ReportSource)) != null))
                    .ToList()
                    .ForEach(f =>
                    {
                        var prop = f.GetType().GetProperty(nameof(ReportSource));
                        if (prop != null)
                        {
                            prop.SetValue(f, GetSubReportSorce(context, (ReportSource)prop.GetValue(f), prOid));
                        }

                        if (f.Action != null)
                        {
                            var aprop = f.Action.GetType().GetProperty(nameof(ReportSource));
                            if (aprop != null)
                            {
                                aprop.SetValue(f.Action, GetSubReportSorce(context, (ReportSource)aprop.GetValue(f.Action), prOid));
                            }
                        }
                    });

                    reportSource = new InstanceReportSource()
                    {
                        ReportDocument = report
                    };

                    //назначение параметров
                    if (parameters != null && parameters.Count() > 0)
                    {
                        reportSource.Parameters.Clear();
                        foreach (var par in parameters)
                        {
                            reportSource.Parameters.Add(par.Name, par.Value);
                        }
                    }


                    break;
                }
            }

            return(reportSource);
        }