Beispiel #1
0
 private int SmallTotal(string xml)
 {
     Helper.ReadXml r = new Helper.ReadXml(xml);
     foreach (Helper.ReadXml r2 in r.ReadList("Page/Column"))
     {
         if (r2.Read("ColName") == "行号")
         {
         }
         else
         {
             if (r2.Read("SmallTotal") == "1")
             {
                 return(1);
             }
             else
             {
             }
         }
     }
     return(0);
 }
Beispiel #2
0
        private void Draw(System.Drawing.Graphics g, int area, int pageIndex, int cur_top)
        {
            Helper.ReadXml r = new Helper.ReadXml(xml);

            int offset_y = 0;

            if (area == 1)
            {
                offset_y -= barHeight;
            }
            else if (area == 2)
            {
                offset_y -= ah + 2 * barHeight;
            }
            else if (area == 3)
            {
                offset_y -= ah + bh + barHeight * 3;
            }
            else if (area == 4)
            {
                offset_y -= ah + bh + ch + barHeight * 4;
            }
            else if (area == 5)
            {
                offset_y -= ah + bh + ch + dh + barHeight * 5;
            }
            if (area == 5)
            {
                cur_top = pageHeight - eh;
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject1"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_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            = Helper.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 == area)
                {
                    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 (Helper.ReadXml r2 in r.ReadList("PrintObject2"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_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            = Helper.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 == area)
                {
                    if (tbmain.Rows.Count != 0)
                    {
                        if (tbmain.Columns.Contains(Field) == true)
                        {
                            DataRow    row = tbmain.Rows[0];
                            DataColumn col = tbmain.Columns[Field];

                            if (tbmain.Columns[Field].DataType == typeof(byte[]))
                            {
                                System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])row[Field]);
                                Image img = Image.FromStream(ms);
                                g.DrawImage(img, rec);
                                continue;
                            }
                            string context = "";
                            if (Format == "")
                            {
                                context = row[Field].ToString();
                            }
                            else if (Format == "大写金额")
                            {
                                context = Helper.Conv.DaXie2(row[Field].ToString());
                            }
                            else if (Format == "条形码")
                            {
                                Helper.Barcode.CreateBarcodeImage(g, rec.X, rec.Y, "C", row[Field].ToString(), 1F, rec.Height);
                            }
                            else if (Format == "二维码")
                            {
                                Helper.QRCode code = new Helper.QRCode();
                                Bitmap        bit  = code.grant_qrcode(row[Field].ToString(), rec.Width, rec.Width);
                                g.DrawImage(bit, rec);
                            }
                            else
                            {
                                if (col.DataType == typeof(decimal))
                                {
                                    context = Helper.Conv.ToDecimal(row[Field]).ToString(Format);
                                }
                                else if (col.DataType == typeof(Int16))
                                {
                                    context = Helper.Conv.ToInt16(row[Field]).ToString(Format);
                                }
                                else if (col.DataType == typeof(Int32))
                                {
                                    context = Helper.Conv.ToInt32(row[Field]).ToString(Format);
                                }
                                else if (col.DataType == typeof(DateTime))
                                {
                                    context = Helper.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);
                            }
                        }
                    }
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject3"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_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            = Helper.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 == area)
                {
                    if (tbdetail.Rows.Count != 0)
                    {
                        if (tbdetail.Columns.Contains(Field) == true)
                        {
                            var     col     = tbdetail.Columns[Field];
                            string  context = "";
                            decimal val     = 0;
                            foreach (DataRow row in tbdetail.Rows)
                            {
                                val += Helper.Conv.ToDecimal(row[Field].ToString());
                            }
                            if (Format == "")
                            {
                                context = val.ToString();
                            }
                            else if (Format == "大写金额")
                            {
                                context = Helper.Conv.DaXie2(val.ToString("0.00"));
                            }
                            else
                            {
                                if (col.DataType == typeof(decimal))
                                {
                                    context = val.ToString(Format);
                                }
                                else if (col.DataType == typeof(Int16))
                                {
                                    context = Helper.Conv.ToInt16(val).ToString(Format);
                                }
                                else if (col.DataType == typeof(Int32))
                                {
                                    context = Helper.Conv.ToInt32(val).ToString(Format);
                                }
                                else if (col.DataType == typeof(DateTime))
                                {
                                    context = Helper.Conv.ToDateTime(val).ToString(Format);
                                }
                                else
                                {
                                    context = val.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 (Helper.ReadXml r2 in r.ReadList("PrintObject4"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_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 == area)
                {
                    g.DrawLine(new Pen(color), left + Width / 2, top, left + Width / 2, top + Height);
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject5"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_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 == area)
                {
                    g.DrawLine(new Pen(color), left, top + Height / 2, left + Width, top + Height / 2);
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject6"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_top;
                int       Width  = Convert.ToInt16(r2.Read("Width"));
                int       Height = Convert.ToInt16(r2.Read("Height"));
                var       img    = Helper.Conv.StringToImage(r2.Read("Image"));
                int       Area   = Convert.ToInt16(r2.Read("Area"));
                Rectangle rec    = new Rectangle(left, top, Width, Height);
                if (Area == area)
                {
                    g.DrawImage(img, rec);
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject7"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));

                top += offset_y + cur_top;
                int Width  = Convert.ToInt16(r2.Read("Width"));
                int Height = Convert.ToInt16(r2.Read("Height"));

                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Helper.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 == area)
                {
                    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 (Helper.ReadXml r2 in r.ReadList("PrintObject8"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_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            = Helper.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 == area)
                {
                    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);
                    }
                }
            }
        }
Beispiel #3
0
        void IBLL.IPrint.Print(string style_id, string xml, System.Data.DataTable tbmain, System.Data.DataTable tbdetail)
        {
            try
            {
                this.style_id = style_id;
                this.xml      = xml;
                this.tbmain   = tbmain;
                this.tbdetail = tbdetail;
                row_count     = this.tbdetail.Rows.Count;
                if (this.tbdetail.Columns.Contains("行号") == true)
                {
                    this.tbdetail.Columns.Remove("行号");
                    this.tbdetail.Columns.Add("行号");
                    this.tbdetail.Columns["行号"].SetOrdinal(0);
                }
                else
                {
                    this.tbdetail.Columns.Add("行号");
                    this.tbdetail.Columns["行号"].SetOrdinal(0);
                }
                //
                Helper.ReadXml r = new Helper.ReadXml(xml);
                barHeight      = Convert.ToInt16(r.Read("Page/BarHeight"));
                pageWidth      = Convert.ToInt16(r.Read("Page/Width"));
                pageHeight     = Convert.ToInt16(r.Read("Page/Height"));
                ah             = Convert.ToInt16(r.Read("Page/AHeight"));
                bh             = Convert.ToInt16(r.Read("Page/BHeight"));
                ch             = Convert.ToInt16(r.Read("Page/CHeight"));
                dh             = Convert.ToInt16(r.Read("Page/DHeight"));
                eh             = Convert.ToInt16(r.Read("Page/EHeight"));
                AppendEmptyRow = Convert.ToInt16(r.Read("Page/AppendEmptyRow"));
                rowHeight      = ch;
                smallTotal     = SmallTotal(xml);
                FontConverter fc = new FontConverter();
                gridFont = (Font)fc.ConvertFromString(r.Read("Page/GridFont"));
                gridLeft = Convert.ToInt16(r.Read("Page/GridLeft"));
                //
                tbstyle = new DataTable();
                tbstyle.Columns.Add("display");
                tbstyle.Columns.Add("colname");
                tbstyle.Columns.Add("colbyname");
                tbstyle.Columns.Add("width", typeof(int));
                tbstyle.Columns.Add("align");
                tbstyle.Columns.Add("format");
                tbstyle.Columns.Add("smalltotal");
                //

                foreach (Helper.ReadXml r2 in r.ReadList("Page/Column"))
                {
                    var row = tbstyle.NewRow();
                    tbstyle.Rows.Add(row);

                    row["display"]   = r2.Read("Display");
                    row["colname"]   = r2.Read("ColName");
                    row["colbyname"] = r2.Read("ColByname");

                    row["width"]      = Convert.ToInt16(r2.Read("Width"));
                    row["align"]      = r2.Read("Align");
                    row["format"]     = r2.Read("Format");
                    row["SmallTotal"] = r2.Read("SmallTotal");
                }

                //
                this.ShowDialog();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Beispiel #4
0
        public void Print(string xml, DataTable tbmain, DataTable tbdetail)
        {
            this.xml      = xml;
            this.tbmain   = tbmain;
            this.tbdetail = tbdetail;
            row_count     = tbdetail.Rows.Count;
            if (this.tbdetail.Columns.Contains("行号") == true)
            {
                this.tbdetail.Columns.Remove("行号");
                this.tbdetail.Columns.Add("行号");
            }
            else
            {
                this.tbdetail.Columns.Add("行号");
            }
            PageCount = this.GetPageCount(xml);
            PageSize  = this.GetPageSize(xml);
            //
            if (tbdetail != null)
            {
                int index = 0;
                foreach (DataRow row in tbdetail.Rows)
                {
                    index++;
                    row["行号"] = index;
                }
            }
            //
            Helper.ReadXml r = new Helper.ReadXml(xml);
            barHeight      = Convert.ToInt16(r.Read("Page/BarHeight"));
            pageWidth      = Convert.ToInt16(r.Read("Page/Width"));
            pageHeight     = Convert.ToInt16(r.Read("Page/Height"));
            ah             = Convert.ToInt16(r.Read("Page/AHeight"));
            bh             = Convert.ToInt16(r.Read("Page/BHeight"));
            ch             = Convert.ToInt16(r.Read("Page/CHeight"));
            dh             = Convert.ToInt16(r.Read("Page/DHeight"));
            eh             = Convert.ToInt16(r.Read("Page/EHeight"));
            AppendEmptyRow = Convert.ToInt16(r.Read("Page/AppendEmptyRow"));
            rowHeight      = ch;
            smallTotal     = SmallTotal(xml);
            FontConverter fc = new FontConverter();

            gridFont = (Font)fc.ConvertFromString(r.Read("Page/GridFont"));
            gridLeft = Convert.ToInt16(r.Read("Page/GridLeft"));
            //
            tbstyle = new DataTable();
            tbstyle.Columns.Add("display");
            tbstyle.Columns.Add("colname");
            tbstyle.Columns.Add("colbyname");
            tbstyle.Columns.Add("width");
            tbstyle.Columns.Add("align");
            tbstyle.Columns.Add("format");
            tbstyle.Columns.Add("smalltotal");
            //

            foreach (Helper.ReadXml r2 in r.ReadList("Page/Column"))
            {
                var row = tbstyle.NewRow();
                tbstyle.Rows.Add(row);

                row["display"]   = r2.Read("Display");
                row["colname"]   = r2.Read("ColName");
                row["colbyname"] = r2.Read("ColByname");

                row["width"]      = Convert.ToInt16(r2.Read("Width"));
                row["align"]      = r2.Read("Align");
                row["format"]     = r2.Read("Format");
                row["SmallTotal"] = r2.Read("SmallTotal");
            }

            //
            //
            pd = new System.Drawing.Printing.PrintDocument();
            pd.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("printPage", PageSize.Width, PageSize.Height);
            pd.PrintPage += this.pd_pagePrint;
            PageIndex     = 1;
            pd.Print();
        }