diff --git a/DOAN.Service/DOAN.Service.csproj b/DOAN.Service/DOAN.Service.csproj index 4225b3b..b29b6fc 100644 --- a/DOAN.Service/DOAN.Service.csproj +++ b/DOAN.Service/DOAN.Service.csproj @@ -8,6 +8,17 @@ 1591 + + + tlbimp + 1 + 10 + d58562c1-e51b-11cf-8941-00a024a9083f + 0 + false + true + + diff --git a/DOAN.Service/MES/Product/ProWorkorderService.cs b/DOAN.Service/MES/Product/ProWorkorderService.cs index 34fcf9c..383950d 100644 --- a/DOAN.Service/MES/Product/ProWorkorderService.cs +++ b/DOAN.Service/MES/Product/ProWorkorderService.cs @@ -2,7 +2,7 @@ using System; using System.Data.Common; using System.Globalization; using System.Linq; -//using BarTender; +using BarTender; using DOAN.Infrastructure.Helper; using DOAN.Model; using DOAN.Model.MES.base_; @@ -1505,51 +1505,50 @@ namespace DOAN.Service.MES.product ProWorkorderExportDto param ) { - return null; - //var dataList = await Context - // .Queryable() - // .Where(p => param.WorkorderArray.Contains(p.Workorder)) - // .ToListAsync(); - //if (dataList.Count == 0) - //{ - // return new CustomException(500, "未找到匹配的工单数据"); - //} - //Application bartenderApp = null; - //Format bartenderFormat = null; - //try - //{ - // bartenderApp = new Application { Visible = false }; - // bartenderFormat = bartenderApp.Formats.Open(param.Path); - // // 4. 遍历数据并打印 - // foreach (var data in dataList) - // { - // bartenderFormat.SetNamedSubStringValue("workorder", data.Workorder); - // bartenderFormat.SetNamedSubStringValue("stoveCode", data.StoveCode); - // bartenderFormat.SetNamedSubStringValue("qty", data.PlanNum.ToString()); - // await Task.Delay(500); - // bartenderFormat.PrintOut(false, false); // 静默打印 - // } + var dataList = await Context + .Queryable() + .Where(p => param.WorkorderArray.Contains(p.Workorder)) + .ToListAsync(); + if (dataList.Count == 0) + { + return new CustomException(500, "未找到匹配的工单数据"); + } + Application bartenderApp = null; + Format bartenderFormat = null; + try + { + bartenderApp = new Application { Visible = false }; + bartenderFormat = bartenderApp.Formats.Open(param.Path); + // 4. 遍历数据并打印 + foreach (var data in dataList) + { + bartenderFormat.SetNamedSubStringValue("workorder", data.Workorder); + bartenderFormat.SetNamedSubStringValue("stoveCode", data.StoveCode); + bartenderFormat.SetNamedSubStringValue("qty", data.PlanNum.ToString()); + await Task.Delay(500); + bartenderFormat.PrintOut(false, false); // 静默打印 + } - // return new CustomException(200, "标签打印成功"); - //} - //catch (Exception ex) - //{ - // // 5. 错误处理(记录日志) - // Console.WriteLine($"打印标签时出错: {ex.Message}"); - // return new CustomException(500, $"打印标签失败: {ex.Message}"); - //} - //finally - //{ - // // 6. 确保资源释放(逆序关闭) - // if (bartenderFormat != null) - // { - // bartenderFormat.Close(BtSaveOptions.btDoNotSaveChanges); - // } - // if (bartenderApp != null) - // { - // bartenderApp.Quit(BtSaveOptions.btDoNotSaveChanges); - // } - //} + return new CustomException(200, "标签打印成功"); + } + catch (Exception ex) + { + // 5. 错误处理(记录日志) + Console.WriteLine($"打印标签时出错: {ex.Message}"); + return new CustomException(500, $"打印标签失败: {ex.Message}"); + } + finally + { + // 6. 确保资源释放(逆序关闭) + if (bartenderFormat != null) + { + bartenderFormat.Close(BtSaveOptions.btDoNotSaveChanges); + } + if (bartenderApp != null) + { + bartenderApp.Quit(BtSaveOptions.btDoNotSaveChanges); + } + } } } }