示例#1
0
        List <repPage> CreatePages(reportInfo ri, string caption, int count)
        {
            List <repPage>  ret = new List <repPage>();
            List <itemInfo> lst = new List <itemInfo>();

            Array.Sort <itemInfo>(ri.Items, RepItemComparer);
            itemInfo[] footer = Array.FindAll <itemInfo>(ri.Items, delegate(itemInfo i) { return(!Common.IsNullOrEmpty(i.group) && i.group == FOOTER); });
            itemInfo[] header = Array.FindAll <itemInfo>(ri.Items, delegate(itemInfo i) { return(!Common.IsNullOrEmpty(i.group) && i.group == HEADER); });
            if (footer.Length == 0)
            {
                ret.Add(new repPage(ri, count, true));
                return(ret);
            }
            float offset = 0;

            if (Common.IsNullOrEmpty(caption))
            {
                caption = ri.name;
            }
            foreach (itemInfo item in ri.Items)
            {
                if (Array.IndexOf(footer, item) >= 0 /* || Array.IndexOf(header, item) >= 0*/)
                {
                    continue;
                }
                if (Array.IndexOf(header, item) >= 0)
                {
                    lst.AddRange(CloneBlock(header, ret.Count + 1));
                }
                else
                {
                    if (item.top + item.height - offset > footer[0].top)
                    {
                        lst.AddRange(CloneBlock(footer, ret.Count + 1));
                        ret.Add(new repPage(new reportInfo(string.Format("{0} (стр.{1})", caption, ret.Count + 1)), count, true));
                        ret[ret.Count - 1].Report.Items = lst.ToArray();
                        lst    = new List <itemInfo>();
                        offset = item.top;
                        if (header.Length > 0)
                        {
                            offset -= header[0].top + header[header.Length - 1].top + header[header.Length - 1].height;
                            lst.AddRange(CloneBlock(header, ret.Count + 1));
                        }
                    }
                    item.top -= offset;
                    lst.Add(item);
                }
            }
            if (lst.Count > 0)
            {
                lst.AddRange(CloneBlock(footer, ret.Count + 1));
                ret.Add(new repPage(new reportInfo(string.Format("{0} (стр.{1})", caption, ret.Count + 1)), count, true));
                ret[ret.Count - 1].Report.Items = lst.ToArray();
            }
            return(ret);
        }
示例#2
0
 public void AppendReportInfo(XmlDocument xml, string caption, int count, IFormattable dat, Dictionary <string, Image> imagelist)
 {
     try
     {
         reportInfo ri = xc.Deserialize(typeof(reportInfo), xml.DocumentElement.OuterXml) as reportInfo;
         AppendReportInfo(ri, caption, count, dat, imagelist);
     }
     catch (Exception ex)
     {
         errors += string.Format("Ошибка в шаблоне {0}, [{2}]\n ", caption, ex.Message);
     }
 }
示例#3
0
        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 = "";
            }
        }
示例#4
0
        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);
        }
示例#5
0
 public repPage(reportInfo ri, int count, bool isprint)
 {
     Report  = ri;
     Count   = count;
     IsPrint = isprint;
 }
示例#6
0
        public void AppendReportInfo(reportInfo ri, string caption, int count, IFormattable dat, Dictionary <string, Image> imagelist)
        {
            Array.Sort <itemInfo>(ri.Items, RepItemComparer);
            ri.Items = AppendGroups(ri.Items, dat);
            if (Common.IsNullOrEmpty(ri.name) || !Common.IsNullOrEmpty(caption))
            {
                try
                {
                    string frmt = Common.CreateFormatString(caption);
                    caption = String.Format(Common.Formatter, frmt, dat);
                }
                catch { }
                ri.name = caption;
            }
            foreach (itemInfo item in ri.Items)
            {
                string value = item.Value == null ? "" : item.Value.Trim();

                try
                {
                    if (item is imgInfo)
                    {
                        if (value.Contains(":BARCODE"))
                        {
                            value = value.Replace("[#", "").Replace("#]", "").Trim();
                            int    i      = value.IndexOf(":BARCODE");
                            string mask   = (value.Length > i + 8) ? value.Substring(i + 9) : "";
                            int    height = Convert.ToInt32(item.height * 10);
                            string field  = value.Substring(0, i);

                            string val = "";
                            val = dat.ToString(field, null);

                            if (mask != "")
                            {
                                val = mask.Replace("%", val);
                            }
                            //new code
                            value      = BARCODEKEYSTRING + val;
                            item.Value = value;
                        }
                        else
                        {
                            imgInfo ii = item as imgInfo;

                            ii.Value = "";
                            if (!Common.IsNullOrEmpty(ii.src))
                            {
                                string imagename = ii.src.Trim();
                                if (imagelist != null && imagelist.ContainsKey(imagename))
                                {
                                    using (MemoryStream str = new MemoryStream())
                                    {
                                        Image image = imagelist[imagename];
                                        image.Save(str, ImageFormat.Jpeg);
                                        ii.Value = Convert.ToBase64String(str.ToArray());
                                        ii.src   = "";
                                    }
                                }
                                else if (!Common.IsNullOrEmpty(image_dir))
                                {
                                    string imagefile = Path.Combine(image_dir, imagename);
                                    if (File.Exists(imagefile))
                                    {
                                        MemoryStream str = new MemoryStream();
                                        Image.FromFile(imagefile).Save(str, System.Drawing.Imaging.ImageFormat.Jpeg);
                                        ii.Value = Convert.ToBase64String(str.ToArray());
                                        ii.src   = "";
                                    }
                                }
                            }
                        }
                    }
                    else if (item is checkInfo && value.Contains("=="))
                    {
                        string prop    = value.Substring(0, value.IndexOf("==")).Trim();
                        string cond    = value.Substring(value.IndexOf("==") + 2).Trim().ToUpper();
                        bool   enumval = false;

                        string propval = dat.ToString(prop, null).Trim().ToUpper();
                        //object val = ExtraRepDataInfo.GetValue(dat, prop);
                        //string propval = (val == null) ? "" : val.ToString().Trim().ToUpper();

                        // Заплатка! Для того, чтобы в отчетах значения enum
                        // можно было использовать как с пробелами, так и без оных.
                        // Андрей 8.8.2007
                        string valnospaces = propval.Replace(" ", "");
                        // Конец заплатки. Ниже значение используется в теле цикла
                        foreach (string s in cond.Split('|'))
                        {
                            enumval |= ((propval == s) || (valnospaces == s));
                        }
                        item.Value = enumval.ToString();
                    }
                    else if (!value.Contains(PAGENUMBER) && (value.Contains("[#") || value.Contains("#]")))
                    {
                        //string frmt = value.Replace("{", @"{{").Replace("}", @"}}").Replace("[#", "{0:").Replace("#]", "}");
                        string frmt = Common.CreateFormatString(value);
                        item.Value = String.Format(Common.Formatter, frmt, dat);
                    }
                }
                catch (Exception ex)
                {
                    errors += string.Format("Ошибка в шаблоне - поле {0}, значение={1}, [{2}]\n ", item.GetType(), item.Value, ex.Message);
                }
            }
            repPages.AddRange(CreatePages(ri, caption, count));
            DefaultPageSettings.Landscape = IsLandscape();
        }