add-添加库位码打印

dev
liuwf 1 week ago
parent 624328a050
commit ad63f9a886

@ -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
/// </summary>
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);//替换后字符串
/// <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);
if (pringFlag == false)
{
Console.WriteLine("打印错误,检查后请重新操作!");
}
}
}
}

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

@ -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)

@ -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; } = "";
}

Loading…
Cancel
Save