Esempio n. 1
0
        public void Start()
        {
            // Create the anchor for all pdf objects
            CompressionConfig cc = RdlEngineConfig.GetCompression();

            anchor = new PdfAnchor(cc != null);

            //Create a PdfCatalog
            string lang;

            if (r.ReportDefinition.Language != null)
            {
                lang = r.ReportDefinition.Language.EvaluateString(this.r, null);
            }
            else
            {
                lang = null;
            }
            catalog = new PdfCatalog(anchor, lang);

            //Create a Page Tree Dictionary
            pageTree = new PdfPageTree(anchor);

            //Create a Font Dictionary
            fonts = new PdfFonts(anchor);

            //Create a Pattern Dictionary
            patterns = new PdfPattern(anchor);

            //Create an Image Dictionary
            images = new PdfImages(anchor);

            //Create an Outline Dictionary
            outline = new PdfOutline(anchor);

            //Create the info Dictionary
            info = new PdfInfo(anchor);

            //Set the info Dictionary.
            info.SetInfo(r.Name, r.Author, r.Description, "");  // title, author, subject, company

            //Create a utility object
            pdfUtility = new PdfUtility(anchor);

            //write out the header
            int size = 0;

            tw.Write(pdfUtility.GetHeader("1.5", out size), 0, size);
            //
            filesize = size;
        }
Esempio n. 2
0
        private void AddParameters(Report rpt, IDbConnection cn, IDbCommand cmSQL, bool bValue)
        {
            // any parameters to substitute
            if (this._QueryParameters == null ||
                this._QueryParameters.Items == null ||
                this._QueryParameters.Items.Count == 0 ||
                this._QueryParameters.ContainsArray)            // arrays get handled by AddParametersAsLiterals
            {
                return;
            }

            // AddParametersAsLiterals handles it when there is replacement
            if (RdlEngineConfig.DoParameterReplacement(Provider, cn))
            {
                return;
            }

            foreach (QueryParameter qp in this._QueryParameters.Items)
            {
                string paramName;

                // force the name to start with @
                if (qp.Name.Nm[0] == '@')
                {
                    paramName = qp.Name.Nm;
                }
                else
                {
                    paramName = "@" + qp.Name.Nm;
                }
                object           pvalue = bValue? qp.Value.Evaluate(rpt, null): null;
                IDbDataParameter dp     = cmSQL.CreateParameter();

                dp.ParameterName = paramName;
                if (pvalue is ArrayList)    // Probably a MultiValue Report parameter result
                {
                    ArrayList ar = (ArrayList)pvalue;
                    dp.Value = ar.ToArray(ar[0].GetType());
                }
                else
                {
                    dp.Value = pvalue;
                }
                cmSQL.Parameters.Add(dp);
            }
        }
Esempio n. 3
0
        override internal void Run(IPresent ip, Row row)
        {
            Report rpt = ip.Report();

            ICustomReportItem cri = null;

            try
            {
                cri = RdlEngineConfig.CreateCustomReportItem(_Type);
            }
            catch (Exception ex)
            {
                rpt.rl.LogError(8, string.Format("Exception in CustomReportItem handling.\n{0}\n{1}", ex.Message, ex.StackTrace));
            }
            finally
            {
                if (cri != null)
                {
                    cri.Dispose();
                }
            }
            return;
        }
Esempio n. 4
0
        override internal void FinalPass()
        {
            base.FinalPass();       // this handles the finalpass of the AltReportItems

            // Handle the final pass for the Custom Properties
            if (_Properties != null)
            {
                foreach (CustomProperty cp in _Properties)
                {
                    cp.Name.FinalPass();
                    cp.Value.FinalPass();
                }
            }

            // Find out whether the type is known
            ICustomReportItem cri = null;

            try
            {
                cri = RdlEngineConfig.CreateCustomReportItem(_Type);
            }
            catch (Exception ex)
            {   // Not an error since we'll simply use the ReportItems
                OwnerReport.rl.LogError(4, string.Format("CustomReportItem load of {0} failed: {1}",
                                                         _Type, ex.Message));
            }
            finally
            {
                if (cri != null)
                {
                    cri.Dispose();
                }
            }

            return;
        }
Esempio n. 5
0
        /// <summary>
        /// Content object
        /// </summary>
        /// <summary>
        /// Get the Content Dictionary
        /// </summary>
        internal byte[] GetContentDict(long filePos, out int size)
        {
            // When no compression
            if (!CanCompress)
            {
                content = string.Format("\r\n{0} 0 obj<</Length {1}>>stream\r{2}\rendstream\rendobj\r",
                                        this.objectNum, contentStream.Length, contentStream);

                return(GetUTF8Bytes(content, filePos, out size));
            }

            // Try to use compression; could still fail in which case fall back to uncompressed
            Stream       strm = null;
            MemoryStream cs   = null;

            try
            {
                CompressionConfig cc = RdlEngineConfig.GetCompression();
                cs = new MemoryStream();                        // this will contain the content stream
                if (cc != null)
                {
                    strm = cc.GetStream(cs);
                }

                if (strm == null)
                {                       // can't compress string
                    cs.Close();

                    content = string.Format("\r\n{0} 0 obj<</Length {1}>>stream\r{2}\rendstream\rendobj\r",
                                            this.objectNum, contentStream.Length, contentStream);

                    return(GetUTF8Bytes(content, filePos, out size));
                }

                // Compress the contents
                int    cssize;
                byte[] ca = PdfUtility.GetUTF8Bytes(contentStream, out cssize);
                strm.Write(ca, 0, cssize);
                strm.Flush();
                cc.CallStreamFinish(strm);

                // Now output the PDF command
                MemoryStream ms = new MemoryStream();
                int          s;
                byte[]       ba;

                // get the compressed data;  we need the lenght now
                byte[] cmpData = cc.GetArray(cs);

                // write the beginning portion of the PDF object
                string ws = string.Format("\r\n{0} 0 obj<< /Filter /FlateDecode /Length {1}>>stream\r",
                                          this.objectNum, cmpData.Length);

                ba = GetUTF8Bytes(ws, filePos, out s);                  // this will also register the object
                ms.Write(ba, 0, ba.Length);
                filePos += s;

                // write the Compressed data
                ms.Write(cmpData, 0, cmpData.Length);
                filePos += ba.Length;

                // write the end portion of the PDF object
                ba = PdfUtility.GetUTF8Bytes("\rendstream\rendobj\r", out s);
                ms.Write(ba, 0, ba.Length);
                filePos += s;

                // now the final output array
                ba   = ms.ToArray();
                size = ba.Length;
                return(ba);
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
            }
        }
Esempio n. 6
0
        override internal void RunPage(Pages pgs, Row row)
        {
            Report rpt = pgs.Report;

            if (IsHidden(pgs.Report, row))
            {
                return;
            }

            SetPagePositionBegin(pgs);

            // Build the Chart bitmap, along with data regions
            Page p = pgs.CurrentPage;
            ICustomReportItem cri = null;
            Bitmap            bm  = null;

            try
            {
                cri = RdlEngineConfig.CreateCustomReportItem(_Type);
                SetProperties(pgs.Report, row, cri);

                int width = WidthCalc(rpt, pgs.G) -
                            (Style == null? 0 :
                             (Style.EvalPaddingLeftPx(rpt, row) + Style.EvalPaddingRightPx(rpt, row)));
                int height = Measurement.PixelsFromPoints(this.HeightOrOwnerHeight, Measurement.STANDARD_DPI_Y) -
                             (Style == null? 0 :
                              (Style.EvalPaddingTopPx(rpt, row) + Style.EvalPaddingBottomPx(rpt, row)));
                bm = new Bitmap(width, height);
                cri.DrawImage(bm);

                MemoryStream ostrm = new MemoryStream();
                // 06122007AJM Changed to use high quality JPEG encoding
                //bm.Save(ostrm, IMAGEFORMAT);	// generate a jpeg   TODO: get png to work with pdf
                System.Drawing.Imaging.ImageCodecInfo[] info;
                info = ImageCodecInfo.GetImageEncoders();
                EncoderParameters encoderParameters;
                encoderParameters = new EncoderParameters(1);
                // 20022008 AJM GJL - Using centralised image quality
                encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.CustomImageQuality);
                System.Drawing.Imaging.ImageCodecInfo codec = null;
                for (int i = 0; i < info.Length; i++)
                {
                    if (info[i].FormatDescription == "JPEG")
                    {
                        codec = info[i];
                        break;
                    }
                }
                bm.Save(ostrm, codec, encoderParameters);

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);   // Create an image
                pi.Sizing = ImageSizingEnum.Clip;
//                RunPageRegionBegin(pgs);

                SetPagePositionAndStyle(rpt, pi, row);

                if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                {       // force page break if it doesn't fit on the page
                    pgs.NextOrNew();
                    pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                    if (this.YParents != null)
                    {
                        pi.Y = 0;
                    }
                }

                p = pgs.CurrentPage;

                p.AddObject(pi);        // Put image onto the current page

                //              RunPageRegionEnd(pgs);

                if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                {
                    float newY = pi.Y + pi.H;
                    p.YOffset += newY;  // bump the y location
                }
                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
            catch (Exception ex)
            {
                rpt.rl.LogError(8, string.Format("Exception in CustomReportItem handling: {0}", ex.Message));
            }
            finally
            {
                if (cri != null)
                {
                    cri.Dispose();
                }
            }

            return;
        }
        internal bool ConnectDataSource(Report rpt)
        {
            IDbConnection cn = GetConnection(rpt);

            if (cn != null)
            {
                return(true);
            }

            if (_DataSourceReference != null)
            {
                ConnectDataSourceReference(rpt);        // this will create a _ConnectionProperties
            }
            if (_ConnectionProperties == null ||
                _ConnectionProperties.ConnectstringValue == null)
            {
                return(false);
            }

            bool rc = false;

            try
            {
                cn = RdlEngineConfig.GetConnection(_ConnectionProperties.DataProvider,
                                                   _ConnectionProperties.Connectstring(rpt));
                if (cn != null)
                {
                    cn.Open();
                    rc = true;
                }
            }
            catch (Exception e)
            {
                string err = string.Format("DataSource '{0}'.\r\n{1}", _Name,
                                           e.InnerException == null ? e.Message : e.InnerException.Message);
                if (rpt == null)
                {
                    OwnerReport.rl.LogError(4, err);    // error occurred during parse phase
                }
                else
                {
                    rpt.rl.LogError(4, err);
                }
                if (cn != null)
                {
                    cn.Close();
                    cn = null;
                }
            }

            if (cn != null)
            {
                SetSysConnection(rpt, cn);
            }
            else
            {
                string err = string.Format("Unable to connect to datasource '{0}'.", this._Name.Nm);
                if (rpt == null)
                {
                    OwnerReport.rl.LogError(4, err);    // error occurred during parse phase
                }
                else
                {
                    rpt.rl.LogError(4, err);
                }
            }
            return(rc);
        }
Esempio n. 8
0
        private string AddParametersAsLiterals(Report rpt, IDbConnection cn, string sql, bool bValue)
        {
            // No parameters means nothing to do
            if (this._QueryParameters == null ||
                this._QueryParameters.Items == null ||
                this._QueryParameters.Items.Count == 0)
            {
                return(sql);
            }

            // Only do this for ODBC datasources - AddParameters handles it in other cases
            if (!RdlEngineConfig.DoParameterReplacement(Provider, cn))
            {
                if (!_QueryParameters.ContainsArray)    // when array we do substitution
                {
                    return(sql);
                }
            }

            StringBuilder         sb = new StringBuilder(sql);
            List <QueryParameter> qlist;

            if (_QueryParameters.Items.Count <= 1)
            {
                qlist = _QueryParameters.Items;
            }
            else
            {                   // need to sort the list so that longer items are first in the list
                                // otherwise substitution could be done incorrectly
                qlist = new List <QueryParameter>(_QueryParameters.Items);
                qlist.Sort();
            }

            foreach (QueryParameter qp in qlist)
            {
                string paramName;

                // force the name to start with @
                if (qp.Name.Nm[0] == '@')
                {
                    paramName = qp.Name.Nm;
                }
                else
                {
                    paramName = "@" + qp.Name.Nm;
                }

                // build the replacement value
                string svalue;
                if (bValue)
                {                       // use the value provided
                    svalue = this.ParameterValue(rpt, qp);
                }
                else
                {                       // just need a place holder value that will pass parsing
                    switch (qp.Value.Expr.GetTypeCode())
                    {
                    case TypeCode.Char:
                        svalue = "' '";
                        break;

                    case TypeCode.DateTime:
                        svalue = "'1900-01-01 00:00:00'";
                        break;

                    case TypeCode.Decimal:
                    case TypeCode.Double:
                    case TypeCode.Int32:
                    case TypeCode.Int64:
                        svalue = "0";
                        break;

                    case TypeCode.Boolean:
                        svalue = "'false'";
                        break;

                    case TypeCode.String:
                    default:
                        svalue = "' '";
                        break;
                    }
                }
                sb.Replace(paramName, svalue);
            }
            return(sb.ToString());
        }