/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="report">report document</param>
        /// <param name="data">multiple report data</param>
        /// <exception cref="ArgumentException">Need at least two ReportData objects</exception>
        public MultipleReportPaginator(ReportDocument report, IEnumerable <ReportData> data)
        {
            if (data == null)
            {
                throw new ArgumentException("Need at least two ReportData objects");
            }

            // create a list of report paginators and compute page counts
            _pageCount = 0;
            int dataCount = 0;

            foreach (ReportData rd in data)
            {
                if (rd == null)
                {
                    continue;
                }
                ReportPaginator paginator = new ReportPaginator(report, rd);
                _reportPaginators.Add(paginator);
                DocumentPage dp = paginator.GetPage(0);
                if ((dp != DocumentPage.Missing) && (dp.Size != Size.Empty))
                {
                    _pageSize = paginator.PageSize;
                }
                _firstPages.Add(dp); // just cache the generated first page
                _pageCount += paginator.PageCount;
                dataCount++;
            }
            if ((_reportPaginators.Count <= 0) || (dataCount < 2))
            {
                throw new ArgumentException("Need at least two ReportData objects");
            }
        }
Ejemplo n.º 2
0
        public FlowDocument CreateFlowDocument(ReportData data, Action <int, int> PageGeneratedCallBack = null)
        {
            MemoryStream ms   = new MemoryStream();
            Package      pkg  = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
            string       pack = String.Format("pack://report{0}.xps", this.ReportName);

            PackageStore.RemovePackage(new Uri(pack));
            PackageStore.AddPackage(new Uri(pack), pkg);
            XpsDocument             doc  = new XpsDocument(pkg, CompressionOption.NotCompressed, pack);
            XpsSerializationManager rsm  = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
            var             flowDocument = this.CreateFlowDocument();
            ReportPaginator rp           = new ReportPaginator(this, data, PageGeneratedCallBack, flowDocument);

            return(flowDocument);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Helper method to create page header or footer from flow document template
        /// </summary>
        /// <param name="data">report data</param>
        /// <param name="fileName">file to save XPS to</param>
        /// <returns></returns>
        public XpsDocument CreateXpsDocument(ReportData data, string fileName)
        {
            Package pkg  = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite);
            string  pack = "pack://report.xps";

            PackageStore.RemovePackage(new Uri(pack));
            PackageStore.AddPackage(new Uri(pack), pkg);
            XpsDocument             doc = new XpsDocument(pkg, _xpsCompressionOption, pack);
            XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);

            ReportPaginator rp = new ReportPaginator(this, data);

            rsm.SaveAsXaml(rp);
            rsm.Commit();
            pkg.Close();
            return(new XpsDocument(fileName, FileAccess.Read));
        }
        /// <summary>
        /// Gets a document page of the appropriate generated report
        /// </summary>
        /// <param name="pageNumber">page number</param>
        /// <returns>parsed DocumentPage</returns>
        public override DocumentPage GetPage(int pageNumber)
        {
            // find the appropriate paginator for the page
            int             currentPage    = 0;
            int             paginatorIndex = 0;
            ReportPaginator pagePaginator  = null;

            foreach (ReportPaginator paginator in _reportPaginators)
            {
                int pageCount = paginator.PageCount;
                if (pageNumber >= currentPage + pageCount)
                {
                    currentPage += pageCount;
                    paginatorIndex++;
                    continue;
                }
                pagePaginator = paginator;
                break;
            }
            if (pagePaginator == null)
            {
                return(DocumentPage.Missing);
            }

            DocumentPage dp;

            if (pageNumber == 0)
            {
                dp = _firstPages[paginatorIndex];
            }
            else
            {
                dp = pagePaginator.GetPage(pageNumber - currentPage);
            }
            if (dp == DocumentPage.Missing)
            {
                return(DocumentPage.Missing);
            }
            _pageSize = dp.Size;
            return(dp);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Helper method to create page header or footer from flow document template
        /// </summary>
        /// <param name="data">report data</param>
        /// <returns></returns>
        public XpsDocument CreateXpsDocument(ReportData data, Action <int, int> PageGeneratedCallBack = null)
        {
            MemoryStream ms   = new MemoryStream();
            Package      pkg  = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
            string       pack = String.Format("pack://report{0}.xps", this.ReportName);

            PackageStore.RemovePackage(new Uri(pack));
            PackageStore.AddPackage(new Uri(pack), pkg);
            XpsDocument             doc = new XpsDocument(pkg, CompressionOption.NotCompressed, pack);
            XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
            //DocumentPaginator paginator = ((IDocumentPaginatorSource)CreateFlowDocument()).DocumentPaginator;

            ReportPaginator rp = new ReportPaginator(this, data, PageGeneratedCallBack);

            rsm.SaveAsXaml(rp);

            rsm.Commit();
            //pkg.Close();

            return(doc);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Helper method to create page header or footer from flow document template
        /// </summary>
        /// <param name="data">report data</param>
        /// <returns></returns>
        public ReportPaginator CreatePaginator(ReportData data, Action <int, int> PageGeneratedCallBack = null)
        {
            ReportPaginator rp = new ReportPaginator(this, data, PageGeneratedCallBack);

            return(rp);
        }