add-添加打印日志

dev
liuwf 3 weeks ago
parent 58815381fe
commit a16bc8d39f

@ -29,24 +29,56 @@
private void InitializeComponent() private void InitializeComponent()
{ {
label1 = new Label(); label1 = new Label();
logList = new ListBox();
label2 = new Label();
SuspendLayout(); SuspendLayout();
// //
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Font = new Font("Microsoft YaHei UI", 21.75F, FontStyle.Bold, GraphicsUnit.Point); label1.Font = new Font("Microsoft YaHei UI", 26.25F, FontStyle.Bold, GraphicsUnit.Point);
label1.Location = new Point(76, 115); label1.ForeColor = SystemColors.MenuHighlight;
label1.Location = new Point(664, 19);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(307, 39); label1.Size = new Size(230, 46);
label1.TabIndex = 0; label1.TabIndex = 0;
label1.Text = "打印条码服务启动成功"; label1.Text = "打印条码服务";
//
// logList
//
logList.BackColor = SystemColors.InactiveCaption;
logList.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Bold, GraphicsUnit.Point);
logList.ForeColor = Color.ForestGreen;
logList.FormattingEnabled = true;
logList.HorizontalScrollbar = true;
logList.ItemHeight = 26;
logList.Location = new Point(12, 123);
logList.Name = "logList";
logList.Size = new Size(1439, 654);
logList.TabIndex = 1;
//
// label2
//
label2.AutoSize = true;
label2.Font = new Font("Microsoft YaHei UI", 15.75F, FontStyle.Bold, GraphicsUnit.Point);
label2.ForeColor = SystemColors.HotTrack;
label2.Location = new Point(12, 85);
label2.Name = "label2";
label2.Size = new Size(117, 28);
label2.TabIndex = 2;
label2.Text = "打印日志:";
// //
// MainForm // MainForm
// //
AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(451, 262); BackColor = SystemColors.ActiveCaption;
ClientSize = new Size(1454, 811);
ControlBox = false;
Controls.Add(label2);
Controls.Add(logList);
Controls.Add(label1); Controls.Add(label1);
FormBorderStyle = FormBorderStyle.FixedDialog;
Name = "MainForm"; Name = "MainForm";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
Text = "打印条码服务"; Text = "打印条码服务";
@ -57,5 +89,7 @@
#endregion #endregion
private Label label1; private Label label1;
private ListBox logList;
private Label label2;
} }
} }

@ -1,7 +1,9 @@
using Microsoft.AspNetCore.Components;
using PrintBarCode.Business; using PrintBarCode.Business;
using PrintBarCode.Helper; using PrintBarCode.Helper;
using PrintBarCode.Model; using PrintBarCode.Model;
using SlnMesnac.Redis; using SlnMesnac.Redis;
using static PrintBarCode.MessageClient;
namespace PrintBarCode namespace PrintBarCode
{ {
@ -11,10 +13,35 @@ namespace PrintBarCode
public MainForm() public MainForm()
{ {
MessageClient.addLogEvent += addLog;
InitializeComponent(); InitializeComponent();
addLog("启动监听打印服务成功......");
}
private void addLog(string logInfo)
{
try
{
// 如果当前调用线程不是创建窗体的线程,使用 Invoke
if (this.logList.InvokeRequired)
{
this.logList.Invoke(new Action<string>(addLog), logInfo);
}
else
{
this.logList.Items.Add($"{DateTime.Now}==>{logInfo}");
}
}
catch (Exception ex)
{
}
} }
} }
} }

@ -3,6 +3,7 @@ using Newtonsoft.Json;
using PrintBarCode.Business; using PrintBarCode.Business;
using PrintBarCode.Helper; using PrintBarCode.Helper;
using PrintBarCode.Model; using PrintBarCode.Model;
using ServiceStack;
using ServiceStack.Messaging; using ServiceStack.Messaging;
using SlnMesnac.Common; using SlnMesnac.Common;
using SlnMesnac.Model.domain; using SlnMesnac.Model.domain;
@ -20,6 +21,19 @@ namespace PrintBarCode
private readonly RedisHandler _redisHandler; private readonly RedisHandler _redisHandler;
private PrintBusiness printBusiness = new PrintBusiness(); private PrintBusiness printBusiness = new PrintBusiness();
private readonly DebugConfig debugConfig = DebugConfig.Instance; private readonly DebugConfig debugConfig = DebugConfig.Instance;
public delegate void addLog(string message);
public static event addLog? addLogEvent;
/// <summary>
/// 刷新日志信息
/// </summary>
/// <param name="msg"></param>
public delegate void PrintMessageToListBox(string msg);
public event PrintMessageToListBox? PrintMessageToListBoxEvent;
public MessageClient(RedisHandler redisHandler) public MessageClient(RedisHandler redisHandler)
{ {
_redisHandler = redisHandler; _redisHandler = redisHandler;
@ -74,8 +88,8 @@ namespace PrintBarCode
try try
{ {
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\":\"product\",\"printContent\":\"[{\\\"saleOrderCode\\\":\\\"\\\",\\\"materialName\\\":\\\"多功能自动剥线钳\\\",\\\"qrcode\\\":\\\"20241019112921CP001\\\",\\\"materialSpec\\\":\\\"\\\",\\\"qty\\\":\\\"1\\\",\\\"materialCode\\\":\\\"MES.MC.A00861\\\",\\\"barcode\\\":\\\"20241019112921CP001\\\",\\\"productPlanCode\\\":\\\"20241019111402JL012\\\"}]\"}";
if (!string.IsNullOrEmpty(jsonString)) if (!string.IsNullOrEmpty(jsonString))
{ {
var result = JsonParser.ParseJson(jsonString); var result = JsonParser.ParseJson(jsonString);
@ -85,14 +99,17 @@ namespace PrintBarCode
{ {
if (item is RawBarCodeInfo rawBarCodeInfo) if (item is RawBarCodeInfo rawBarCodeInfo)
{ {
addLogEvent?.Invoke(rawBarCodeInfo.ToJson());
printBusiness.PrintRawBarCodeInfo(rawBarCodeInfo); printBusiness.PrintRawBarCodeInfo(rawBarCodeInfo);
Console.WriteLine($"SaleOrderCode: {rawBarCodeInfo.SaleOrderCode}, MaterialName: {rawBarCodeInfo.MaterialName}, PoNo: {rawBarCodeInfo.PoNo}, QrCode: {rawBarCodeInfo.QrCode}, BatchCode: {rawBarCodeInfo.BatchCode}, MaterialSpec: {rawBarCodeInfo.MaterialSpec}, MaterialCode: {rawBarCodeInfo.MaterialCode}, Barcode: {rawBarCodeInfo.Barcode}");
} }
else if (item is ProductBarCodeInfo productBarCodeInfo) else if (item is ProductBarCodeInfo productBarCodeInfo)
{ {
addLogEvent?.Invoke(productBarCodeInfo.ToJson());
printBusiness.PrintProductBarCodeInfo(productBarCodeInfo); printBusiness.PrintProductBarCodeInfo(productBarCodeInfo);
}else if (item is BindBarCodeInfo bindBarCodeInfo) }else if (item is BindBarCodeInfo bindBarCodeInfo)
{ {
addLogEvent?.Invoke(bindBarCodeInfo.ToJson());
printBusiness.PrintBindBarCodeInfo(bindBarCodeInfo); printBusiness.PrintBindBarCodeInfo(bindBarCodeInfo);
} }
Thread.Sleep(1000); Thread.Sleep(1000);

Loading…
Cancel
Save