/// <summary>
        /// ����Ĺ��÷���
        /// </summary>
        /// <returns></returns>
        public virtual PrinterContent BuildPrinter()
        {
            this.customMargin=this.GetPageMargin();
            PrinterContent content = new PrinterContent();

            content.CustomPageMargin = customMargin;
            content.Header = this.BuildHeader();
            content.IsPrinterPages = true;
            content.Footer = this.BuildFooter();
            content.Body = this.BuildContent();
            return content;
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.dataGridView1.EndEdit();
            PrintCommonSetting.Default_Border_Style = BordersEdgeStyle.All;
            //if (this.dataGridView1.Rows.Count == 0)
            //{
                //MessageBoxHelper.Show("���������Ҫ��ӡ��ѧԱ��");
            //}
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            int rowHeight = 34;
            PageMargin margin = new PageMargin();
            margin.Left = 35;
            margin.Right = 35;
            //margin.Bottom = 36;

            //margin.Top = 37;
            margin.Bottom = 40;
            margin.Top = 33;
            PrinterContent content = new PrinterContent();
            content.CustomPageMargin = margin;
            PrinterHint header = this.GetHeader(content.CustomPageMargin.Width, this.comboBox1.Text);
            //header.Rectangle = new Rectangle((content.CustomPageMargin.Width - header.Rectangle.Width), 0, header.Rectangle.Width, header.Rectangle.Height);
            content.Header = header;
            content.IsPrinterPages = false;

            int[] columnWidth ={ 60, 90, 90,60, 184, 135,60, content.CustomPageMargin.Width - 679 };
            string[] columnHeader ={ "���", "����", "����", "�Ա�", "���֤������", "׼��֤����", "�ɼ�", "��ע" };
            int len = columnWidth.Length;
            PrinterTable table = new PrinterTable();
            PrinterRow row = new PrinterRow();
            row.Rectangle = new System.Drawing.Rectangle(0, 0, content.CustomPageMargin.Width, 43);
            TextDraw text = null;
            int tmp = 0;
            Font col = new Font("����",15);

            for (int i = 0; i < len; i++)
            {
                text = new TextDraw(columnHeader[i]);
                text.Formater = sf;
                text.Font = col;
                text.Border = BordersEdgeStyle.All;
                text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], 43);
                tmp += columnWidth[i];
                row.Add(text);
            }
            table.Header = row;
            //table.Add(row);
            row = null;
            DataRow dr = null;
            string tmpCarType = string.Empty;
               // DataTable dt = this.MockData();
            DataTable dt = this.GetDataFromGrid();
            if (dt.Rows.Count == 0)
            {
                for (int i = 0; i < 24; i++)
                {
                    dt.Rows.Add(new string[] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty });
                }
            }
            else
            {
                int tmprowcount = dt.Rows.Count % 24;
                if (tmprowcount != 0)
                {
                    tmprowcount = 24 - tmprowcount;
                    for (int i = 0; i < tmprowcount; i++)
                    {
                        dt.Rows.Add(new string[] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty });
                    }
                }
            }
            for (int j = 0; j < dt.Rows.Count; j++)
            {
                dr = dt.Rows[j];
                tmp = 0;
                row = new PrinterRow();
                row.Rectangle = new System.Drawing.Rectangle(0, 0, content.CustomPageMargin.Width, rowHeight);
                text = new TextDraw(((j + 1)%24==0?24:(j+1)%24).ToString());
                text.Formater = sf;
                text.Border = BordersEdgeStyle.All;
                text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[0], rowHeight);
                tmp += columnWidth[0];
                row.Add(text);
                tmpCarType = dr[3].ToString();
                for (int i = 1; i < len; i++)
                {
                    text = new TextDraw(Convert.IsDBNull(dr[i - 1]) ? string.Empty : dr[i - 1].ToString());
                    text.Border = BordersEdgeStyle.All;
                    text.Formater = sf;
                    text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], rowHeight);
                    tmp += columnWidth[i];
                    row.Add(text);
                }
                table.Add(row);
            }
            table.Border = BordersEdgeStyle.None;
            content.Body = table;
            PrinterHint footer = this.GetFooter(content.CustomPageMargin.Width);
            content.Footer = footer;
            content.PrinterSetting();
            //content.Preview();
        }