using PrintBarCode.Helper; using PrintBarCode.Model; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PrintBarCode.Business { public class PrintBusiness { private DebugConfig debugConfig = DebugConfig.Instance; private static string basePath = AppDomain.CurrentDomain.BaseDirectory; PrintHelper PrintH = new PrintHelper(); private RawPrinterHelper zplp = new RawPrinterHelper(); public PrintBusiness() { } /// /// 打印原材料条码方法 /// public void PrintRawBarCodeInfo(RawBarCodeInfo rawBarCodeInfo) { // 拼接成目标文件的完整路径 string path = Path.Combine(basePath, "templates", "rawTemplate.prn"); // string[] args = new string[] { rawBarCodeInfo.MaterialName, rawBarCodeInfo.MaterialCode, rawBarCodeInfo.MaterialSpec, rawBarCodeInfo.BatchCode, rawBarCodeInfo.PoNo, rawBarCodeInfo.SaleOrderCode, rawBarCodeInfo.Barcode, rawBarCodeInfo.QrCode, }; // 将属性值用 "~" 连接起来,不带前缀 string TempStr = $"{rawBarCodeInfo.MaterialName}~{rawBarCodeInfo.MaterialCode}~{rawBarCodeInfo.MaterialSpec}~{rawBarCodeInfo.BatchCode}~{rawBarCodeInfo.PoNo}~{rawBarCodeInfo.SaleOrderCode}~{rawBarCodeInfo.Barcode}~{rawBarCodeInfo.QrCode}"; string ZplStr = PrintH.GetPrintString(path, TempStr);//替换后字符串 bool pringFlag = zplp.SendStringToPrinter(debugConfig.PrintName, ZplStr); if (pringFlag == false) { Console.WriteLine("打印错误,检查后请重新操作!"); } } /// /// 打印成品条码方法 /// public void PrintProductBarCodeInfo(ProductBarCodeInfo productBarCodeInfo) { // 拼接成目标文件的完整路径 string path = Path.Combine(basePath, "templates", "productTemplate.prn"); // string[] args = new string[] { productBarCodeInfo.MaterialName, productBarCodeInfo.MaterialCode, productBarCodeInfo.MaterialSpec, productBarCodeInfo.ProductPlanCode, productBarCodeInfo.SaleOrderCode, productBarCodeInfo.BarCode, productBarCodeInfo.Qty, productBarCodeInfo.QrCode, }; string TempStr = $"{productBarCodeInfo.MaterialName}~{productBarCodeInfo.MaterialCode}~{productBarCodeInfo.MaterialSpec}~{productBarCodeInfo.ProductPlanCode}~{productBarCodeInfo.SaleOrderCode}~{productBarCodeInfo.BarCode}~{productBarCodeInfo.Qty}~{productBarCodeInfo.QrCode}"; string ZplStr = PrintH.GetPrintString(path, TempStr);//替换后字符串 bool pringFlag = zplp.SendStringToPrinter(debugConfig.PrintName, ZplStr); if (pringFlag == false) { Console.WriteLine("打印错误,检查后请重新操作!"); } } /// /// 打印配对码方法 /// public void PrintBindBarCodeInfo(BindBarCodeInfo bindBarCodeInfo) { // 拼接成目标文件的完整路径 string path = Path.Combine(basePath, "templates", "bindTemplate.prn"); // string[] args = new string[] { bindBarCodeInfo.MaterialName, bindBarCodeInfo.MaterialCode, bindBarCodeInfo.MaterialSpec, bindBarCodeInfo.BatchCode, bindBarCodeInfo.PoNo, bindBarCodeInfo.SaleOrderCode, bindBarCodeInfo.Barcode, bindBarCodeInfo.QrCode, }; // 将属性值用 "~" 连接起来,不带前缀 string TempStr = $"{bindBarCodeInfo.MaterialName}~{bindBarCodeInfo.MaterialCode}~{bindBarCodeInfo.MaterialSpec}~{bindBarCodeInfo.BatchCode}~{bindBarCodeInfo.PoNo}~{bindBarCodeInfo.SaleOrderCode}~{bindBarCodeInfo.Barcode}~{bindBarCodeInfo.QrCode}"; string ZplStr = PrintH.GetPrintString(path, TempStr);//替换后字符串 bool pringFlag = zplp.SendStringToPrinter(debugConfig.PrintName, ZplStr); if (pringFlag == false) { Console.WriteLine("打印错误,检查后请重新操作!"); } } /// /// 打印小条码库位码方法 /// public void PrintSmallBarCodeInfo(SmallCodeInfo smallCodeInfo) { try { // 拼接成目标文件的完整路径 string path = Path.Combine(basePath, "templates", "smallTemplate.prn"); string[] args = new string[] { smallCodeInfo.QrCode, 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("打印错误,检查后请重新操作!"); } } /// /// 打印空白页 /// 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); } } }