Bartender调整

This commit is contained in:
2025-12-29 08:25:14 +08:00
parent 1bbe7c3549
commit aa217ab03e
2 changed files with 55 additions and 45 deletions

View File

@@ -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<ProWorkorder>()
// .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<ProWorkorder>()
.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);
}
}
}
}
}