using BarTender; using Microsoft.Extensions.Logging; using Syc.Basic.Web.WMS.Dto; using Syc.Basic.Web.WMS.Entitys; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Syc.Basic.Web.WMS { public class BarTenderHelper { /// /// 打印标签 /// /// 模板全路径,如:D://AD盘/新建文件夹/xxxx.btw /// 打印机名称 /// 模板变量参数 /// public static void Print(string templatePath,string deviceName,Dictionary @params = null) { Console.WriteLine("开始打印"); Application bartenderApp = new Application(); var btFormat = bartenderApp.Formats.Open(templatePath,false,deviceName); if (@params is not null && @params.Any()) { foreach (var param in @params) btFormat.SetNamedSubStringValue(param.Key, param.Value); } btFormat.IdenticalCopiesOfLabel = 1; //设置打印份数,自动贴标就只出一张 BarTender.Messages btMsgs; //开始打印 var btPrintRtn = btFormat.Print(PrintJobName:"打印标签",WaitForSpoolJobToComplete:false,Messages:out btMsgs); if (btPrintRtn != BarTender.BtPrintResult.btSuccess) foreach (BarTender.Message msg in btMsgs) { var text = msg.Message; } //输出错误日志 if (btPrintRtn != BarTender.BtPrintResult.btSuccess) { foreach(BarTender.Message msg in btMsgs) { var text = msg.Message; } } //关闭模板 btFormat.Close(BarTender.BtSaveOptions.btPromptSave); //退出打印程序 bartenderApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); } /// /// 打印箱子标签 /// /// public static void BoxPrint(Box box) { Dictionary list = new Dictionary() { {"$TYPE", box.Type }, {"$SPEC", box.Spec }, {"$QTY", box.Qty.ToString()}, {"$CTN", Math.Round(box.Net_Weight.Value,2).ToString()}, { "$LOTNO", box.Lot_No }, {"$LENGTH", box.Length }, { "$DATE", box.Dom_Time.ToString()}, { "$EXP", box.Exp_Time.ToString()}, { "$CODE", box.Code } }; Print(@"D:\btw\装箱码垛标签.btw", "NOVEXX Solutions XLP 504 (300 dpi)Max", list); } /// /// 打印丝锭标签 /// /// public static void SilkPrint(Silk silk) { Dictionary list = new Dictionary() { {"$Name", silk.Name }, {"$Type", silk.Type }, {"$NetWeight", Math.Round(silk.Net_Weight.Value,2).ToString() }, { "$Length", silk.Length}, {"$Date", silk.Date.ToString() }, { "$LotNo", silk.Lot_No}, { "$Code", silk.Code} }; Print(@"D:\btw\丝锭标签.btw", "NOVEXX Solutions XLP 504 (300 dpi)Min", list); } } }