Exemple #1
0
        public void Print()
        {
            PrinterContent content = this.GetPrinterContent();

            if (content != null)
            {
                content.Print();
            }
        }
        /// <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;
        }
 /// <summary>
 /// 根据全局配置来打印
 /// </summary>
 public void Print()
 {
     PrinterContent content = this.BuildPrinter();
     if (printSetting.PrintModel == "直接打")
     {
         content.Print();
     }
     else if (printSetting.PrintModel == "选择打印机")
     {
         content.PrinterSetting();
     }
     else
     {
         content.Preview();
     }
 }
Exemple #4
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();
        }