public bool IsLandscape() { float max_right = 0; foreach (repPage page in repPages) { foreach (itemInfo item in page.Report.Items) { float left = item.left * 10; float width = item.width * 10; if (left + width > max_right) { textInfo ti = item as textInfo; if (ti == null || ti.border == null || ti.border[1] != 0 || ti.border[2] != 0 || ti.border[3] != 0 || !Common.IsNullOrEmpty(ti.Value) ) { max_right = left + width; } } } } return(max_right > 200); }
public void AppendReportInfo(string filename, string caption, string tooltip, int count, IFormattable dat, Dictionary <string, Image> imagelist) { image_dir = ""; if (File.Exists(filename)) { try { image_dir = Path.GetDirectoryName(filename); reportInfo ri = xc.Read <reportInfo>(filename); ri.Tootip = tooltip; AppendReportInfo(ri, caption, count, dat, imagelist); } catch (Exception ex) { errors += string.Format("Ошибка в файле {0},\nшаблоне {1},\n [{2}]\n ", filename, caption, Common.ExMessage(ex)); } } else { errors += string.Format("Файл с шаблоном отчета {0} не найден\n", filename); } if (errors != "") { reportInfo ri = new reportInfo(); if (Common.IsNullOrEmpty(caption)) { caption = filename.Substring(filename.LastIndexOf(@"\")).Replace(@"\", ""); } textInfo ii = new textInfo(); ii.width = 20; ii.height = 40; ii.Value = errors; ri.Items = new itemInfo[] { ii }; AppendReportInfo(ri, caption, count, dat, imagelist); errors = ""; } }
string CreateGraphicsRI(Graphics g, reportInfo report) { if (repPages.Count == 0) { return("Формат документа не задан !"); } string error = ""; int counter = 0; PointF offset = new PointF(0, 0); foreach (itemInfo item in report.Items) { counter++; try { float left = item.left * 10; float top = item.top * 10; float width = item.width * 10; float height = item.height * 10; RectangleF rect = new RectangleF(left, top, width, height); string value = item.Value; StringFormat frmt = new StringFormat(); frmt.Trimming = StringTrimming.None; Color foreColor = Color.Black; Color backColor = Color.White; if (item is imgInfo) { imgInfo ii = item as imgInfo; foreColor = GetColor(ii.forecolor, Color.Black); Brush fore_brush = new SolidBrush(foreColor); backColor = GetColor(ii.backcolor, Color.White); Brush back_brush = new SolidBrush(backColor); if (backColor != Color.White) { g.FillRectangle(back_brush, rect); } string font_name = Common.IsNullOrEmpty(ii.fontname) ? "Arial" : ii.fontname; float font_size = ii.fontsize; if (font_size == 0) { font_size = 9; } FontStyle style = FontStyle.Regular; if (ii.fontbold) { style |= FontStyle.Bold; } if (ii.fontitalic) { style |= FontStyle.Italic; } if (ii.fontunderline) { style |= FontStyle.Underline; } Font font = new Font(font_name, font_size, style, GraphicsUnit.Point); frmt.Alignment = GetStringAlignment(ii.align); if (!Common.IsNullOrEmpty(value)) { try { RectangleF new_rect = new RectangleF(rect.Location, rect.Size); if (value.StartsWith(BARCODEKEYSTRING)) { string barcode = value.Substring(BARCODEKEYSTRING.Length); BarCode.DrawBarCodeFromString(barcode, g, new_rect); } else { Image img = Image.FromStream(new MemoryStream(Convert.FromBase64String(value))); if (ii.valign == valignType.Center) { new_rect.Offset(0, rect.Height / 2 - img.Height); } else if (ii.valign == valignType.Bottom) { new_rect.Offset(0, rect.Height - img.Height); } g.DrawImage(img, new_rect); } } catch (Exception exp) { string exp_str = exp.Message; } } } else if (item is textInfo) { textInfo ti = item as textInfo; foreColor = GetColor(ti.forecolor, Color.Black); backColor = GetColor(ti.backcolor, Color.White); Brush fore_brush = new SolidBrush(foreColor); Brush back_brush = new SolidBrush(backColor); if (backColor != Color.White) { g.FillRectangle(back_brush, rect); } string font_name = Common.IsNullOrEmpty(ti.fontname) ? "Arial" : ti.fontname; float font_size = ti.fontsize; if (font_size == 0) { font_size = 9; } FontStyle style = FontStyle.Regular; if (ti.fontbold) { style |= FontStyle.Bold; } if (ti.fontitalic) { style |= FontStyle.Italic; } if (ti.fontunderline) { style |= FontStyle.Underline; } Font font = new Font(font_name, font_size, style, GraphicsUnit.Point); if (ti.nowrap) { frmt.FormatFlags = StringFormatFlags.NoWrap; } frmt.Alignment = GetStringAlignment(ti.align); if (ti.bordercolor != null) { Color bclrLeft = GetColor(ti.bordercolor[0], Color.Black); Color bclrTop = GetColor(ti.bordercolor[1], Color.Black); Color bclrRight = GetColor(ti.bordercolor[2], Color.Black); Color bclrBottom = GetColor(ti.bordercolor[3], Color.Black); float bwidthLeft = ti.border[0]; float bwidthTop = ti.border[1]; float bwidthRight = ti.border[2]; float bwidthBottom = ti.border[3]; if (bwidthLeft != 0) { g.DrawLine(GetPen(bclrLeft, bwidthLeft), rect.X, rect.Y, rect.X, rect.Y + rect.Height); } if (bwidthTop != 0) { g.DrawLine(GetPen(bclrTop, bwidthTop), rect.X, rect.Y, rect.X + rect.Width, rect.Y); } if (bwidthRight != 0) { g.DrawLine(GetPen(bclrRight, bwidthRight), rect.X + rect.Width, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); } if (bwidthBottom != 0) { g.DrawLine(GetPen(bclrBottom, bwidthBottom), rect.X, rect.Y + rect.Height, rect.X + rect.Width, rect.Y + rect.Height); } } frmt.LineAlignment = GetStringAlignment(ti.valign); SizeF textsize = g.MeasureString(value, font); g.DrawString(value, font, fore_brush, rect, frmt); } else if (item is checkInfo) { checkInfo ci = item as checkInfo; RectangleF ch = new RectangleF(rect.X + 1.3f, rect.Y + (rect.Height - 2.6f) / 2, 2.6f, 2.6f); Brush fore_brush = new SolidBrush(Color.Black); Brush back_brush = new SolidBrush(Color.White); g.FillRectangle(back_brush, ch.X, ch.Y, ch.Width, ch.Height); g.DrawRectangle(new Pen(fore_brush, 0.2f), ch.X, ch.Y, ch.Width, ch.Height); if (value == "1" || value.ToUpper() == "TRUE") { g.FillRectangle(fore_brush, ch.X + 0.5f, ch.Y + 0.5f, 1.6f, 1.6f); } } } catch (Exception exp) { error += "(строка " + counter.ToString() + "): " + exp.Message + "\n" + ((exp.InnerException == null) ? "" : exp.InnerException.Message) + ";\n"; } } return(error); }