| | |
| | | using Bro.Common.Helper; |
| | | using Bro.Common.Interface; |
| | | using Bro.UI.Model.Winform; |
| | | using Sunny.UI; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | |
| | | using System.Windows.Forms; |
| | | using ZXing; |
| | | using ZXing.Common; |
| | | using static System.Windows.Forms.AxHost; |
| | | |
| | | //using System.Printing; |
| | | |
| | |
| | | { |
| | | base.OnProcessUpdated(); |
| | | printDocument1.PrintPage += new PrintPageEventHandler(printDocument_Print); |
| | | |
| | | Process141.StartPrinter += StartPrint; |
| | | textBox1.Text = "Broconcentric"; |
| | | } |
| | | |
| | | |
| | | |
| | | PrintDocument printDocument1 = new PrintDocument(); |
| | | int ttwith = (int)(80 * 4); |
| | |
| | | |
| | | public void StartPrint(string str) |
| | | { |
| | | ttwith = 320; |
| | | ttheigh = 160; |
| | | message = str; |
| | | try |
| | | { |
| | | ttwith = 320; |
| | | ttheigh = 160; |
| | | message = str; |
| | | |
| | | this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)"; |
| | | this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh); |
| | | if (string.IsNullOrEmpty(message)) |
| | | { |
| | | message = textBox1.Text; |
| | | } |
| | | |
| | | this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController(); |
| | | this.printDocument1.Print(); |
| | | this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)"; |
| | | this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh); |
| | | |
| | | this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController(); |
| | | this.printDocument1.Print(); |
| | | |
| | | } |
| | | catch |
| | | { |
| | | |
| | | } |
| | | |
| | | int statuscode = GetPrinterStatusCodeInt(); |
| | | string status = GetPrinterStatusMessage(statuscode); |
| | | |
| | | //Config141 |
| | | Process141.PlcwritePrinter(1520, 0); |
| | | Process141.PlcwritePrinter(1510, 1); |
| | | |
| | | } |
| | | |
| | | |
| | | private void printDocument_Print(object sender, PrintPageEventArgs e) |
| | | { |
| | | Font fntTxt = new Font("黑体", 15, System.Drawing.FontStyle.Bold);//正文文字 |
| | |
| | | try |
| | | { |
| | | string numvalue = message; |
| | | Bitmap bitmap = CreateCode(numvalue); |
| | | |
| | | int with = (ttwith - bitmap.Width) / 2 - 20; |
| | | int heih = (ttheigh - bitmap.Height) / 2; |
| | | float Scale = (float)0.95; |
| | | int startX = 10; |
| | | int startY = 25; |
| | | |
| | | //int length = 320 * Scale; |
| | | //int height = 160 * Scale; |
| | | var g = e.Graphics; |
| | | |
| | | Font font = new Font("Arial", 8 * Scale);//设置字体颜色 |
| | | Font font2 = new Font("Arial", 11 * Scale);//设置字体颜色 |
| | | Font font3 = new Font("Arial", 36 * Scale);//设置字体颜色 |
| | | Font font4 = new Font("Arial", 12 * Scale);//设置字体颜色 |
| | | |
| | | |
| | | Pen p = new Pen(Color.Black, Scale);//定义了一个黑色,宽度为1的画笔 |
| | | g.Clear(Color.White); |
| | | g.DrawRectangle(p, startX * Scale, startY * Scale, 70 * Scale, 20 * Scale);//在画板上画矩形,起始坐标为(10,10),宽为80,高为20 |
| | | g.DrawRectangle(p, startX * Scale, startY * Scale, 280 * Scale, 20 * Scale);//在画板上画矩形,起始坐标为(90,10),宽为80,高为20 |
| | | g.DrawString("厂商", font, brush, (startX + 20) * Scale, (startY + 5) * Scale);// |
| | | g.DrawString("嘉彰科技", font2, brush, (startX + 140) * Scale, (startY + 4) * Scale); |
| | | |
| | | |
| | | //第二行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 280 * Scale, 20 * Scale); |
| | | g.DrawString("品名", font, brush, (startX + 20) * Scale, (startY + 25) * Scale); |
| | | g.DrawString(@"COVER LG208H-RC100 #2", font4, brush, (startX + 71) * Scale, (startY + 22) * Scale); |
| | | |
| | | //第三行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 280 * Scale, 20 * Scale); |
| | | g.DrawString("料号", font, brush, (startX + 20) * Scale, (startY + 45) * Scale); |
| | | g.DrawString(@"436LG208I000", font2, brush, (startX + 130) * Scale, (startY + 43) * Scale); |
| | | |
| | | //第四行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("数量", font, brush, (startX + 20) * Scale, (startY + 65) * Scale); |
| | | g.DrawString(@"50PCS", font2, brush, (startX + 120) * Scale, (startY + 62) * Scale); |
| | | |
| | | //第五行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("生产日期", font, brush, (startX + 10) * Scale, (startY + 85) * Scale); |
| | | g.DrawString($"{DateTime.Now.ToString("yyyy.MM.dd")}", font2, brush, (startX + 105) * Scale, (startY + 82) * Scale); |
| | | |
| | | //第六行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 140 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("MARK1", font, brush, (startX + 15) * Scale, (startY + 104) * Scale); |
| | | g.DrawString("MARK2", font, brush, (startX + 155) * Scale, (startY + 104) * Scale); |
| | | |
| | | |
| | | //侧面 |
| | | g.DrawRectangle(p, (startX + 210) * Scale, (startY + 60) * Scale, 70 * Scale, 60 * Scale); |
| | | g.DrawString(@"#2", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale); |
| | | } |
| | | catch (Exception ee) |
| | | { |
| | | MessageBox.Show(ee.Message); |
| | | } |
| | | } |
| | | |
| | | private void printDocument_Print222(object sender, PrintPageEventArgs e) |
| | | { |
| | | Font fntTxt = new Font("黑体", 15, System.Drawing.FontStyle.Bold);//正文文字 |
| | | System.Drawing.Brush brush = new SolidBrush(System.Drawing.Color.Black);//画刷 |
| | | try |
| | | { |
| | | string numvalue = message; |
| | | //Bitmap bitmap = getexcel();// CreateCode(numvalue); |
| | | |
| | | //int with = (ttwith - bitmap.Width) / 2 - 20; |
| | | //int heih = (ttheigh - bitmap.Height) / 2; |
| | | //條碼的位置 |
| | | e.Graphics.DrawImage(bitmap, new System.Drawing.Point(with, heih)); |
| | | //e.Graphics.DrawImage(bitmap, new System.Drawing.Point(0, 0)); |
| | | //條碼信息數字的位置 |
| | | e.Graphics.DrawString(numvalue, fntTxt, brush, new System.Drawing.Point(bitmap.Width / 4 + with - 10, heih + bitmap.Height + 5)); |
| | | //e.Graphics.DrawString(numvalue, fntTxt, brush, new System.Drawing.Point(bitmap.Width / 4 + with - 10, heih + bitmap.Height + 5)); |
| | | |
| | | |
| | | //e.Graphics.DrawImage(img, new Rectangle(25, 25, bmpwidth, bmpheight), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); |
| | | int Scale = 1; |
| | | int startX = 10; |
| | | int startY = 25; |
| | | |
| | | int length = 320 * Scale; |
| | | int height = 160 * Scale; |
| | | var g = e.Graphics; |
| | | |
| | | Font font = new Font("Arial", 8 * Scale);//设置字体颜色 |
| | | Font font2 = new Font("Arial", 11 * Scale);//设置字体颜色 |
| | | Font font3 = new Font("Arial", 36 * Scale);//设置字体颜色 |
| | | Font font4 = new Font("Arial", 12 * Scale);//设置字体颜色 |
| | | |
| | | |
| | | //SolidBrush brush = new SolidBrush(Color.Black);//新建一个画刷,到这里为止,我们已经准备好了画板、画刷、和数据 |
| | | |
| | | |
| | | Pen p = new Pen(Color.Black, Scale);//定义了一个黑色,宽度为1的画笔 |
| | | g.Clear(Color.White); //设置白色背景 |
| | | //第一行数据 |
| | | g.DrawRectangle(p, startX * Scale, startY * Scale, 70 * Scale, 20 * Scale);//在画板上画矩形,起始坐标为(10,10),宽为80,高为20 |
| | | g.DrawRectangle(p, startX * Scale, startY * Scale, 280 * Scale, 20 * Scale);//在画板上画矩形,起始坐标为(90,10),宽为80,高为20 |
| | | g.DrawString("厂商", font, brush, (startX + 20) * Scale, (startY + 5) * Scale);// |
| | | g.DrawString("嘉彰科技", font2, brush, (startX + 140) * Scale, (startY + 4) * Scale); |
| | | |
| | | |
| | | //第二行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 280 * Scale, 20 * Scale); |
| | | g.DrawString("品名", font, brush, (startX + 20) * Scale, (startY + 25) * Scale); |
| | | g.DrawString(@"COVER LG208H-RC100 #2", font4, brush, (startX + 71) * Scale, (startY + 22) * Scale); |
| | | |
| | | //第三行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 280 * Scale, 20 * Scale); |
| | | g.DrawString("料号", font, brush, (startX + 20) * Scale, (startY + 45) * Scale); |
| | | g.DrawString(@"436LG208I000", font2, brush, (startX + 130) * Scale, (startY + 43) * Scale); |
| | | |
| | | //第四行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("数量", font, brush, (startX + 20) * Scale, (startY + 65) * Scale); |
| | | g.DrawString(@"50PCS", font2, brush, (startX + 120) * Scale, (startY + 62) * Scale); |
| | | |
| | | //第五行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("生产日期", font, brush, (startX + 10) * Scale, (startY + 85) * Scale); |
| | | g.DrawString($"{DateTime.Now.ToString("yyyy.MM.dd")}", font2, brush, (startX + 105) * Scale, (startY + 82) * Scale); |
| | | |
| | | //第六行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 140 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("MARK1", font, brush, (startX + 15) * Scale, (startY + 104) * Scale); |
| | | g.DrawString("MARK2", font, brush, (startX + 155) * Scale, (startY + 104) * Scale); |
| | | |
| | | |
| | | //侧面 |
| | | g.DrawRectangle(p, (startX + 210) * Scale, (startY + 60) * Scale, 70 * Scale, 60 * Scale); |
| | | g.DrawString(@"#2", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | catch (Exception ee) |
| | |
| | | PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog(); |
| | | this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)"; |
| | | this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh); |
| | | this.printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument_Print); |
| | | //this.printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument_Print); |
| | | printPreviewDialog1.Document = printDocument1; |
| | | DialogResult res = printPreviewDialog1.ShowDialog(); |
| | | printPreviewDialog1.Document.Dispose(); |
| | | } |
| | | |
| | | |
| | | |
| | | public Bitmap getexcel() |
| | | { |
| | | |
| | | |
| | | int startX = 10; |
| | | int startY = 25; |
| | | |
| | | int Scale = 1; |
| | | |
| | | int length = 320 * Scale; |
| | | int height = 160 * Scale; |
| | | |
| | | Bitmap bmp = new Bitmap(length, height);//, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//新建一个图片对象 |
| | | |
| | | //bmp.SetResolution(320, 160); |
| | | |
| | | Graphics g = Graphics.FromImage(bmp);//利用该图片对象生成“画板” |
| | | |
| | | Font font = new Font("Arial", 8 * Scale);//设置字体颜色 |
| | | Font font2 = new Font("Arial", 11 * Scale);//设置字体颜色 |
| | | Font font3 = new Font("Arial", 36 * Scale);//设置字体颜色 |
| | | Font font4 = new Font("Arial", 12 * Scale);//设置字体颜色 |
| | | |
| | | |
| | | SolidBrush brush = new SolidBrush(Color.Black);//新建一个画刷,到这里为止,我们已经准备好了画板、画刷、和数据 |
| | | |
| | | //g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; |
| | | //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; |
| | | //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; |
| | | |
| | | |
| | | //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; |
| | | //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; |
| | | //g.PixelOffsetMode = PixelOffsetMode.Half; |
| | | |
| | | |
| | | Pen p = new Pen(Color.Black, Scale);//定义了一个黑色,宽度为1的画笔 |
| | | g.Clear(Color.White); //设置白色背景 |
| | | //第一行数据 |
| | | g.DrawRectangle(p, startX * Scale, startY * Scale, 70 * Scale, 20 * Scale);//在画板上画矩形,起始坐标为(10,10),宽为80,高为20 |
| | | g.DrawRectangle(p, startX * Scale, startY * Scale, 280 * Scale, 20 * Scale);//在画板上画矩形,起始坐标为(90,10),宽为80,高为20 |
| | | g.DrawString("厂商", font, brush, (startX + 20) * Scale, (startY + 5) * Scale);// |
| | | g.DrawString("嘉彰科技", font2, brush, (startX + 140) * Scale, (startY + 4) * Scale); |
| | | |
| | | |
| | | //第二行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 280 * Scale, 20 * Scale); |
| | | g.DrawString("品名", font, brush, (startX + 20) * Scale, (startY + 25) * Scale); |
| | | g.DrawString(@"COVER LG208H-RC100 #2", font4, brush, (startX + 71) * Scale, (startY + 22) * Scale); |
| | | |
| | | //第三行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 280 * Scale, 20 * Scale); |
| | | g.DrawString("料号", font, brush, (startX + 20) * Scale, (startY + 45) * Scale); |
| | | g.DrawString(@"436LG208I000", font2, brush, (startX + 130) * Scale, (startY + 43) * Scale); |
| | | |
| | | //第四行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("数量", font, brush, (startX + 20) * Scale, (startY + 65) * Scale); |
| | | g.DrawString(@"50PCS", font2, brush, (startX + 120) * Scale, (startY + 62) * Scale); |
| | | |
| | | //第五行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("生产日期", font, brush, (startX + 10) * Scale, (startY + 85) * Scale); |
| | | g.DrawString($"{DateTime.Now.ToString("yyyy.MM.dd")}", font2, brush, (startX + 105) * Scale, (startY + 82) * Scale); |
| | | |
| | | //第六行数据 |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 70 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 140 * Scale, 20 * Scale); |
| | | g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 210 * Scale, 20 * Scale); |
| | | g.DrawString("MARK1", font, brush, (startX + 15) * Scale, (startY + 104) * Scale); |
| | | g.DrawString("MARK2", font, brush, (startX + 155) * Scale, (startY + 104) * Scale); |
| | | |
| | | |
| | | //侧面 |
| | | g.DrawRectangle(p, (startX + 210) * Scale, (startY + 60) * Scale, 70 * Scale, 60 * Scale); |
| | | g.DrawString(@"#2", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //Font font22 = new Font("Arial", 6);//设置字体颜色 |
| | | //for (int i = 0; i < 32;i++) |
| | | //{ |
| | | // g.DrawString(i.ToString(), font22, brush, 0, i*10); |
| | | // g.DrawString(i.ToString(), font22, brush, i * 10, 0); |
| | | //} |
| | | |
| | | //bmp.Save("E:/test.bmp");//保存为输出流,否则页面上显示不出来 |
| | | g.Dispose();//释放掉该资源 |
| | | |
| | | bmp.SetResolution(105 * Scale, 105 * Scale); |
| | | |
| | | |
| | | return bmp; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | #region |
| | | [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)] |
| | |
| | | int statuscode = GetPrinterStatusCodeInt(); |
| | | string status = GetPrinterStatusMessage(statuscode); |
| | | //只有在打印机异常时再次下发打印任务后,才能获取到打印机状态。这是因为打印机驱动程序通常只在处理打印请求时更新其状态信息。如果打印机没有接收到新的打印任务,可能无法立即反映出真实状态。 |
| | | textBox2.Text = "taskNum:" + taskNum+ ",statuscode:"+ statuscode+",status:"+status; |
| | | textBox2.Text = "taskNum:" + taskNum + ",statuscode:" + statuscode + ",status:" + status; |
| | | } |
| | | } |
| | | } |