diff --git a/PrintBarCode/Business/PrintBusiness.cs b/PrintBarCode/Business/PrintBusiness.cs index 5a9a521..8c40408 100644 --- a/PrintBarCode/Business/PrintBusiness.cs +++ b/PrintBarCode/Business/PrintBusiness.cs @@ -2,6 +2,7 @@ using PrintBarCode.Model; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -134,29 +135,46 @@ namespace PrintBarCode.Business /// public void PrintSmallBarCodeInfo(SmallCodeInfo smallCodeInfo) { - // 拼接成目标文件的完整路径 - string path = Path.Combine(basePath, "templates", "smallTemplate.prn"); - - string[] args = new string[] + try { + // 拼接成目标文件的完整路径 + string path = Path.Combine(basePath, "templates", "smallTemplate.prn"); + + string[] args = new string[] + { smallCodeInfo.QrCode, - smallCodeInfo.Text, - }; + smallCodeInfo.Text, + }; + + // 将属性值用 "~" 连接起来,不带前缀 + string TempStr = $"{smallCodeInfo.QrCode}~{smallCodeInfo.Text}"; + + string ZplStr = PrintH.GetPrintString(path, TempStr);//替换后字符串 + + bool pringFlag = zplp.SendStringToPrinter(debugConfig.PrintName, ZplStr); + if (pringFlag == false) + { + Console.WriteLine("打印错误,检查后请重新操作!"); + } + }catch (Exception ex) + { + Console.WriteLine("打印错误,检查后请重新操作!"); + } + } + - // 将属性值用 "~" 连接起来,不带前缀 - string TempStr = $"{smallCodeInfo.QrCode}~{smallCodeInfo.Text}"; - string ZplStr = PrintH.GetPrintString(path, TempStr);//替换后字符串 + /// + /// 打印空白页 + /// + public void PrintBlankPage() + { + string ZplStr = "^XA^MMT^FS ^LH0,0^FO50,50^ADN,36,20^FDTest Page^FS^FO50,350^GB700,10,10^FS^XZ";//空白页 bool pringFlag = zplp.SendStringToPrinter(debugConfig.PrintName, ZplStr); - if (pringFlag == false) - { - Console.WriteLine("打印错误,检查后请重新操作!"); - } } - } } diff --git a/PrintBarCode/Helper/JsonParser.cs b/PrintBarCode/Helper/JsonParser.cs index f4ede58..2d2b4de 100644 --- a/PrintBarCode/Helper/JsonParser.cs +++ b/PrintBarCode/Helper/JsonParser.cs @@ -23,22 +23,26 @@ namespace PrintBarCode.Helper { var rawBarCodeInfoList = JsonSerializer.Deserialize>(output.PrintContent); + //rawBarCodeInfoList.Add(new RawBarCodeInfo()); return rawBarCodeInfoList.Cast().ToList(); } else if (output.Template == "product") { var productBarCodeInfoList = JsonSerializer.Deserialize>(output.PrintContent); + // productBarCodeInfoList.Add(new ProductBarCodeInfo()); return productBarCodeInfoList.Cast().ToList(); } else if(output.Template == "bind") { var bindBarCodeInfoList = JsonSerializer.Deserialize>(output.PrintContent); + //bindBarCodeInfoList.Add(new BindBarCodeInfo()); return bindBarCodeInfoList.Cast().ToList(); } else if(output.Template == "small") { var smallCodeInfoList = JsonSerializer.Deserialize>(output.PrintContent); + // smallCodeInfoList.Add(new SmallCodeInfo()); return smallCodeInfoList.Cast().ToList(); } else diff --git a/PrintBarCode/MessageClient.cs b/PrintBarCode/MessageClient.cs index 1da5dde..fe59cae 100644 --- a/PrintBarCode/MessageClient.cs +++ b/PrintBarCode/MessageClient.cs @@ -80,6 +80,7 @@ namespace PrintBarCode private void Listening() { + int IsPrintBlank = 0; Task.Run(() => { Thread.Sleep(1000 * 2); @@ -89,9 +90,10 @@ namespace PrintBarCode { string channelWork = $"print_{debugConfig.IP}"; string jsonString = _redisHandler.ConsumeMessageFromWorker(channelWork); - // string jsonString = "{\"template\":\"product\",\"printContent\":\"[{\\\"saleOrderCode\\\":\\\"\\\",\\\"materialName\\\":\\\"多功能自动剥线钳\\\",\\\"qrcode\\\":\\\"20241019112921CP001\\\",\\\"materialSpec\\\":\\\"\\\",\\\"qty\\\":\\\"1\\\",\\\"materialCode\\\":\\\"MES.MC.A00861\\\",\\\"barcode\\\":\\\"20241019112921CP001\\\",\\\"productPlanCode\\\":\\\"20241019111402JL012\\\"}]\"}"; + // string jsonString = "{\"template\":\"small\",\"printContent\":\"[{\\\"text\\\":\\\"李华\\\",\\\"qrcode\\\":\\\"12001\\\"}]\"}"; if (!string.IsNullOrEmpty(jsonString)) { + IsPrintBlank = 1; var result = JsonParser.ParseJson(jsonString); if (result != null) { @@ -101,7 +103,6 @@ namespace PrintBarCode { addLogEvent?.Invoke(rawBarCodeInfo.ToJson()); printBusiness.PrintRawBarCodeInfo(rawBarCodeInfo); - } else if (item is ProductBarCodeInfo productBarCodeInfo) { @@ -119,9 +120,15 @@ namespace PrintBarCode Thread.Sleep(1000); } } - } - + else + { + if(IsPrintBlank == 1) + { + printBusiness.PrintBlankPage(); + IsPrintBlank = 0; + } + } Thread.Sleep(1000 * 1); } catch (Exception ex) diff --git a/PrintBarCode/Model/SmallCodeInfo.cs b/PrintBarCode/Model/SmallCodeInfo.cs index b482ca7..f59376b 100644 --- a/PrintBarCode/Model/SmallCodeInfo.cs +++ b/PrintBarCode/Model/SmallCodeInfo.cs @@ -11,10 +11,10 @@ namespace PrintBarCode.Model { [JsonPropertyName("text")] - public string Text { get; set; } - + public string Text { get; set; } = ""; + [JsonPropertyName("qrcode")] - public string QrCode { get; set; } + public string QrCode { get; set; } = ""; }