using System; using System.Diagnostics; using System.IO; using System.Threading; using ZJ_BYD.DB; using ZJ_BYD.Model; namespace ZJ_BYD.Untils { public class BartenderPrintHeper : MyEventHandler { /// /// 通过BatTender手动打印条码 /// /// /// /// /// public static (bool ok, string barCode, string msg) PrintByHttp(string fileName, string softwareVersion, string barCode) { var path = "D:\\PrintTemplate\\" + fileName + ".btw"; if (!File.Exists(path)) { return (false, "", $"{DateTime.Now:HH:mm:ss}>>>>>手动打印时模板文件不存在{Environment.NewLine}"); } string version = $"SW:{softwareVersion}/BC34-1200V-C-V0.11"; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); T_PrintInfo t_PrintInfo = new T_PrintInfo { Id = Guid.NewGuid().ToString(), FileName = fileName, BarCode = barCode, SoftVersion = version, CreatedTime = DateTime.Now }; var row = MskCodeHelper.AddPrintInfo(t_PrintInfo); if (row <= 0) { return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>手动打印信息发送失败,保存打印参数耗时:{stopwatch.ElapsedMilliseconds}毫秒{Environment.NewLine}"); } #region 监听打印结果 bool printResult = false; Stopwatch stopwatch1 = new Stopwatch(); stopwatch1.Start(); bool doWhile = true; while (doWhile) { doWhile = false; if (stopwatch1.ElapsedMilliseconds >= 10000) { break;//超时跳出循环 } var printInfo = MskCodeHelper.QueryPrintInfo(barCode); if (printInfo == null) { break;//查询打印参数为空跳出循环 } else if (printInfo.PrintResult.HasValue && printInfo.PrintResult.Value) { printResult = true; break;//打印成功跳出循环 } else if (printInfo.PrintResult.HasValue && !printInfo.PrintResult.Value) { break;//打印失败跳出循环 } doWhile = true; Thread.Sleep(300); } #endregion stopwatch.Stop(); if (printResult) { return (true, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>一体机反馈:打印成功,打印条码信息:{barCode},软件编码:{CAN1DeviceHelper.Instance.DeviceInfo.SoftwareCode},引导版本号:{CAN1DeviceHelper.Instance.DeviceInfo.GuideVersion},软件版本号:{CAN1DeviceHelper.Instance.DeviceInfo.SoftwareVersion},电压:{CAN1DeviceHelper.Instance.DeviceInfo.Voltage},耗时:{stopwatch.ElapsedMilliseconds}毫秒{Environment.NewLine}"); } else { return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>一体机反馈:打印失败,耗时:{stopwatch.ElapsedMilliseconds}毫秒{Environment.NewLine}"); } } } }