Пример #1
0
        private System.Drawing.Size GetPageSize(string xml)
        {
            ReadXml r = new ReadXml(xml);
            int     w = Convert.ToInt16(r.Read("Page/Width"));
            int     h = Convert.ToInt16(r.Read("Page/Height"));

            return(new System.Drawing.Size(w, h));
        }
Пример #2
0
        private int GetPageCount(string xml)
        {
            ReadXml r = new ReadXml(xml);

            //
            if (r.Read("PrintObject3") == "")
            {
                return(1);
            }
            else
            {
                int columnHeight   = Convert.ToInt16(r.Read("PrintObject3/ColumnHeight"));
                int rowHeight      = Convert.ToInt16(r.Read("PrintObject3/RowHeight"));
                int gridWidth      = Convert.ToInt16(r.Read("PrintObject3/Width"));
                int gridHeight     = Convert.ToInt16(r.Read("PrintObject3/Height"));
                int smallTotal     = Conv.ToInt16(r.Read("PrintObject3/SmallTotal"));
                int anPageRowCount = 0;
                if (smallTotal == 1)
                {
                    anPageRowCount = (gridHeight - columnHeight - rowHeight) / rowHeight;
                }
                else
                {
                    anPageRowCount = (gridHeight - columnHeight) / rowHeight;
                }

                if (tbdetail.Rows.Count == 0)
                {
                    return(1);
                }
                else
                {
                    int cnt = tbdetail.Rows.Count / anPageRowCount;
                    if (tbdetail.Rows.Count % anPageRowCount != 0)
                    {
                        cnt += 1;
                    }
                    return(cnt);
                }
            }
        }
Пример #3
0
        private void Draw(System.Drawing.Graphics g, int pageIndex, bool isFirst, bool isLast)
        {
            ReadXml r = new ReadXml(xml);

            foreach (ReadXml r2 in r.ReadList("PrintObject1"))
            {
                int           left          = Convert.ToInt16(r2.Read("Left"));
                int           top           = Convert.ToInt16(r2.Read("Top"));
                int           Width         = Convert.ToInt16(r2.Read("Width"));
                int           Height        = Convert.ToInt16(r2.Read("Height"));
                string        context       = r2.Read("Context");
                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == 2 && isFirst == false || Area == 4 && isLast == false)
                {
                }
                else
                {
                    g.DrawString(context, font, new SolidBrush(color), rec, sf);
                    if (_BorderLeft == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left, top + Height);
                    }
                    if (_BorderRight == 1)
                    {
                        g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                    }
                    if (_BorderTop == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left + Width, top);
                    }
                    if (_BorderBottom == 1)
                    {
                        g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                    }
                }
            }
            foreach (ReadXml r2 in r.ReadList("PrintObject2"))
            {
                int           left          = Convert.ToInt16(r2.Read("Left"));
                int           top           = Convert.ToInt16(r2.Read("Top"));
                int           Width         = Convert.ToInt16(r2.Read("Width"));
                int           Height        = Convert.ToInt16(r2.Read("Height"));
                string        Field         = r2.Read("Field");
                string        Format        = r2.Read("Format");
                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == 2 && isFirst == false || Area == 4 && isLast == false)
                {
                }
                else
                {
                    if (tbmain.Rows.Count != 0)
                    {
                        DataRow    row     = tbmain.Rows[0];
                        DataColumn col     = tbmain.Columns[Field];
                        string     context = "";
                        if (Format == "")
                        {
                            context = row[Field].ToString();
                        }
                        else if (Format == "大写金额")
                        {
                            context = Conv.DaXie2(row[Field].ToString());
                        }
                        else if (Format == "条形码")
                        {
                            Barcode.CreateBarcodeImage(g, rec.X, rec.Y, "C", row[Field].ToString(), 1F, rec.Height);
                        }
                        else if (Format == "二维码")
                        {
                            QRCode code = new QRCode();
                            Bitmap bit  = code.grant_qrcode(row[Field].ToString(), rec.Width, rec.Width);
                            g.DrawImage(bit, rec);
                        }
                        else
                        {
                            if (col.DataType == typeof(decimal))
                            {
                                context = Conv.ToDecimal(row[Field]).ToString(Format);
                            }
                            else if (col.DataType == typeof(Int16))
                            {
                                context = Conv.ToInt16(row[Field]).ToString(Format);
                            }
                            else if (col.DataType == typeof(Int32))
                            {
                                context = Conv.ToInt32(row[Field]).ToString(Format);
                            }
                            else if (col.DataType == typeof(DateTime))
                            {
                                context = Conv.ToDateTime(row[Field]).ToString(Format);
                            }
                            else
                            {
                                context = row[Field].ToString();
                            }
                        }
                        if (Format == "条形码")
                        {
                        }
                        else if (Format == "二维码")
                        {
                        }
                        else
                        {
                            g.DrawString(context, font, new SolidBrush(color), rec, sf);
                        }
                        if (_BorderLeft == 1)
                        {
                            g.DrawLine(Pens.Black, left, top, left, top + Height);
                        }
                        if (_BorderRight == 1)
                        {
                            g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                        }
                        if (_BorderTop == 1)
                        {
                            g.DrawLine(Pens.Black, left, top, left + Width, top);
                        }
                        if (_BorderBottom == 1)
                        {
                            g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                        }
                    }
                }
            }
            if (r.Read("PrintObject3") != "")
            {
                int flag = 0;
                foreach (ReadXml r2 in r.ReadList("PrintObject3/Column"))
                {
                    if (r2.Read("ColName") == "#")
                    {
                        flag = 1;
                        break;
                    }
                }
                //


                if (flag == 0)
                {
                    IDrawDetail draw = new DrawDetailDefault();
                    draw.Draw(g, xml, tbdetail, pageIndex);
                }
                else
                {
                    IDrawDetail draw = new DrawDetailJH();
                    draw.Draw(g, xml, tbdetail, pageIndex);
                }
            }
            foreach (ReadXml r2 in r.ReadList("PrintObject4"))
            {
                int left   = Convert.ToInt16(r2.Read("Left"));
                int top    = Convert.ToInt16(r2.Read("Top"));
                int Width  = Convert.ToInt16(r2.Read("Width"));
                int Height = Convert.ToInt16(r2.Read("Height"));
                var color  = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int Area   = Convert.ToInt16(r2.Read("Area"));
                if (Area == 2 && isFirst == false || Area == 4 && isLast == false)
                {
                }
                else
                {
                    g.DrawLine(new Pen(color), left + Width / 2, top, left + Width / 2, top + Height);
                }
            }
            foreach (ReadXml r2 in r.ReadList("PrintObject5"))
            {
                int left   = Convert.ToInt16(r2.Read("Left"));
                int top    = Convert.ToInt16(r2.Read("Top"));
                int Width  = Convert.ToInt16(r2.Read("Width"));
                int Height = Convert.ToInt16(r2.Read("Height"));
                var color  = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int Area   = Convert.ToInt16(r2.Read("Area"));
                if (Area == 2 && isFirst == false || Area == 4 && isLast == false)
                {
                }
                else
                {
                    g.DrawLine(new Pen(color), left, top + Height / 2, left + Width, top + Height / 2);
                }
            }
            foreach (ReadXml r2 in r.ReadList("PrintObject6"))
            {
                int       left   = Convert.ToInt16(r2.Read("Left"));
                int       top    = Convert.ToInt16(r2.Read("Top"));
                int       Width  = Convert.ToInt16(r2.Read("Width"));
                int       Height = Convert.ToInt16(r2.Read("Height"));
                var       img    = Conv.StringToImage(r2.Read("Image"));
                int       Area   = Convert.ToInt16(r2.Read("Area"));
                Rectangle rec    = new Rectangle(left, top, Width, Height);
                if (Area == 2 && isFirst == false || Area == 4 && isLast == false)
                {
                }
                else
                {
                    g.DrawImage(img, rec);
                }
            }
            foreach (ReadXml r2 in r.ReadList("PrintObject7"))
            {
                int left   = Convert.ToInt16(r2.Read("Left"));
                int top    = Convert.ToInt16(r2.Read("Top"));
                int Width  = Convert.ToInt16(r2.Read("Width"));
                int Height = Convert.ToInt16(r2.Read("Height"));

                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == 2 && isFirst == false || Area == 4 && isLast == false)
                {
                }
                else
                {
                    string context = "第N页,共M页".Replace("N", pageIndex.ToString())
                                     .Replace("M", PageCount.ToString());
                    g.DrawString(context, font, new SolidBrush(color), rec, sf);
                    if (_BorderLeft == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left, top + Height);
                    }
                    if (_BorderRight == 1)
                    {
                        g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                    }
                    if (_BorderTop == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left + Width, top);
                    }
                    if (_BorderBottom == 1)
                    {
                        g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                    }
                }
            }
            foreach (ReadXml r2 in r.ReadList("PrintObject8"))
            {
                int           left          = Convert.ToInt16(r2.Read("Left"));
                int           top           = Convert.ToInt16(r2.Read("Top"));
                int           Width         = Convert.ToInt16(r2.Read("Width"));
                int           Height        = Convert.ToInt16(r2.Read("Height"));
                string        format        = r2.Read("Format");
                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == 2 && isFirst == false || Area == 4 && isLast == false)
                {
                }
                else
                {
                    string context = "";
                    if (format == "")
                    {
                        context = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        context = System.DateTime.Now.ToString(format);
                    }
                    g.DrawString(context, font, new SolidBrush(color), rec, sf);
                    if (_BorderLeft == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left, top + Height);
                    }
                    if (_BorderRight == 1)
                    {
                        g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                    }
                    if (_BorderTop == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left + Width, top);
                    }
                    if (_BorderBottom == 1)
                    {
                        g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                    }
                }
            }
        }