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; } }
//加载RptReport 的数据 private DIYReport.ReportModel.RptReport createReportData(XmlNode pReportNode) { DIYReport.ReportModel.RptReport report = new DIYReport.ReportModel.RptReport(); report.Name = pReportNode.Attributes["Name"].Value; //存储当前处理的报表的名称 //nick add 2005-11-28 为了处理导入导出而增加的。 if (_RptID == Guid.Empty) { if (pReportNode.Attributes["ID"] != null) { string id = pReportNode.Attributes["ID"].Value; _RptID = new System.Guid(id); } } report.ID = _RptID; _ReportName = report.Name; if (pReportNode.Attributes["Text"] != null) { report.Text = pReportNode.Attributes["Text"].Value; } if (pReportNode.Attributes["DetailOrderString"] != null) { report.DetailOrderString = pReportNode.Attributes["DetailOrderString"].Value; } if (pReportNode.Attributes["GroupLayoutType"] != null) { report.GroupLayoutType = (DIYReport.ReportModel.GroupLayoutType)PublicFun.ToInt(pReportNode.Attributes["GroupLayoutType"].Value); } int width = PublicFun.ToInt(pReportNode.Attributes["Width"].Value); int height = PublicFun.ToInt(pReportNode.Attributes["Height"].Value); if (pReportNode.Attributes["PrintName"] != null) { report.PrintName = pReportNode.Attributes["PrintName"].Value; } //bool isCustom = false; if (pReportNode.Attributes["PaperName"] != null) { string pageName = pReportNode.Attributes["PaperName"].Value; PaperSize size = DIYReport.Print.RptPageSetting.GetSizeByFullInfo(report.PrintDocument, report.PrintName, pageName, width, height); //new PaperSize(pageName,width,height); if (size != null) { if (size.Kind == PaperKind.Custom) { try{ //pagersize 的大小是不能进行修改的。 size.Width = width; size.Height = height; } catch { } //isCustom = true; } //MyCDC // PaperSize size = DIYReport.Print.RptPageSetting.GetPaperSizeByName(report.PrintDocument,"MyCDC"); //new PaperSize(pageName,width,height); // if(size.Kind == PaperKind.Custom){ // size.Width = 200; // size.Height = 400; // }//MyCDC report.PaperSize = size; } } //if(report.PrintName==null || report.PrintName.Length ==0) report.PrintName = report.PrintDocument.PrinterSettings.PrinterName; report.IsLandscape = bool.Parse(pReportNode.Attributes["IsLandscape"].Value); report.FillNULLRow = bool.Parse(pReportNode.Attributes["FillNULLRow"].Value); int left = PublicFun.ToInt(pReportNode.Attributes["Margins-Left"].Value); int top = PublicFun.ToInt(pReportNode.Attributes["Margins-Top"].Value); int right = PublicFun.ToInt(pReportNode.Attributes["Margins-Right"].Value); int bottom = PublicFun.ToInt(pReportNode.Attributes["Margins-Bottom"].Value); Margins m = new Margins(left, right, top, bottom); report.Margins = m; PageSettings setting = new PageSettings(); setting.Margins = m; setting.Landscape = report.IsLandscape; setting.PaperSize = report.PaperSize; report.PrintDocument.DefaultPageSettings = setting; //report.PrintDocument.PrinterSettings.DefaultPageSettings = setting; // if(isCustom){ // DIYReport.Print.MyPrinterSettings.ChangeSetting(report.PrintDocument,"Microsoft Office Document Image Writer",System.Convert.ToInt16(width),System.Convert.ToInt16(height)); // } //report.PrintDocument.PrinterSettings.PrinterName = setting.PrinterSettings.PrinterName; // createSection(report, pReportNode.ChildNodes); return(report); }