using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using testPrint;
using System.Drawing.Printing;namespace printCloseEyesApplication
{
    public partial class Showxx : Form
    {
        public Showxx()
        {
            InitializeComponent();
        }
        string dingdanId;
        string loginid;
        Getprintcont.WebService_Official gpc = new printCloseEyesApplication.Getprintcont.WebService_Official();
        UpdatePrintinformation_Record.WebService_Official upr = new printCloseEyesApplication.UpdatePrintinformation_Record.WebService_Official();
        SelectHelper sh = new SelectHelper();
        Label la;
        public Showxx(string dingdanId, string logingid)
        {
            InitializeComponent();
            this.dingdanId = dingdanId;
            this.loginid = logingid;
            this.printDocument1.OriginAtMargins = true;//启用页边距
            this.pageSetupDialog1.EnableMetric = true; //以毫米为单位
        }        private void Showxx_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = gpc.Getprintcont(dingdanId).Tables[0];
            int index = dt.Rows.Count;
            lblddh.Text = dt.Rows[0][0].ToString();
            lblhyh.Text = dt.Rows[0][1].ToString();
            lblzsxm.Text = dt.Rows[0][2].ToString();
            lbldh.Text = dt.Rows[0][7].ToString();
            lbldz.Text = dt.Rows[0][8].ToString();
            lblxxdz.Text = dt.Rows[0][9].ToString();
            for (int i = 0; i < index; i++)
            {
                if (i == 0)
                {
                    la = new Label();
                    // la.Font = new Font("宋体", 11);
                    la.Text = "商品名称";
                    la.Location = new Point(20, 90 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Text = "颜色";
                    la.Location = new Point(350, 90 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Text = "规格";
                    la.Location = new Point(450, 90 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Text = "数量";
                    la.Location = new Point(550, 90 + 30 * i);
                    groupBox1.Controls.Add(la);
                    //详细内容
                    la = new Label();
                    la.Font = new Font("宋体", 11);
                    la.Width = 320;
                    la.Text = dt.Rows[i][3].ToString();
                    la.Location = new Point(20, 120 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Font = new Font("宋体", 11);
                    la.Text = dt.Rows[i][4].ToString();
                    la.Location = new Point(350, 120 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Font = new Font("宋体", 11);
                    la.Text = dt.Rows[i][5].ToString();
                    la.Location = new Point(450, 120 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Font = new Font("宋体", 11);
                    la.Text = dt.Rows[i][6].ToString();
                    la.Location = new Point(550, 120 + 30 * i);
                    groupBox1.Controls.Add(la);
                    lblhpzl.Location = new Point(500, 150 + 30 * i);
                    lblNum.Location = new Point(560, 150 + 30 * i);
                    groupBox1.Height = 180 + 30 * i;
                }
                else
                {
                    la = new Label();
                    la.Font = new Font("宋体", 11);
                    la.Width = 320;
                    la.Text = dt.Rows[i][3].ToString();
                    la.Location = new Point(20, 120 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Font = new Font("宋体", 11);
                    la.Text = dt.Rows[i][4].ToString();
                    la.Location = new Point(350, 120 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Font = new Font("宋体", 11);
                    la.Text = dt.Rows[i][5].ToString();
                    la.Location = new Point(450, 120 + 30 * i);
                    groupBox1.Controls.Add(la);                    la = new Label();
                    la.Font = new Font("宋体", 11);
                    la.Text = dt.Rows[i][6].ToString();
                    la.Location = new Point(550, 120 + 30 * i);
                    groupBox1.Controls.Add(la);
                    lblhpzl.Location = new Point(500, 150 + 30 * i);
                    lblNum.Location = new Point(560, 150 + 30 * i);
                    groupBox1.Height = 180 + 30 * i;
                }
            }
            lblNum.Text = sh.GetTotle(dt).ToString();
        }        private void btnprint_Click(object sender, EventArgs e)
        {
            try
            {                this.printDocument1.Print();                PaperSize ps = new PaperSize("name", _width, _height + 150);                this.printDocument1.DefaultPageSettings.PaperSize = ps;                int res = upr.UpdatePrintinformation_Record(loginid, dingdanId);
                if (res > 0)
                {
                    MessageBox.Show("打印成功,已经记录!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("数据库维护中,记录失败!");
                }
            }
            catch (Exception)
            {
                throw;
            }            //}
        }
        int _height = 0;
        int _width = 0;
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            //打印内容 为 局部的 this.groupBox1
            Bitmap _NewBitmap = new Bitmap(groupBox1.Width, groupBox1.Height);
            groupBox1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
            _height = _NewBitmap.Height;
            _width = _NewBitmap.Width;            e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height + 150);        }