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; } + + + } +}