示例#1
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);
        }
示例#2
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();
        }