add-添加库位码打印

dev
liuwf 1 week ago
parent 624328a050
commit ad63f9a886

@ -2,6 +2,7 @@
using PrintBarCode.Model; using PrintBarCode.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -133,6 +134,8 @@ namespace PrintBarCode.Business
/// 打印小条码库位码方法 /// 打印小条码库位码方法
/// </summary> /// </summary>
public void PrintSmallBarCodeInfo(SmallCodeInfo smallCodeInfo) public void PrintSmallBarCodeInfo(SmallCodeInfo smallCodeInfo)
{
try
{ {
// 拼接成目标文件的完整路径 // 拼接成目标文件的完整路径
string path = Path.Combine(basePath, "templates", "smallTemplate.prn"); string path = Path.Combine(basePath, "templates", "smallTemplate.prn");
@ -146,7 +149,6 @@ namespace PrintBarCode.Business
// 将属性值用 "~" 连接起来,不带前缀 // 将属性值用 "~" 连接起来,不带前缀
string TempStr = $"{smallCodeInfo.QrCode}~{smallCodeInfo.Text}"; string TempStr = $"{smallCodeInfo.QrCode}~{smallCodeInfo.Text}";
string ZplStr = PrintH.GetPrintString(path, TempStr);//替换后字符串 string ZplStr = PrintH.GetPrintString(path, TempStr);//替换后字符串
bool pringFlag = zplp.SendStringToPrinter(debugConfig.PrintName, ZplStr); bool pringFlag = zplp.SendStringToPrinter(debugConfig.PrintName, ZplStr);
@ -154,9 +156,25 @@ namespace PrintBarCode.Business
{ {
Console.WriteLine("打印错误,检查后请重新操作!"); Console.WriteLine("打印错误,检查后请重新操作!");
} }
}catch (Exception ex)
{
Console.WriteLine("打印错误,检查后请重新操作!");
} }
}
/// <summary>
/// 打印空白页
/// </summary>
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);
}
} }
} }

@ -23,22 +23,26 @@ namespace PrintBarCode.Helper
{ {
var rawBarCodeInfoList = JsonSerializer.Deserialize<List<RawBarCodeInfo>>(output.PrintContent); var rawBarCodeInfoList = JsonSerializer.Deserialize<List<RawBarCodeInfo>>(output.PrintContent);
//rawBarCodeInfoList.Add(new RawBarCodeInfo());
return rawBarCodeInfoList.Cast<object>().ToList(); return rawBarCodeInfoList.Cast<object>().ToList();
} }
else if (output.Template == "product") else if (output.Template == "product")
{ {
var productBarCodeInfoList = JsonSerializer.Deserialize<List<ProductBarCodeInfo>>(output.PrintContent); var productBarCodeInfoList = JsonSerializer.Deserialize<List<ProductBarCodeInfo>>(output.PrintContent);
// productBarCodeInfoList.Add(new ProductBarCodeInfo());
return productBarCodeInfoList.Cast<object>().ToList(); return productBarCodeInfoList.Cast<object>().ToList();
} }
else if(output.Template == "bind") else if(output.Template == "bind")
{ {
var bindBarCodeInfoList = JsonSerializer.Deserialize<List<BindBarCodeInfo>>(output.PrintContent); var bindBarCodeInfoList = JsonSerializer.Deserialize<List<BindBarCodeInfo>>(output.PrintContent);
//bindBarCodeInfoList.Add(new BindBarCodeInfo());
return bindBarCodeInfoList.Cast<object>().ToList(); return bindBarCodeInfoList.Cast<object>().ToList();
} }
else if(output.Template == "small") else if(output.Template == "small")
{ {
var smallCodeInfoList = JsonSerializer.Deserialize<List<SmallCodeInfo>>(output.PrintContent); var smallCodeInfoList = JsonSerializer.Deserialize<List<SmallCodeInfo>>(output.PrintContent);
// smallCodeInfoList.Add(new SmallCodeInfo());
return smallCodeInfoList.Cast<object>().ToList(); return smallCodeInfoList.Cast<object>().ToList();
} }
else else

@ -80,6 +80,7 @@ namespace PrintBarCode
private void Listening() private void Listening()
{ {
int IsPrintBlank = 0;
Task.Run(() => Task.Run(() =>
{ {
Thread.Sleep(1000 * 2); Thread.Sleep(1000 * 2);
@ -89,9 +90,10 @@ namespace PrintBarCode
{ {
string channelWork = $"print_{debugConfig.IP}"; string channelWork = $"print_{debugConfig.IP}";
string jsonString = _redisHandler.ConsumeMessageFromWorker(channelWork); 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)) if (!string.IsNullOrEmpty(jsonString))
{ {
IsPrintBlank = 1;
var result = JsonParser.ParseJson(jsonString); var result = JsonParser.ParseJson(jsonString);
if (result != null) if (result != null)
{ {
@ -101,7 +103,6 @@ namespace PrintBarCode
{ {
addLogEvent?.Invoke(rawBarCodeInfo.ToJson()); addLogEvent?.Invoke(rawBarCodeInfo.ToJson());
printBusiness.PrintRawBarCodeInfo(rawBarCodeInfo); printBusiness.PrintRawBarCodeInfo(rawBarCodeInfo);
} }
else if (item is ProductBarCodeInfo productBarCodeInfo) else if (item is ProductBarCodeInfo productBarCodeInfo)
{ {
@ -119,9 +120,15 @@ namespace PrintBarCode
Thread.Sleep(1000); Thread.Sleep(1000);
} }
} }
} }
else
{
if(IsPrintBlank == 1)
{
printBusiness.PrintBlankPage();
IsPrintBlank = 0;
}
}
Thread.Sleep(1000 * 1); Thread.Sleep(1000 * 1);
} }
catch (Exception ex) catch (Exception ex)

@ -11,10 +11,10 @@ namespace PrintBarCode.Model
{ {
[JsonPropertyName("text")] [JsonPropertyName("text")]
public string Text { get; set; } public string Text { get; set; } = "";
[JsonPropertyName("qrcode")] [JsonPropertyName("qrcode")]
public string QrCode { get; set; } public string QrCode { get; set; } = "";
} }

Loading…
Cancel
Save