diff --git a/PrintBarCode/MainForm.Designer.cs b/PrintBarCode/MainForm.Designer.cs index 850ecc5..7ca658a 100644 --- a/PrintBarCode/MainForm.Designer.cs +++ b/PrintBarCode/MainForm.Designer.cs @@ -29,24 +29,56 @@ private void InitializeComponent() { label1 = new Label(); + logList = new ListBox(); + label2 = new Label(); SuspendLayout(); // // label1 // label1.AutoSize = true; - label1.Font = new Font("Microsoft YaHei UI", 21.75F, FontStyle.Bold, GraphicsUnit.Point); - label1.Location = new Point(76, 115); + label1.Font = new Font("Microsoft YaHei UI", 26.25F, FontStyle.Bold, GraphicsUnit.Point); + label1.ForeColor = SystemColors.MenuHighlight; + label1.Location = new Point(664, 19); label1.Name = "label1"; - label1.Size = new Size(307, 39); + label1.Size = new Size(230, 46); 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 // AutoScaleDimensions = new SizeF(7F, 17F); 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); + FormBorderStyle = FormBorderStyle.FixedDialog; Name = "MainForm"; StartPosition = FormStartPosition.CenterScreen; Text = "打印条码服务"; @@ -57,5 +89,7 @@ #endregion private Label label1; + private ListBox logList; + private Label label2; } } \ No newline at end of file diff --git a/PrintBarCode/MainForm.cs b/PrintBarCode/MainForm.cs index 61e9a72..3513f28 100644 --- a/PrintBarCode/MainForm.cs +++ b/PrintBarCode/MainForm.cs @@ -1,20 +1,47 @@ +using Microsoft.AspNetCore.Components; using PrintBarCode.Business; using PrintBarCode.Helper; using PrintBarCode.Model; using SlnMesnac.Redis; +using static PrintBarCode.MessageClient; namespace PrintBarCode { public partial class MainForm : Form { - + public MainForm() { - + MessageClient.addLogEvent += addLog; InitializeComponent(); + addLog("ӡɹ......"); + + + } + + + private void addLog(string logInfo) + { + try + { + + // ǰ̲߳Ǵ̣߳ʹ Invoke + if (this.logList.InvokeRequired) + { + this.logList.Invoke(new Action(addLog), logInfo); + } + else + { + this.logList.Items.Add($"{DateTime.Now}==>{logInfo}"); + } + + } + catch (Exception ex) + { + } } } } \ No newline at end of file diff --git a/PrintBarCode/MessageClient.cs b/PrintBarCode/MessageClient.cs index 739fdf0..64f4df7 100644 --- a/PrintBarCode/MessageClient.cs +++ b/PrintBarCode/MessageClient.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using PrintBarCode.Business; using PrintBarCode.Helper; using PrintBarCode.Model; +using ServiceStack; using ServiceStack.Messaging; using SlnMesnac.Common; using SlnMesnac.Model.domain; @@ -20,6 +21,19 @@ namespace PrintBarCode private readonly RedisHandler _redisHandler; private PrintBusiness printBusiness = new PrintBusiness(); private readonly DebugConfig debugConfig = DebugConfig.Instance; + + public delegate void addLog(string message); + public static event addLog? addLogEvent; + + /// + /// 刷新日志信息 + /// + /// + public delegate void PrintMessageToListBox(string msg); + public event PrintMessageToListBox? PrintMessageToListBoxEvent; + + + public MessageClient(RedisHandler redisHandler) { _redisHandler = redisHandler; @@ -74,8 +88,8 @@ namespace PrintBarCode try { 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 = _redisHandler.ConsumeMessageFromWorker(channelWork); + string jsonString = "{\"template\":\"product\",\"printContent\":\"[{\\\"saleOrderCode\\\":\\\"\\\",\\\"materialName\\\":\\\"多功能自动剥线钳\\\",\\\"qrcode\\\":\\\"20241019112921CP001\\\",\\\"materialSpec\\\":\\\"\\\",\\\"qty\\\":\\\"1\\\",\\\"materialCode\\\":\\\"MES.MC.A00861\\\",\\\"barcode\\\":\\\"20241019112921CP001\\\",\\\"productPlanCode\\\":\\\"20241019111402JL012\\\"}]\"}"; if (!string.IsNullOrEmpty(jsonString)) { var result = JsonParser.ParseJson(jsonString); @@ -85,14 +99,17 @@ namespace PrintBarCode { if (item is RawBarCodeInfo rawBarCodeInfo) { + addLogEvent?.Invoke(rawBarCodeInfo.ToJson()); 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) { + addLogEvent?.Invoke(productBarCodeInfo.ToJson()); printBusiness.PrintProductBarCodeInfo(productBarCodeInfo); }else if (item is BindBarCodeInfo bindBarCodeInfo) { + addLogEvent?.Invoke(bindBarCodeInfo.ToJson()); printBusiness.PrintBindBarCodeInfo(bindBarCodeInfo); } Thread.Sleep(1000);