From 305e2990bb2161177e87ab7711f9dfb205762bcd Mon Sep 17 00:00:00 2001 From: kingno <30263@KINGNO> Date: 星期一, 09 六月 2025 15:52:42 +0800 Subject: [PATCH] 优化数据传递 --- src/Bro.M141.Process/UI/UIPrinter.cs | 545 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 529 insertions(+), 16 deletions(-) diff --git a/src/Bro.M141.Process/UI/UIPrinter.cs b/src/Bro.M141.Process/UI/UIPrinter.cs index 950a1d0..949bd0d 100644 --- a/src/Bro.M141.Process/UI/UIPrinter.cs +++ b/src/Bro.M141.Process/UI/UIPrinter.cs @@ -2,6 +2,7 @@ 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; @@ -9,12 +10,15 @@ using System.Drawing; using System.Drawing.Printing; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ZXing; using ZXing.Common; +using static System.Windows.Forms.AxHost; +//using System.Printing; namespace Bro.M141.Process { @@ -36,7 +40,12 @@ { base.OnProcessUpdated(); printDocument1.PrintPage += new PrintPageEventHandler(printDocument_Print); + + Process141.StartPrinter += StartPrint; + textBox1.Text = "Broconcentric"; } + + PrintDocument printDocument1 = new PrintDocument(); int ttwith = (int)(80 * 4); @@ -45,19 +54,37 @@ 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);//姝f枃鏂囧瓧 @@ -65,14 +92,153 @@ 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);//姝f枃鏂囧瓧 + 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) @@ -124,12 +290,359 @@ return; } PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog(); - this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240 (300 dpi)"; + 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)] + private static extern bool OpenPrinter(string pPrinterName, out IntPtr hPrinter, IntPtr pDefault); + + + [DllImport("winspool.drv", SetLastError = true)] + private static extern bool ClosePrinter(IntPtr hPrinter); + + + [DllImport("winspool.drv", SetLastError = true)] + private static extern bool GetPrinter(IntPtr hPrinter, + int dwLevel, IntPtr pPrinter, int cbBuf, out int pcbNeeded); + + + [DllImport("winspool.drv", CharSet = CharSet.Auto)] + public static extern int EnumJobs(IntPtr hPrinter, int FirstJob, int NoJobs, int Level, IntPtr pInfo, int cdBuf, + out int pcbNeeded, out int pcReturned); + + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public struct PRINTER_INFO_2 + { + public string pServerName; + public string pPrinterName; + public string pShareName; + public string pPortName; + public string pDriverName; + public string pComment; + public string pLocation; + public IntPtr pDevMode; + public string pSepFile; + public string pPrintProcessor; + public string pDatatype; + public string pParameters; + public IntPtr pSecurityDescriptor; + public uint Attributes; + public uint Priority; + public uint DefaultPriority; + public uint StartTime; + public uint UntilTime; + public uint Status; + public uint cJobs; + public uint AveragePPM; + } + + /// <summary> + /// 榛樿鎵撳嵃鏈虹殑鍚嶇О + /// </summary> + //private static string printerName = new LocalPrintServer().DefaultPrintQueue.Name; + private static string printerName = "Honeywell PX240S (300 dpi)"; + + /// <summary> + /// 鑾峰彇鎵撳嵃鏈虹殑鐘舵�佺紪鐮�(鏂瑰紡1) + /// </summary> + /// <returns></returns> + public static int GetPrinterStatusCodeInt() + { + int intRet = -1; + IntPtr hPrinter; + + + if (OpenPrinter(printerName, out hPrinter, IntPtr.Zero)) + { + int cbNeeded = 0; + bool bolRet = GetPrinter(hPrinter, 2, IntPtr.Zero, 0, out cbNeeded); + if (cbNeeded > 0) + { + IntPtr pAddr = Marshal.AllocHGlobal((int)cbNeeded); + bolRet = GetPrinter(hPrinter, 2, pAddr, cbNeeded, out cbNeeded); + if (bolRet) + { + PRINTER_INFO_2 Info2 = new PRINTER_INFO_2(); + + + Info2 = (PRINTER_INFO_2)Marshal.PtrToStructure(pAddr, typeof(PRINTER_INFO_2)); + + + intRet = System.Convert.ToInt32(Info2.Status); + } + Marshal.FreeHGlobal(pAddr); + } + ClosePrinter(hPrinter); + } + + + return intRet; + } + /// <summary> + /// 妫�鏌ユ墦鍗版満鏄惁鍙敤(鏂瑰紡1) + /// </summary> + /// <param name="intStatusCodeValue"></param> + /// <returns></returns> + public static bool CheckIsEnable(int intStatusCodeValue) + { + bool isEnable = false; + if (UIPrinter.GetTaskNumber() == 0) + { + return true; + } + if (intStatusCodeValue == 0x0008000 || intStatusCodeValue == 0x00000400 || intStatusCodeValue == 0x00004000) + { + return true; + } + return isEnable; + } + + + /// <summary> + /// 鑾峰彇鎵撳嵃鏈虹殑鐘舵�佷俊鎭�(鏂瑰紡1) + /// </summary> + /// <returns></returns> + public static string GetPrinterStatusMessage(int intStatusCodeValue) + { + string strRet = string.Empty; + switch (intStatusCodeValue) + { + case 0: + strRet = "鍑嗗灏辩华锛圧eady锛�"; + break; + case 0x00000200: + strRet = "蹇�(Busy锛�"; + break; + case 0x00400000: + strRet = "琚墦寮�锛圥rinter Door Open锛�"; + break; + case 0x00000002: + strRet = "閿欒(Printer Error锛�"; + break; + case 0x0008000: + strRet = "鍒濆鍖�(Initializing锛�"; + break; + case 0x00000100: + strRet = "姝e湪杈撳叆,杈撳嚭锛圛/O Active锛�"; + break; + case 0x00000020: + strRet = "鎵嬪伐閫佺焊锛圡anual Feed锛�"; + break; + case 0x00040000: + strRet = "鏃犲ⅷ绮夛紙No Toner锛�"; + break; + case 0x00001000: + strRet = "涓嶅彲鐢紙Not Available锛�"; + break; + case 0x00000080: + strRet = "鑴辨満锛圤ff Line锛�"; + break; + case 0x00200000: + strRet = "鍐呭瓨婧㈠嚭锛圤ut of Memory锛�"; + break; + case 0x00000800: + strRet = "杈撳嚭鍙e凡婊★紙Output Bin Full锛�"; + break; + case 0x00080000: + strRet = "褰撳墠椤垫棤娉曟墦鍗帮紙Page Punt锛�"; + break; + case 0x00000008: + strRet = "濉炵焊锛圥aper Jam锛�"; + break; + case 0x00000010: + strRet = "鎵撳嵃绾哥敤瀹岋紙Paper Out锛�"; + break; + case 0x00000040: + strRet = "绾稿紶闂锛圥age Problem锛�"; + break; + case 0x00000001: + strRet = "鏆傚仠锛圥aused锛�"; + break; + case 0x00000004: + strRet = "姝e湪鍒犻櫎锛圥ending Deletion锛�"; + break; + case 0x00000400: + strRet = "姝e湪鎵撳嵃锛圥rinting锛�"; + break; + case 0x00004000: + strRet = "姝e湪澶勭悊锛圥rocessing锛�"; + break; + case 0x00020000: + strRet = "澧ㄧ矇涓嶈冻锛圱oner Low锛�"; + break; + case 0x00100000: + strRet = "闇�瑕佺敤鎴峰共棰勶紙User Intervention锛�"; + break; + case 0x20000000: + strRet = "绛夊緟锛圵aiting锛�"; + break; + case 0x00010000: + strRet = "鐑満涓紙Warming Up锛�"; + break; + case 1048706: + strRet = "鑹插甫宸茬敤灏�"; + break; + default: + strRet = "鏈煡鐘舵�侊紙Unknown Status锛�"; + break; + } + return strRet; + } + + /// <summary> + /// 鑾峰彇鎵撳嵃鏈烘鍦ㄦ墦鍗扮殑浠诲姟鏁�(鏂瑰紡1) + /// </summary> + /// <returns></returns> + public static int GetTaskNumber() + { + IntPtr handle; + int FirstJob = 0; + int NumJobs = 127; + int pcbNeeded; + int pcReturned = -1; + OpenPrinter(printerName, out handle, IntPtr.Zero); + // get num bytes required, here we assume the maxt job for the printer quest is 128 (0..127) + EnumJobs(handle, FirstJob, NumJobs, 1, IntPtr.Zero, 0, out pcbNeeded, out pcReturned); + + // allocate unmanaged memory + IntPtr pData = Marshal.AllocHGlobal(pcbNeeded); + + // get structs + EnumJobs(handle, FirstJob, NumJobs, 1, pData, pcbNeeded, out pcbNeeded, out pcReturned); + + return pcReturned; + } + #endregion + + + private void button3_Click(object sender, EventArgs e) + { + int taskNum = GetTaskNumber(); + int statuscode = GetPrinterStatusCodeInt(); + string status = GetPrinterStatusMessage(statuscode); + //鍙湁鍦ㄦ墦鍗版満寮傚父鏃跺啀娆′笅鍙戞墦鍗颁换鍔″悗锛屾墠鑳借幏鍙栧埌鎵撳嵃鏈虹姸鎬併�傝繖鏄洜涓烘墦鍗版満椹卞姩绋嬪簭閫氬父鍙湪澶勭悊鎵撳嵃璇锋眰鏃舵洿鏂板叾鐘舵�佷俊鎭�傚鏋滄墦鍗版満娌℃湁鎺ユ敹鍒版柊鐨勬墦鍗颁换鍔★紝鍙兘鏃犳硶绔嬪嵆鍙嶆槧鍑虹湡瀹炵姸鎬併�� + textBox2.Text = "taskNum:" + taskNum + ",statuscode:" + statuscode + ",status:" + status; + } } } -- Gitblit v1.8.0