From 624328a0509d60262f6e30d8878d0e0385d5b4b1 Mon Sep 17 00:00:00 2001 From: liuwf Date: Thu, 7 Nov 2024 13:20:53 +0800 Subject: [PATCH] =?UTF-8?q?add-=E6=B7=BB=E5=8A=A0=E5=BA=93=E4=BD=8D?= =?UTF-8?q?=E7=A0=81=E6=89=93=E5=8D=B0=E6=A8=A1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrintBarCode/Business/PrintBusiness.cs | 28 ++++++++++++++++++++++++++ PrintBarCode/Helper/JsonParser.cs | 7 ++++++- PrintBarCode/MessageClient.cs | 4 ++++ PrintBarCode/Model/SmallCodeInfo.cs | 21 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 PrintBarCode/Model/SmallCodeInfo.cs diff --git a/PrintBarCode/Business/PrintBusiness.cs b/PrintBarCode/Business/PrintBusiness.cs index da3434c..5a9a521 100644 --- a/PrintBarCode/Business/PrintBusiness.cs +++ b/PrintBarCode/Business/PrintBusiness.cs @@ -129,6 +129,34 @@ namespace PrintBarCode.Business } + /// + /// 打印小条码库位码方法 + /// + public void PrintSmallBarCodeInfo(SmallCodeInfo smallCodeInfo) + { + // 拼接成目标文件的完整路径 + string path = Path.Combine(basePath, "templates", "smallTemplate.prn"); + + string[] args = new string[] + { + smallCodeInfo.QrCode, + 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("打印错误,检查后请重新操作!"); + } + } + + } } diff --git a/PrintBarCode/Helper/JsonParser.cs b/PrintBarCode/Helper/JsonParser.cs index 3de73aa..f4ede58 100644 --- a/PrintBarCode/Helper/JsonParser.cs +++ b/PrintBarCode/Helper/JsonParser.cs @@ -36,7 +36,12 @@ namespace PrintBarCode.Helper var bindBarCodeInfoList = JsonSerializer.Deserialize>(output.PrintContent); return bindBarCodeInfoList.Cast().ToList(); } - else + else if(output.Template == "small") + { + var smallCodeInfoList = JsonSerializer.Deserialize>(output.PrintContent); + return smallCodeInfoList.Cast().ToList(); + } + else { return null; } diff --git a/PrintBarCode/MessageClient.cs b/PrintBarCode/MessageClient.cs index cec3d07..1da5dde 100644 --- a/PrintBarCode/MessageClient.cs +++ b/PrintBarCode/MessageClient.cs @@ -111,6 +111,10 @@ namespace PrintBarCode { addLogEvent?.Invoke(bindBarCodeInfo.ToJson()); printBusiness.PrintBindBarCodeInfo(bindBarCodeInfo); + }else if(item is SmallCodeInfo smallCodeInfo) + { + addLogEvent?.Invoke(smallCodeInfo.ToJson()); + printBusiness.PrintSmallBarCodeInfo(smallCodeInfo); } Thread.Sleep(1000); } diff --git a/PrintBarCode/Model/SmallCodeInfo.cs b/PrintBarCode/Model/SmallCodeInfo.cs new file mode 100644 index 0000000..b482ca7 --- /dev/null +++ b/PrintBarCode/Model/SmallCodeInfo.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace PrintBarCode.Model +{ + public class SmallCodeInfo + { + + [JsonPropertyName("text")] + public string Text { get; set; } + + [JsonPropertyName("qrcode")] + public string QrCode { get; set; } + + + } +}