Exemplo n.º 1
0
        public void Draw(Graphics g, PointF location, ReportRuntime rptRuntime, RectangleF backRect, bool isExport = false, Extension ext = null)
        {
            if (null == _Tag || null == rptRuntime)
            {
                return;
            }
            try {
                if (location.X < 0)
                {
                    location.X = backRect.Location.X;
                }
                if (location.Y < 0)
                {
                    location.Y = backRect.Location.Y;
                }
                Canvas DraqCanvas = new Canvas(g);
                string realText   = Text;
                if (_Tag is PmsLabel)
                {
                    //需要二次计算的带页参数的报表元素(页码等)
                    string str = (_Tag as IExpression).Expression;
                    if ((str.IndexOf("PageIndex") >= 0 || str.IndexOf("PageCount") >= 0))
                    {
                        object o = rptRuntime.ExpressionEngine.Execute(str, rptRuntime.DataTables, "");
                        if (o != null)
                        {
                            realText = Convert.ToString(o);
                        }
                    }
                    else
                    {
                        str = Text.ToLower();
                        if (!string.IsNullOrEmpty(str) && (str.IndexOf("[#pageindex#]") >= 0 || str.IndexOf("[#pageCount#]") >= 0))
                        {
                            object objVisible = rptRuntime.ExpressionEngine.ExcuteBindText(Text, rptRuntime.DataTables, "");
                            if (objVisible != null)
                            {
                                realText = Convert.ToString(objVisible);
                            }
                        }
                    }
                }
                else if (_Tag is IVisibleExpression)
                {
                    string str = (_Tag as IVisibleExpression).VisibleExpression;
                    if (!string.IsNullOrEmpty(str) && ((str.IndexOf("PageIndex") >= 0 || str.IndexOf("PageCount") >= 0)))
                    {
                        object o = rptRuntime.ExpressionEngine.Execute(str, rptRuntime.DataTables, "");
                        if (o != null)
                        {
                            bool bVisible = Convert.ToBoolean(o);
                            if (!bVisible)
                            {
                                return;
                            }
                        }
                    }
                }
                float dpiZoom = 1.0f;
                if (null != _Page && null != _Page.PageManager)
                {
                    dpiZoom = g.DpiX / _Page.PageManager.ReportConfigDpiX;
                }

                if (_Tag is ICell)
                {
                    ICell cell = _Tag as ICell;
                    cell.RealText = realText;
                    if (_Parameter != null)
                    {
                        cell.Style = _Parameter as PMS.Libraries.ToolControls.MESTable.CellStyles.Style;
                    }
                    //todo: qiuleilei
                    if (CurrentPrjInfo.CurrentEnvironment == MESEnvironment.MESReportServer && cell.Style != null)
                    {
                        var ff = FontFamily.Families.FirstOrDefault((f) => f.Name == "宋体");
                        if (ff == null)
                        {
                            cell.Style.Font = SystemFonts.DefaultFont;                            //ff = FontFamily.Families.FirstOrDefault((f)=> f.Name.Contains("Sans"));
                        }
                        if (ff != null)
                        {
                            cell.Style.Font = new Font(ff, 9.0f, FontStyle.Regular);
                        }
                    }
                    cell.Width  = SizeConversion.ConvertInchesToPixel(_Width, backRect.Width - location.X, g.DpiX);
                    cell.Height = SizeConversion.ConvertInchesToPixel(_Height, backRect.Height - location.Y + backRect.Y, g.DpiY);
                    cell.DirectDraw(DraqCanvas, location.X, location.Y, dpiZoom);
                }
                else if (_Tag is IChartElement)
                {
                    IChartElement curve = _Tag as IChartElement;
                    //if (curve is IBindDataTableManager)
                    //{
                    //    (curve as IBindReportExpressionEngine).ExpressionEngine = rptRuntime.ExpressionEngine;
                    //    (curve as IBindDataTableManager).BindDataTableManager(rptRuntime.DataTables, realText);
                    //}
                    curve.Width  = (int)SizeConversion.ConvertInchesToPixel(_Width, backRect.Width - location.X, g.DpiX);
                    curve.Height = (int)SizeConversion.ConvertInchesToPixel(_Height, backRect.Height - location.Y + backRect.Y, g.DpiY);
                    if (curve is Control)
                    {
                        (curve as Control).Width  = curve.Width;
                        (curve as Control).Height = curve.Height;
                    }
                    curve.DirectDraw(DraqCanvas, location.X, location.Y, dpiZoom);
                }
                else if (_Tag is SectionChart)
                {
                    SectionChart curve = _Tag as SectionChart;
                    //if (curve is IBindDataTableManager)
                    //{
                    //    (curve as IBindReportExpressionEngine).ExpressionEngine = rptRuntime.ExpressionEngine;
                    //    (curve as IBindDataTableManager).BindDataTableManager(rptRuntime.DataTables, realText);
                    //}
                    (curve as IElementExtended).Width  = (int)SizeConversion.ConvertInchesToPixel(_Width, backRect.Width - location.X, g.DpiX);
                    (curve as IElementExtended).Height = (int)SizeConversion.ConvertInchesToPixel(_Height, backRect.Height - location.Y + backRect.Y, g.DpiY);
                    if (curve is Control)
                    {
                        (curve as Control).Width  = (curve as IElementExtended).Width;
                        (curve as Control).Height = (curve as IElementExtended).Height;
                    }
                    curve.DirectDraw(DraqCanvas, location.X, location.Y, dpiZoom);
                }
                else if (_Tag is IDirectDrawable)
                {
                    if (_Tag is IElementContent)
                    {
                        (_Tag as IElementContent).RealText = realText;
                    }
                    if (_Tag is IElement)
                    {
                        (_Tag as IElement).Width  = (int)SizeConversion.ConvertInchesToPixel(_Width, backRect.Width - location.X, g.DpiX);
                        (_Tag as IElement).Height = (int)SizeConversion.ConvertInchesToPixel(_Height, backRect.Height - location.Y + backRect.Y, g.DpiY);
                    }
                    (_Tag as IDirectDrawable).DirectDraw(DraqCanvas, location.X, location.Y, dpiZoom);
                }
                //todo:qiuleilei
                if (isExport && CurrentPrjInfo.CurrentEnvironment == MESEnvironment.MESReportServer && ext != null)
                {
                    ext.ToHtml(Page, rptRuntime, _Tag, location, SizeConversion.ConvertInchesToPixel(_Width, backRect.Width - location.X, g.DpiX), SizeConversion.ConvertInchesToPixel(_Height, backRect.Height - location.Y + backRect.Y, g.DpiY));
//					if (_Tag != null && _Tag is Control) {
//						(_Tag as Control).Dispose ();
//						_Tag = null;
//					}
                }
            } catch (System.Exception ex) {
                if (_Tag is IElement)
                {
                    rptRuntime.AddReportLog(ex, (_Tag as IElement).Name);
                }
                else
                {
                    rptRuntime.AddReportLog(ex);
                }
            }
        }