Example #1
0
        // 打印制管大标牌
        private void PipeCardPrint2(System.Drawing.Printing.PrintPageEventArgs e)
        {
            int    lableWith = 70, lableLength = 100, lineHight = 6;
            double dotMM = 4;
            // 顶部和底部的大矩形
            Size topBox = new Size(lableWith, 55);

            //左边空白矩形区
            Size littleBox = new Size(14, lineHight);
            //左边空白矩形区
            Size leftBlankBox = new Size(24, lineHight);
            //一行只有一个类型
            Size oneTypeBox = new Size(lableWith - littleBox.Width, lineHight);
            ////生产时间矩形区
            Size prodDateLeftBox  = new Size(20, lineHight);
            Size prodDateBlankBox = new Size(40, lineHight);

            // 条码矩形区
            Size barcodeBox = new Size(67, 18);

            // 地址矩形区
            Size addrBox = new Size(lableWith, 5);

            // 矩形坐标定义
            Rectangle[] _rects = new Rectangle[19];
            int         i      = 0;

            // 标签头部
            _rects[i] = new Rectangle(0, 0, topBox.Width, topBox.Height);
            //----------------------------------------------------------------------------- 第1行
            // 品名
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);
            //----------------------------------------------------------------------------- 第2行
            // 批号
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);
            //----------------------------------------------------------------------------- 第3行
            //标准
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);

            //牌号
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);


            //----------------------------------------------------------------------------- 第4行
            // 规格
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);

            //----------------------------------------------------------------------------- 第5行
            //重量
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);

            //支数
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, leftBlankBox.Width, leftBlankBox.Height);

            //----------------------------------------------------------------------------- 第6行
            // 生产日期
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, prodDateLeftBox.Width, prodDateLeftBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, prodDateBlankBox.Width, prodDateBlankBox.Height);
            //----------------------------------------------------------------------------- 第7行
            // 底部的条码区
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, barcodeBox.Width, barcodeBox.Height);
            // 地址区
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height + 1, addrBox.Width, addrBox.Height);
            // 坐标单位转换 mm -> dot
            for (i = 0; i < _rects.Length; i++)
            {
                _rects[i].X      = (int)(_rects[i].X * dotMM);
                _rects[i].Y      = (int)(_rects[i].Y * dotMM) - 65;
                _rects[i].Width  = (int)(_rects[i].Width * dotMM);
                _rects[i].Height = (int)(_rects[i].Height * dotMM);
            }

            // 定义字体
            Font CFont  = new Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font EFont  = new Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sEFont = new Font("Arial", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sCFont = new Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            //Font ssCFont = new Font("隶书", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

            Font cCFont = new Font("隶书", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font eEFont = new Font("Arial", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            StringFormat drawFormat1 = new StringFormat();

            drawFormat1.Alignment     = StringAlignment.Center;
            drawFormat1.LineAlignment = StringAlignment.Center;
            // add by [bhb]
            StringFormat formatLeft = new StringFormat();

            formatLeft.Alignment     = StringAlignment.Near;
            formatLeft.LineAlignment = StringAlignment.Near;
            //===========================画矩形===========================
            //Pen rectPen = new Pen(Brushes.Blue, 2);
            //for (i = 0; i < _rects.Length; i++)
            //{
            //    e.Graphics.DrawRectangle(rectPen, _rects[i]);
            //}

            //===========================打印数据===========================
            //打印品名
            _rects[2].Y -= 24;
            e.Graphics.DrawString(_lable.PM, EFont, Brushes.Black, _rects[2], drawFormat1);
            _rects[4].Y -= 24;
            //打印批次号
            if (_lable.BandNo.Length == 1)
            {
                e.Graphics.DrawString(_lable.BatchNo + "   0" + _lable.BandNo, EFont, Brushes.Black, _rects[4], drawFormat1);
            }
            else
            {
                e.Graphics.DrawString(_lable.BatchNo + "   " + _lable.BandNo, EFont, Brushes.Black, _rects[4], drawFormat1);
            }

            //打印标准
            e.Graphics.DrawString(_lable.Standard, EFont, Brushes.Black, _rects[6], drawFormat1);
            // 打印牌号\ 增加X的偏移量
            // _rects[6].X -= 10;
            _rects[8].Y -= 24;
            _rects[8].X  = 56;
            e.Graphics.DrawString(_lable.SteelType, EFont, Brushes.Black, _rects[8], drawFormat1);

            //打印规格
            e.Graphics.DrawString(_lable.Spec, EFont, Brushes.Black, _rects[10], drawFormat1);
            //打印重量

            e.Graphics.DrawString(_lable.Weight, EFont, Brushes.Black, _rects[12], drawFormat1); //重量
            //打印支数
            //e.Graphics.DrawString(_lable.Count, EFont, Brushes.Black, _rects[14], drawFormat1); //重量
            //打印生产日期
            e.Graphics.DrawString(_lable.Date.ToString("yyyy") + "-" + _lable.Date.ToString("MM") + "-" + _lable.Date.ToString("dd") + "    " + _lable.Term, CFont, Brushes.Black, _rects[16], drawFormat1); //生产日期
            // 打印条码
            Code128 c128 = new Code128();

            c128.printPipeCode(_lable.BarCode, _rects[17], e);

            // 打印地址
            if (Data.PrintAddress)
            {
                e.Graphics.DrawString("云南 ● 玉溪", sCFont, Brushes.Black, _rects[18], drawFormat1); //地点
            }
        }
Example #2
0
        // 打印制管大标牌
        private void PipeCardPrint2(System.Drawing.Printing.PrintPageEventArgs e)
        {
            int lableWith = 70, lableLength = 100, lineHight = 6;
            double dotMM = 4;
            // 顶部和底部的大矩形
            Size topBox = new Size(lableWith,55);

            //左边空白矩形区
            Size littleBox = new Size(14, lineHight);
            //左边空白矩形区
            Size leftBlankBox = new Size(24, lineHight);
            //一行只有一个类型
            Size oneTypeBox = new Size(lableWith - littleBox.Width, lineHight);
            ////生产时间矩形区
            Size prodDateLeftBox = new Size(20, lineHight);
            Size prodDateBlankBox = new Size(40, lineHight);

            // 条码矩形区
            Size barcodeBox = new Size(67, 18);

            // 地址矩形区
            Size addrBox = new Size(lableWith, 5);

            // 矩形坐标定义
            Rectangle[] _rects = new Rectangle[19];
            int i = 0;
            // 标签头部
            _rects[i] = new Rectangle(0, 0, topBox.Width, topBox.Height);
            //----------------------------------------------------------------------------- 第1行
            // 品名
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);
            //----------------------------------------------------------------------------- 第2行
            // 批号
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);
            //----------------------------------------------------------------------------- 第3行
            //标准
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);

            //牌号
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);

            //----------------------------------------------------------------------------- 第4行
            // 规格
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);

            //----------------------------------------------------------------------------- 第5行
            //重量
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, oneTypeBox.Width, oneTypeBox.Height);

            //支数
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, leftBlankBox.Width, leftBlankBox.Height);

            //----------------------------------------------------------------------------- 第6行
            // 生产日期
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, prodDateLeftBox.Width, prodDateLeftBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, prodDateBlankBox.Width, prodDateBlankBox.Height);
            //----------------------------------------------------------------------------- 第7行
            // 底部的条码区
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, barcodeBox.Width, barcodeBox.Height);
            // 地址区
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height+1, addrBox.Width, addrBox.Height);
            // 坐标单位转换 mm -> dot
            for (i = 0; i < _rects.Length; i++)
            {
                _rects[i].X = (int)(_rects[i].X * dotMM);
                _rects[i].Y = (int)(_rects[i].Y * dotMM) - 65;
                _rects[i].Width = (int)(_rects[i].Width * dotMM);
                _rects[i].Height = (int)(_rects[i].Height * dotMM);
            }

            // 定义字体
            Font CFont = new Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font EFont = new Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sEFont = new Font("Arial", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sCFont = new Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            //Font ssCFont = new Font("隶书", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

            Font cCFont = new Font("隶书", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font eEFont = new Font("Arial", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            StringFormat drawFormat1 = new StringFormat();
            drawFormat1.Alignment = StringAlignment.Center;
            drawFormat1.LineAlignment = StringAlignment.Center;
            // add by [bhb]
            StringFormat formatLeft = new StringFormat();
            formatLeft.Alignment = StringAlignment.Near;
            formatLeft.LineAlignment = StringAlignment.Near;
            //===========================画矩形===========================
            //Pen rectPen = new Pen(Brushes.Blue, 2);
            //for (i = 0; i < _rects.Length; i++)
            //{
            //    e.Graphics.DrawRectangle(rectPen, _rects[i]);
            //}

            //===========================打印数据===========================
            //打印品名
            _rects[2].Y -= 24;
            e.Graphics.DrawString(_lable.PM, EFont, Brushes.Black, _rects[2], drawFormat1);
            _rects[4].Y -= 24;
            //打印批次号
            if (_lable.BandNo.Length == 1)
                e.Graphics.DrawString(_lable.BatchNo + "   0" + _lable.BandNo, EFont, Brushes.Black, _rects[4], drawFormat1);
            else
                e.Graphics.DrawString(_lable.BatchNo + "   " + _lable.BandNo, EFont, Brushes.Black, _rects[4], drawFormat1);

            //打印标准
            e.Graphics.DrawString(_lable.Standard, EFont, Brushes.Black, _rects[6], drawFormat1);
            // 打印牌号\ 增加X的偏移量
               // _rects[6].X -= 10;
            _rects[8].Y -= 24;
            _rects[8].X = 56;
            e.Graphics.DrawString(_lable.SteelType, EFont, Brushes.Black, _rects[8], drawFormat1);

            //打印规格
            e.Graphics.DrawString( _lable.Spec, EFont, Brushes.Black, _rects[10], drawFormat1);
            //打印重量

            e.Graphics.DrawString(_lable.Weight, EFont, Brushes.Black, _rects[12], drawFormat1); //重量
            //打印支数
            //e.Graphics.DrawString(_lable.Count, EFont, Brushes.Black, _rects[14], drawFormat1); //重量
            //打印生产日期
            e.Graphics.DrawString(_lable.Date.ToString("yyyy") + "-" + _lable.Date.ToString("MM") + "-" + _lable.Date.ToString("dd") + "    " + _lable.Term, CFont, Brushes.Black, _rects[16], drawFormat1); //生产日期
            // 打印条码
            Code128 c128 = new Code128();
            c128.printPipeCode(_lable.BarCode, _rects[17], e);

            // 打印地址
            if (Data.PrintAddress)
            {
                e.Graphics.DrawString("云南 ● 玉溪", sCFont, Brushes.Black, _rects[18], drawFormat1); //地点
            }
        }