예제 #1
0
        /// <summary>
        /// 根据类型创建报表对象。
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dispText"></param>
        /// <returns></returns>
        public static DIYReport.Interface.IRptSingleObj CreateObj(DIYReport.ReportModel.RptObjType pType, string dispText)
        {
            DIYReport.Interface.IRptSingleObj obj = null;
            switch (pType)
            {
            case DIYReport.ReportModel.RptObjType.Line:
                obj = new DIYReport.ReportModel.RptObj.RptLine(null);
                break;

            case DIYReport.ReportModel.RptObjType.Rect:
                obj = new DIYReport.ReportModel.RptObj.RptRect(null);
                break;

            case DIYReport.ReportModel.RptObjType.Text:
                obj = new DIYReport.ReportModel.RptObj.RptLable(null, dispText);
                break;

            case DIYReport.ReportModel.RptObjType.Express:
                obj = new DIYReport.ReportModel.RptObj.RptExpressBox(null, dispText);
                break;

            case DIYReport.ReportModel.RptObjType.Image:
                obj = new DIYReport.ReportModel.RptObj.RptPictureBox(null);
                break;

            case DIYReport.ReportModel.RptObjType.FieldImage:
                obj = new DIYReport.ReportModel.RptObj.RptDBPictureBox(null);
                break;

            case DIYReport.ReportModel.RptObjType.CheckBox:
                obj = new DIYReport.ReportModel.RptObj.RptCheckBox(null);
                break;

            case DIYReport.ReportModel.RptObjType.BarCode:
                obj = new DIYReport.ReportModel.RptObj.RptBarCode(null);
                break;

            case DIYReport.ReportModel.RptObjType.SubReport:
                obj = new DIYReport.ReportModel.RptObj.RptSubReport(null);
                break;

            case DIYReport.ReportModel.RptObjType.FieldTextBox:
                obj = new DIYReport.ReportModel.RptObj.RptFieldTextBox(null);
                break;

            case DIYReport.ReportModel.RptObjType.HViewSpecField:
                obj = new DIYReport.ReportModel.RptObj.RptHViewSpecFieldBox(null);
                break;

            case DIYReport.ReportModel.RptObjType.RichTextBox:
                obj = new DIYReport.ReportModel.RptObj.RptRichTextBox(null);
                break;

            default:
                Debug.Assert(false, "该控件类型目前还没有处理!", "");
                return(null);
            }
            return(obj);
        }
예제 #2
0
        //画文本对象
        private void drawTextObj(Graphics g, DIYReport.Interface.IRptSingleObj pObj, DataRow pDRow)
        {
            DIYReport.Interface.IRptTextObj textObj = pObj as DIYReport.Interface.IRptTextObj;
            StringFormat strFormat = new StringFormat();
            SolidBrush   foreBrush = new SolidBrush(pObj.ForeColor);

            if (textObj.WordWrap == false)
            {
                strFormat.Trimming    = StringTrimming.EllipsisCharacter;
                strFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit;
            }
            else
            {
                strFormat.FormatFlags = StringFormatFlags.LineLimit;
            }
            strFormat.Alignment = textObj.Alignment;
            RectangleF strRect    = RealRectangle(textObj);
            SizeF      fontSize   = g.MeasureString("A", textObj.Font);
            float      fontFirstY = strRect.Y + (textObj.Size.Height - fontSize.Height) / 2;

            strRect.Y = fontFirstY;
            if (textObj.Type == DIYReport.ReportModel.RptObjType.Text)
            {
                DIYReport.ReportModel.RptObj.RptLable lab = pObj as DIYReport.ReportModel.RptObj.RptLable;
                if (lab.Text != null)
                {
                    g.DrawString(lab.Text, lab.Font, foreBrush, strRect, strFormat);
                }
            }
            else
            {
                //如果绑定的不是文本而是字段、表达式或者系统参数等,那么就需要对它进行解释并绘制它
                string val = "";
                DIYReport.ReportModel.RptObj.RptExpressBox box = pObj as DIYReport.ReportModel.RptObj.RptExpressBox;
                if (box.DataSource != null && box.DataSource != "" && box.DataSource != "[未绑定]")
                {
                    switch (box.ExpressType)
                    {
                    case ReportModel.ExpressType.Express:
                        int beginIndex = 0, endIndex = 0;
                        if (box.Section.SectionType == DIYReport.SectionType.ReportBottom)                                 //统计的字段在报表脚,那么是统计所有的行
                        {
                            beginIndex = 0;
                            endIndex   = _Rows.Length;
                        }
                        else if (box.Section.SectionType == DIYReport.SectionType.PageFooter)                                //统计的字段在页脚,那么是统计当前页所有的行
                        {
                            beginIndex = _HasDrawRowCount - _RowPoint;
                            endIndex   = _HasDrawRowCount;
                        }
                        else if (box.Section.SectionType == DIYReport.SectionType.GroupFooter)                                //统计的字段在分组的脚,那么统计分组涉及到的行
                        {
                            DIYReport.Print.DrawGroupField groupField = _DrawDetailInfo.GetGroupFieldByName(box.Section.GroupField.FieldName);
                            beginIndex = groupField.PrevFirstRowIndex;
                            endIndex   = _HasDrawRowCount;
                        }
                        else
                        {
                            //g.DrawString("不支持的表达式",box.Font,foreBrush,strRect,strFormat);
                            g.DrawString(string.Empty, box.Font, foreBrush, strRect, strFormat);
                            break;
                        }
                        val = DIYReport.Express.ExStatistical.GetStatisticalValue(beginIndex, endIndex - 1, box.DataSource, box.BingDBFieldName, _Rows);
                        if (val == null)
                        {
                            val = " ";
                        }
                        double dval = DIYReport.PublicFun.ToDouble(val);
                        if (box.FormatStyle != null && box.FormatStyle != "")
                        {
                            try{
                                //val = String.Format(box.FormatStyle,dval);
                                val = DIYReport.PublicFun.FormatString(box.FormatStyle.Trim(), dval);
                            }
                            catch {}
                        }
                        g.DrawString(val, box.Font, foreBrush, strRect, strFormat);
                        break;

                    case ReportModel.ExpressType.SysParam:                               //系统参数
                        Type       clsType = System.Type.GetType("DIYReport.Express.ExSpecial");
                        MethodInfo meth    = clsType.GetMethod(box.DataSource);
                        if (meth != null)
                        {
                            object speTxt = meth.Invoke(clsType, null);
                            val = speTxt.ToString();
                        }
                        g.DrawString(val, box.Font, foreBrush, strRect, strFormat);
                        break;

                    case ReportModel.ExpressType.UserParam:                             //用户外部参数
                        DIYReport.ReportModel.RptParam param = DIYReport.UserDIY.DesignEnviroment.CurrentReport.UserParamList[box.DataSource];
                        if (param != null)
                        {
                            g.DrawString(param.Value.ToString(), box.Font, foreBrush, strRect, strFormat);
                        }
                        break;

                    case ReportModel.ExpressType.Field:                             //用户绑定字段
//							string str = "";
//							if(pDRow!=null)
//								str = pDRow[box.DataSource].ToString();
//							g.DrawString(str,box.Font ,foreBrush,RealRectangle(box) ,strFormat);
                        DrawField(g, pDRow, box, foreBrush, strRect, strFormat);
                        break;

                    default:
                        break;
                    }
                }
            }
            if (textObj.ShowFrame == true)
            {
                drawRect(g, pObj);
            }
        }
예제 #3
0
        private void fillInfoToRptObj(DIYReport.Interface.IRptSingleObj pRptObj, XmlNode pNode)
        {
            int x = PublicFun.ToInt(pNode.Attributes["Location-X"].Value);
            int y = PublicFun.ToInt(pNode.Attributes["Location-Y"].Value);

            pRptObj.Location = new Point(x, y);
            int width  = PublicFun.ToInt(pNode.Attributes["Size-Width"].Value);
            int height = PublicFun.ToInt(pNode.Attributes["Size-Height"].Value);

            pRptObj.Size      = new Size(width, height);
            pRptObj.LinePound = PublicFun.ToInt(pNode.Attributes["LinePound"].Value);
            if (pNode.Attributes["LineStyle"] != null)
            {
                int lineStyle = PublicFun.ToInt(pNode.Attributes["LineStyle"].Value);
                pRptObj.LineStyle = (System.Drawing.Drawing2D.DashStyle)lineStyle;
            }
            else
            {
                pRptObj.LineStyle = System.Drawing.Drawing2D.DashStyle.Solid;
            }
            pRptObj.BackgroundColor = Color.FromArgb(PublicFun.ToInt(pNode.Attributes["BackgroundColor"].Value));
            pRptObj.ForeColor       = Color.FromArgb(PublicFun.ToInt(pNode.Attributes["ForeColor"].Value));
            switch (pRptObj.Type)
            {
            case DIYReport.ReportModel.RptObjType.Line:
                DIYReport.ReportModel.RptObj.RptLine line = pRptObj as  DIYReport.ReportModel.RptObj.RptLine;
                if (pNode.Attributes["LineType"] != null)
                {
                    line.LineType = (DIYReport.ReportModel.LineType) int.Parse(pNode.Attributes["LineType"].Value);
                }
                break;

            case DIYReport.ReportModel.RptObjType.Text:
            case DIYReport.ReportModel.RptObjType.Express:
                //如果是文本对象,需要加载字体的颜色、形状
                DIYReport.Interface.IRptTextObj txt = pRptObj as DIYReport.Interface.IRptTextObj;
                txt.WordWrap = bool.Parse(pNode.Attributes["WordWrap"].Value);
                string sLimg = pNode.Attributes["Alignment"].Value;
                //得到字符对齐方式  //由于早期的报表是存储字符的,为了保持兼容性,也采取这种存储方式
                if (sLimg == "Near")
                {
                    txt.Alignment = StringAlignment.Near;
                }
                else if (sLimg == "Center")
                {
                    txt.Alignment = StringAlignment.Center;
                }
                else
                {
                    txt.Alignment = StringAlignment.Far;
                }

                txt.ShowFrame = bool.Parse(pNode.Attributes["ShowFrame"].Value);
                if (pNode.Attributes["FormatStyle"] != null)
                {
                    txt.FormatStyle = pNode.Attributes["FormatStyle"].Value;
                }
                string    fontName  = pNode.Attributes["Font-FamilyName"].Value;
                float     fontSize  = PublicFun.ToFloat(pNode.Attributes["Font-Size"].Value);
                bool      bold      = bool.Parse(pNode.Attributes["Font-Bold"].Value);
                bool      underline = bool.Parse(pNode.Attributes["Font-Underline"].Value);
                bool      italic    = bool.Parse(pNode.Attributes["Font-Italic"].Value);
                bool      strikeout = bool.Parse(pNode.Attributes["Font-Strikeout"].Value);
                FontStyle fontType  = FontStyle.Regular;
                //通过位运算得到字符stype 靠!怎么会采取这种存储方式呢,看来晚上是不能写的太晚~~~~~~~~
                if (bold)
                {
                    fontType = fontType | FontStyle.Bold;
                }
                if (underline)
                {
                    fontType = fontType | FontStyle.Underline;
                }
                if (italic)
                {
                    fontType = fontType | FontStyle.Italic;
                }


                Font f    = new Font(fontName, fontSize);
                Font font = new Font(f, fontType);
                txt.Font = font;
                if (txt.Type == DIYReport.ReportModel.RptObjType.Text)
                {
                    if (pNode.Attributes["Text"] != null)
                    {
                        DIYReport.ReportModel.RptObj.RptLable lab = txt as DIYReport.ReportModel.RptObj.RptLable;
                        lab.Text = pNode.Attributes["Text"].Value;
                    }
                }
                else
                {
                    DIYReport.ReportModel.RptObj.RptExpressBox box = txt as DIYReport.ReportModel.RptObj.RptExpressBox;
                    if (pNode.Attributes["ExpressType"] != null)
                    {
                        int exType = int.Parse(pNode.Attributes["ExpressType"].Value);
                        box.ExpressType = (DIYReport.ReportModel.ExpressType)exType;
                    }
                    if (pNode.Attributes["DataSource"] != null)
                    {
                        box.DataSource = pNode.Attributes["DataSource"].Value;
                    }
                    if (pNode.Attributes["FieldName"] != null)
                    {
                        box.FieldName = pNode.Attributes["FieldName"].Value;
                    }
                }
                break;

            case DIYReport.ReportModel.RptObjType.Image:
                DIYReport.ReportModel.RptObj.RptPictureBox pic = pRptObj as DIYReport.ReportModel.RptObj.RptPictureBox;
                //处理图片
                ReadRptImage(pic);
                break;

            default:
                break;
            }
        }
예제 #4
0
        private string rptObjString(DIYReport.Interface.IRptSingleObj pRptObj)
        {
            StringBuilder xmlSB = new StringBuilder();

            xmlSB.Append("<RptObj Name = '" + pRptObj.Name + "'");
            xmlSB.Append(" Type = '" + ((int)pRptObj.Type).ToString() + "'");
            xmlSB.Append(" Location-X='" + pRptObj.Location.X.ToString() + "'");
            xmlSB.Append(" Location-Y='" + pRptObj.Location.Y.ToString() + "'");
            xmlSB.Append(" Size-Width='" + pRptObj.Size.Width.ToString() + "'");
            xmlSB.Append(" Size-Height='" + pRptObj.Size.Height.ToString() + "'");
            xmlSB.Append(" LinePound ='" + pRptObj.LinePound.ToString() + "'");
            xmlSB.Append(" LineStyle ='" + ((int)pRptObj.LineStyle).ToString() + "'");
            xmlSB.Append(" BackgroundColor ='" + pRptObj.BackgroundColor.ToArgb().ToString() + "'");
            xmlSB.Append(" ForeColor ='" + pRptObj.ForeColor.ToArgb().ToString() + "'");
            switch (pRptObj.Type)
            {
            case DIYReport.ReportModel.RptObjType.Line:
                DIYReport.ReportModel.RptObj.RptLine obj = pRptObj as  DIYReport.ReportModel.RptObj.RptLine;
                xmlSB.Append(" LineType ='" + ((int)obj.LineType).ToString() + "'");
                break;

            case DIYReport.ReportModel.RptObjType.Rect:
                break;

            case DIYReport.ReportModel.RptObjType.Text:
            case DIYReport.ReportModel.RptObjType.Express:
                DIYReport.Interface.IRptTextObj txt = pRptObj as DIYReport.Interface.IRptTextObj;
                xmlSB.Append(" WordWrap ='" + txt.WordWrap.ToString() + "'");
                xmlSB.Append(" Alignment ='" + txt.Alignment.ToString() + "'");
                xmlSB.Append(" ShowFrame ='" + txt.ShowFrame.ToString() + "'");
                xmlSB.Append(" FormatStyle ='" + txt.FormatStyle + "'");

                xmlSB.Append(" Font-Bold='" + txt.Font.Bold.ToString() + "'");
                xmlSB.Append(" Font-FamilyName='" + txt.Font.FontFamily.Name + "'");
                xmlSB.Append(" Font-Underline='" + txt.Font.Underline.ToString() + "'");
                xmlSB.Append(" Font-Italic='" + txt.Font.Italic.ToString() + "'");
                xmlSB.Append(" Font-Strikeout='" + txt.Font.Strikeout.ToString() + "'");
                xmlSB.Append(" Font-Size='" + txt.Font.Size.ToString() + "'");

                if (txt.Type == DIYReport.ReportModel.RptObjType.Text)
                {
                    DIYReport.ReportModel.RptObj.RptLable lab = txt as DIYReport.ReportModel.RptObj.RptLable;
                    if (lab.Text != null && lab.Text.Trim() != "")
                    {
                        xmlSB.Append(" Text ='" + lab.Text + "'");
                    }
                }
                else
                {
                    DIYReport.ReportModel.RptObj.RptExpressBox box = txt as DIYReport.ReportModel.RptObj.RptExpressBox;
                    if (box.DataSource != null && box.DataSource.Trim() != "")
                    {
                        xmlSB.Append(" DataSource ='" + box.DataSource.Trim() + "'");
                    }
                    if (box.FieldName != null && box.FieldName.Trim() != "")
                    {
                        xmlSB.Append(" FieldName ='" + box.FieldName.Trim() + "'");
                    }
                    xmlSB.Append(" ExpressType ='" + ((int)box.ExpressType).ToString() + "'");
                }
                break;

            case DIYReport.ReportModel.RptObjType.Image:
                DIYReport.ReportModel.RptObj.RptPictureBox pic = pRptObj as DIYReport.ReportModel.RptObj.RptPictureBox;
                //等待处理图片
                SaveRptImage(pic);
                break;

            default:
                break;
            }
            xmlSB.Append(">");
            //write end rptObj
            xmlSB.Append("</RptObj>");
            return(xmlSB.ToString());
        }