quanzhou
2026-03-07 f6326d8e85b55a290ca88c9f14a0f2a9ecbf6971
src/Bro.M141.Process/UI/UIPrinter.cs
@@ -1,5 +1,4 @@

using Bro.Common.Helper;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.M135.Common;
using Bro.UI.Model.Winform;
@@ -17,7 +16,12 @@
using System.Windows.Forms;
using ZXing;
using ZXing.Common;
using static Bro.M141.Process.BasketCodeUI;
using ZXing.QrCode.Internal;
using static System.Windows.Forms.AxHost;
using ZXing.QrCode;
//using System.Printing;
@@ -41,24 +45,28 @@
        {
            base.OnProcessUpdated();
            printDocument1.PrintPage += new PrintPageEventHandler(printDocument_Print);
            Process141.StartPrinter += StartPrint;
            textBox1.Text = "Broconcentric";
            printDocument2.PrintPage += new PrintPageEventHandler(printDocument_Print1);
            textBox1.Text = "C229M2508250500002";
        }
        PrintDocument printDocument1 = new PrintDocument();
        int ttwith = (int)(80 * 4);
        int ttheigh = (int)(40 * 4);
        int ttwith = (int)(60 * 4);
        int ttheigh = (int)(20 * 4);
        PrintDocument printDocument2 = new PrintDocument();
        int ttwith1 = (int)(80 * 4);
        int ttheigh1 = (int)(40 * 4);
        string message = "";
        public void StartPrint(string str)
        {
            try
            {
                ttwith = 320;
                ttheigh = 160;
                ttwith = 240;
                ttheigh = 80;
                message = str;
                if (string.IsNullOrEmpty(message))
@@ -72,6 +80,14 @@
                this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();
                this.printDocument1.Print();
                //this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)1";
                //this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh);
                //this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();
                //this.printDocument1.Print();
            }
            catch
            {
@@ -82,10 +98,65 @@
            string status = GetPrinterStatusMessage(statuscode);
            //Config141
            Process141.PlcwritePrinter(1520, 0);
            Process141.PlcwritePrinter(1510, 1);
            try
            {
                Process141.PlcwritePrinter(1520, 0);
                Process141.PlcwritePrinter(1510, 1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void StartPrint1(string str)
        {
            try
            {
                ttwith1 = textBox9.Text.ToInt();
                ttheigh1 = textBox10.Text.ToInt();
                message = str;
                if (string.IsNullOrEmpty(message))
                {
                    message = textBox1.Text;
                }
                //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();
                this.printDocument2.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)1";
                this.printDocument2.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh);
                this.printDocument2.PrintController = new System.Drawing.Printing.StandardPrintController();
                this.printDocument2.Print();
            }
            catch
            {
            }
            int statuscode = GetPrinterStatusCodeInt();
            string status = GetPrinterStatusMessage(statuscode);
            //Config141
            try
            {
                Process141.PlcwritePrinter(1520, 0);
                Process141.PlcwritePrinter(1510, 1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //C229M2508250500002
        private void printDocument_Print(object sender, PrintPageEventArgs e)
        {
            Font fntTxt = new Font("黑体", 15, System.Drawing.FontStyle.Bold);//正文文字               
@@ -97,6 +168,122 @@
                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);
                BarcodeWriter writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.QR_CODE;
                QrCodeEncodingOptions options = new QrCodeEncodingOptions()
                {
                    DisableECI = true,//设置内容编码
                    CharacterSet = "UTF-8",  //设置二维码的宽度和高度
                    Width = 60,
                    Height = 60,
                    Margin = 1//设置二维码的边距,单位不是固定像素
                };
                writer.Options = options;
                Bitmap map = writer.Write(numvalue);
                e.Graphics.DrawImage(map, new System.Drawing.Point(90, 4));
                // 在二维码下方画内容文字
                using (Font font = new Font("Arial", 10))
                using (Brush brush3 = new SolidBrush(Color.Black))
                {
                    // 让文字居中到二维码下方
                    SizeF textSize = e.Graphics.MeasureString(numvalue, font);
                    float textX = 90 + (map.Width - textSize.Width) / 2;
                    float textY = 1 + map.Height;
                    e.Graphics.DrawString(numvalue, font, brush3, textX, textY);
                }
                //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);
                //BarcodeWriter writer = new BarcodeWriter();
                //writer.Format = BarcodeFormat.QR_CODE;
                //QrCodeEncodingOptions options = new QrCodeEncodingOptions()
                //{
                //    DisableECI = true,//设置内容编码
                //    CharacterSet = "UTF-8",  //设置二维码的宽度和高度
                //    Width = 123,
                //    Height = 123,
                //    Margin = 1//设置二维码的边距,单位不是固定像素
                //};
                ////第二行数据
                //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_Print1(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;
                float Scale = textBox11.Text.ToFloat();
                ///(float)0.85;
                int startX = textBox12.Text.ToInt();
                //10;
                int startY = textBox13.Text.ToInt();
                  //  -20;
                //int length = 320 * Scale;
                //int height = 160 * Scale;
@@ -120,13 +307,13 @@
                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.DrawString(@"COVER LG208I-RC100 #1", 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.DrawString(@"436LG208J000", font2, brush, (startX + 130) * Scale, (startY + 43) * Scale);
                //第四行数据
                g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 70 * Scale, 20 * Scale);
@@ -150,7 +337,7 @@
                //侧面
                g.DrawRectangle(p, (startX + 210) * Scale, (startY + 60) * Scale, 70 * Scale, 60 * Scale);
                g.DrawString(@"#2", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale);
                g.DrawString(@"#1", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale);
            }
            catch (Exception ee)
            {
@@ -279,7 +466,16 @@
            }
            StartPrint(message);
        }
        private void button4_Click(object sender, EventArgs e)
        {
            message = textBox1.Text;
            if (string.IsNullOrEmpty(message))
            {
                MessageBox.Show("打印内容不可为空");
                return;
            }
            StartPrint1(message);
        }
        //预览
        private void button2_Click(object sender, EventArgs e)
@@ -298,6 +494,27 @@
            DialogResult res = printPreviewDialog1.ShowDialog();
            printPreviewDialog1.Document.Dispose();
        }
        private void button7_Click(object sender, EventArgs e)
        {
            ttwith1 = textBox9.Text.ToInt();
            ttheigh1 = textBox10.Text.ToInt();
            message = textBox1.Text;
            if (string.IsNullOrEmpty(message))
            {
                MessageBox.Show("打印内容不可为空");
                return;
            }
            PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
            this.printDocument2.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)";
            this.printDocument2.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith1, ttheigh1);
            //this.printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument_Print);
            printPreviewDialog1.Document = printDocument2;
            DialogResult res = printPreviewDialog1.ShowDialog();
            printPreviewDialog1.Document.Dispose();
        }
@@ -317,7 +534,7 @@
            //bmp.SetResolution(320, 160);
            Graphics g = Graphics.FromImage(bmp);//利用该图片对象生成“画板”
            Graphics g = Graphics.FromImage(bmp);//利用该图片对象生成“画板”mo
            Font font = new Font("Arial", 8 * Scale);//设置字体颜色
            Font font2 = new Font("Arial", 11 * Scale);//设置字体颜色
@@ -401,16 +618,6 @@
            return bmp;
        }
        #region 
@@ -669,7 +876,7 @@
        int pronum = 0;
        private void button6_Click(object sender, EventArgs e)//sn,result,zword,zno,entray
        {
            string Msg = Task.Run(() => Process141.mqtt.MESForProduceAsync(new ProductModel() { SN = textBox3.Text, Result = textBox4.Text }, textBox5.Text, Convert.ToInt32(textBox6.Text), textBox7.Text)).Result;
            string Msg = Task.Run(() => Process141.mqtt.MESForProduceAsync(new ProductModel() { SN = textBox3.Text, Result = textBox4.Text, Zword = textBox5.Text }, textBox8.Text, Convert.ToInt32(textBox6.Text), textBox7.Text)).Result;
            if (Msg == null)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 物料 返回数据为 null");
@@ -679,9 +886,5 @@
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 物料 返回数据为 {Msg}");
            }
        }
    }
}