修改为bar模板打印
This commit is contained in:
@@ -32,6 +32,9 @@ using QuestPDF;
|
||||
using QuestPDF.Fluent;
|
||||
using QuestPDF.Helpers;
|
||||
using QuestPDF.Infrastructure;
|
||||
using BarTender;
|
||||
using MathNet.Numerics.RootFinding;
|
||||
using Infrastructure;
|
||||
|
||||
|
||||
namespace DOAN.Service.MES.product
|
||||
@@ -1303,12 +1306,12 @@ namespace DOAN.Service.MES.product
|
||||
|
||||
/// <summary>
|
||||
/// https://www.questpdf.com/
|
||||
/// </summary>
|
||||
/// </summary>要打印的工单号
|
||||
/// <param name="workorderArray"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(string, Stream)> ExportPDFByQuestPDFDemo(string[] workorderArray)
|
||||
{
|
||||
|
||||
|
||||
var dataList = Context.Queryable<ProWorkorder>().Where(it => workorderArray.Contains(it.Workorder))
|
||||
.ToList();
|
||||
if (dataList.Count() == 0)
|
||||
@@ -1381,10 +1384,56 @@ namespace DOAN.Service.MES.product
|
||||
return new(fileName, ms);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据模板打印工单信息
|
||||
/// </summary>
|
||||
/// <param name="workorderArray"></param>
|
||||
/// <param name="path">模板路径</param>
|
||||
/// <returns></returns>
|
||||
public async Task<CustomException> PrintTicketsByTemplate(string[] workorderArray,string path)
|
||||
{
|
||||
var dataList = await Context.Queryable<ProWorkorder>().Where(p => workorderArray.Contains(p.Workorder)).ToListAsync();
|
||||
if (!dataList.Any())
|
||||
{
|
||||
return new CustomException(204, "未找到匹配的工单数据");
|
||||
|
||||
}
|
||||
Application bartenderApp = null;
|
||||
Format bartenderFormat = null;
|
||||
try
|
||||
{
|
||||
bartenderApp = new Application { Visible = false };
|
||||
bartenderFormat = bartenderApp.Formats.Open(path);
|
||||
// 4. 遍历数据并打印
|
||||
foreach (var data in dataList)
|
||||
{
|
||||
bartenderFormat.SetNamedSubStringValue("Workorder", data.Workorder);
|
||||
bartenderFormat.SetNamedSubStringValue("StoveCode", data.StoveCode);
|
||||
bartenderFormat.SetNamedSubStringValue("PlanNum", 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(200, $"打印标签失败: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 6. 确保资源释放(逆序关闭)
|
||||
if (bartenderFormat != null)
|
||||
{
|
||||
bartenderFormat.Close(BtSaveOptions.btDoNotSaveChanges);
|
||||
}
|
||||
if (bartenderApp != null)
|
||||
{
|
||||
bartenderApp.Quit(BtSaveOptions.btDoNotSaveChanges);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user