Example #1
0
        /// <summary>
        /// Returns the number of logical pages
        /// -!- check if the current version of the report generator still generates the ancient doc and xls file formats,
        /// instead of xlsx/docx... if ever needed; at the moment, no report is using these formats in connection with the RDLC engine
        /// </summary>
        protected int RenderAsMsdbrpt(string resultfilebasename, ref MemoryStream chunk, ref string mime, LocalReport rpt, bool count_pages_only)
        {
            string rpt_format;

            if (Outputformat == FileType.ft_xls)
            {
                rpt_format = "Excel";
                if (resultfilebasename.EndsWith(".xls") == false)
                {
                    resultfilebasename += ".xls";
                }
                mime = SetResultDisposition(resultfilebasename + ".xls", FileType.ft_xls);
                if (chunk == null)
                {
                    chunk = new MemoryStream();
                }
            }
            else if (Outputformat == FileType.ft_doc)
            {
                rpt_format = "Word";
                if (resultfilebasename.EndsWith(".doc") == false)
                {
                    resultfilebasename += ".doc";
                }
                mime = SetResultDisposition(resultfilebasename, FileType.ft_doc);
                if (chunk == null)
                {
                    chunk = new MemoryStream();
                }
            }
            else if (Outputformat == FileType.ft_pdf)
            {
                rpt_format = "PDF";
                if (resultfilebasename.EndsWith(".pdf") == false)
                {
                    resultfilebasename += ".pdf";
                }
                mime = SetResultDisposition(resultfilebasename, FileType.ft_pdf);
                if (chunk == null)
                {
                    chunk = new MemoryStream();
                }
            }
            else
            {
                /* cannot render that... */
                throw new NotSupportedException(Outputformat.ToString());
            }
            /* do it */
            string[]  streams;
            Warning[] warnings;
            string    encoding;
            string    extension;

            /* [pkosec 20140521] set dpi for rdlc (MEA-2014-00207 initiative)
             * [pkosec 20140506] use the default value (null), if DPI has not been set */
            string devinfo = null;

            if (GetDPI != 0)
            {
                devinfo = String.Format("<DeviceInfo><DpiX>{0}</DpiX><DpiY>{0}</DpiY></DeviceInfo>", GetDPI);
            }
            var result = rpt.Render(rpt_format, devinfo, PageCountMode.Actual, out mime, out encoding, out extension, out streams, out warnings);

            foreach (var w in warnings)
            {
                Tracing.WarningCore("Code: {0}, Message: {1}, Objectname: {2}, Objecttype: {3}, Severity: {4}",
                                    w.Code,
                                    w.Message,
                                    w.ObjectName,
                                    w.ObjectType,
                                    w.Severity.ToString()
                                    );
            }
            if (count_pages_only == false)
            {
                chunk = new MemoryStream(result);
            }
            /* [dlatikay 20150424] added value: return the number of pages */
            return(rpt.GetTotalPages());
        }