feat(打印): 实现成品入库单打印功能并优化打印流程
- 在PrintControlViewModel中集成FinishedProductService进行实际打印 - 完善FinishedProductService的打印逻辑,包括打印参数构建和状态更新 - 更新appsettings.json中的标签路径配置 - 调整MainControl.xaml中DataGrid的最大高度 - 清理和优化相关代码的using引用
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Prism.Events;
|
||||
using RIZO_Application.Core;
|
||||
using RIZO_Application.Models;
|
||||
using RIZO_Application.Infrastructure.CustomAttribute;
|
||||
using RIZO_Application.Infrastructure.Model;
|
||||
using RIZO_Application.Models.Model;
|
||||
using RIZO_Application.Modules.ModuleName.Services.IServices;
|
||||
using RIZO_Application.Repository;
|
||||
using SqlSugar;
|
||||
using SqlSugar.IOC;
|
||||
using RIZO_Application.Infrastructure.CustomAttribute;
|
||||
using RIZO_Application.Infrastructure.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace RIZO_Application.Modules.ModuleName.Services
|
||||
{
|
||||
@@ -21,13 +19,16 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
{
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly SqlSugarClient _db;
|
||||
private readonly IPrintService _printService;
|
||||
private readonly string _labelPath = PrintConfigs.Current.BaseLabelPath;
|
||||
private readonly bool _useMockData = false;
|
||||
private readonly string _labelFrom; // 改为在构造函数中初始化
|
||||
private readonly List<ProFinishedProductReceipt> _mockData;
|
||||
|
||||
public FinishedProductService(IEventAggregator eventAggregator)
|
||||
public FinishedProductService(IEventAggregator eventAggregator, IPrintService printService)
|
||||
{
|
||||
_eventAggregator = eventAggregator;
|
||||
_printService = printService;
|
||||
_mockData = GenerateMockData();
|
||||
// 安全地获取标签来源配置
|
||||
_labelFrom = PrintConfigs.Current?.LabelFrom ?? "全部";
|
||||
@@ -303,6 +304,7 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//MessageBox.Show($"添加成品入库单失败: {ex.Message}");
|
||||
_eventAggregator.GetEvent<SystemLogEvent>().Publish($"添加成品入库单失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
@@ -358,6 +360,7 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//MessageBox.Show($"更新成品入库单失败: {ex.Message}");
|
||||
_eventAggregator.GetEvent<SystemLogEvent>().Publish($"更新成品入库单失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
@@ -397,6 +400,7 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//MessageBox.Show($"删除成品入库单失败: {ex.Message}");
|
||||
_eventAggregator.GetEvent<SystemLogEvent>().Publish($"删除成品入库单失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
@@ -406,37 +410,83 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
ProFinishedProductReceipt product = null;
|
||||
if (_useMockData)
|
||||
{
|
||||
var product = _mockData.Find(p => p.ReceiptNo == receiptNo);
|
||||
if (product != null)
|
||||
product = _mockData.Find(p => p.ReceiptNo == receiptNo);
|
||||
if (product == null)
|
||||
{
|
||||
product.LabelPrintStatus = "已打印";
|
||||
_eventAggregator
|
||||
.GetEvent<SystemLogEvent>()
|
||||
.Publish($"模拟打印成品入库单成功: {receiptNo}");
|
||||
return await Task.FromResult(true);
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
int result = Context
|
||||
.Updateable<ProFinishedProductReceipt>()
|
||||
.SetColumns(it => new ProFinishedProductReceipt { LabelPrintStatus = "已打印" })
|
||||
product = await Context.Queryable<ProFinishedProductReceipt>()
|
||||
.Where(it => it.ReceiptNo == receiptNo)
|
||||
.ExecuteCommand();
|
||||
if (result > 0)
|
||||
.FirstAsync();
|
||||
if (product == null)
|
||||
{
|
||||
_eventAggregator
|
||||
.GetEvent<SystemLogEvent>()
|
||||
.Publish($"打印成品入库单成功: {receiptNo}");
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
// 构建打印参数
|
||||
var printDto = new PrintDto
|
||||
{
|
||||
Path = _labelPath,
|
||||
SiteNo = product.SiteNo ?? string.Empty,
|
||||
Name = "成品入库单打印",
|
||||
LabelFrom = product.LabelFrom ?? "未知",
|
||||
PartNumber = product.PartNumber ?? string.Empty,
|
||||
Description = product.Description ?? string.Empty,
|
||||
WorkOrder = product.WorkOrder ?? string.Empty,
|
||||
ProductionTime = product.BatchCode ?? string.Empty,
|
||||
BatchCode = product.BatchCode ?? string.Empty,
|
||||
PackageCout = product.PackageCount ?? 1,
|
||||
PackageNum = product.PackageNum ?? 1,
|
||||
LabelCode = product.LabelCode ?? string.Empty,
|
||||
Team = product.Team ?? string.Empty,
|
||||
};
|
||||
|
||||
// 调用打印服务
|
||||
bool printSuccess = await _printService.PrintLabelAsync(printDto);
|
||||
|
||||
if (printSuccess)
|
||||
{
|
||||
// 更新打印状态
|
||||
if (_useMockData)
|
||||
{
|
||||
product.LabelPrintStatus = "已打印";
|
||||
}
|
||||
else
|
||||
{
|
||||
int result = Context
|
||||
.Updateable<ProFinishedProductReceipt>()
|
||||
.SetColumns(it => new ProFinishedProductReceipt { LabelPrintStatus = "已打印" })
|
||||
.Where(it => it.ReceiptNo == receiptNo)
|
||||
.ExecuteCommand();
|
||||
if (result <= 0)
|
||||
{
|
||||
_eventAggregator.GetEvent<SystemLogEvent>().Publish($"更新打印状态失败: {receiptNo}");
|
||||
}
|
||||
}
|
||||
|
||||
_eventAggregator
|
||||
.GetEvent<SystemLogEvent>()
|
||||
.Publish($"打印成品入库单成功: {receiptNo}");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_eventAggregator
|
||||
.GetEvent<SystemLogEvent>()
|
||||
.Publish($"打印成品入库单失败: {receiptNo}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"打印成品入库单失败: {ex.Message}");
|
||||
_eventAggregator.GetEvent<SystemLogEvent>().Publish($"打印成品入库单失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
using linesider_screen_tool;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using Microsoft.Win32;
|
||||
using Prism.Commands;
|
||||
using Prism.Events;
|
||||
using Prism.Regions;
|
||||
using RIZO_Application.Core;
|
||||
using RIZO_Application.Core.Mvvm;
|
||||
using RIZO_Application.Infrastructure.Model;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using RIZO_Application.Modules.ModuleName.Services.IServices;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using Prism.Commands;
|
||||
|
||||
namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
{
|
||||
@@ -23,16 +19,19 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IPrintService _printService;
|
||||
private readonly IFinishedProductService _finishedProductService;
|
||||
private SubscriptionToken _printEventToken;
|
||||
private bool _isDisposed;
|
||||
public PrintControlViewModel(
|
||||
IRegionManager regionManager,
|
||||
IEventAggregator eventAggregator,
|
||||
IPrintService printService)
|
||||
IPrintService printService,
|
||||
IFinishedProductService finishedProductService)
|
||||
: base(regionManager)
|
||||
{
|
||||
_eventAggregator = eventAggregator;
|
||||
_printService = printService;
|
||||
_finishedProductService = finishedProductService;
|
||||
PrintTestButtonCommand = new DelegateCommand<string>(ExecutePrintTestButtonCommand);
|
||||
BrowseFileCommand = new DelegateCommand(ExecuteBrowseFileCommand);
|
||||
if (!AppSettings.Current.PrintInit)
|
||||
@@ -153,11 +152,27 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecutePrintTestButtonCommand(string parameter)
|
||||
private async void ExecutePrintTestButtonCommand(string parameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
PublishPrintMqttMessage(parameter);
|
||||
|
||||
// 调用打印服务进行实际打印
|
||||
// 这里使用固定的receiptNo作为测试,实际应用中应该从UI或其他地方获取
|
||||
string receiptNo = "TEST-001";
|
||||
bool printResult = await _finishedProductService.PrintFinishedProductAsync(receiptNo);
|
||||
|
||||
if (printResult)
|
||||
{
|
||||
MessageBox.Show($"打印成功!");
|
||||
_eventAggregator.GetEvent<SystemLogEvent>().Publish($"打印成功: {receiptNo}");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show($"打印失败!");
|
||||
_eventAggregator.GetEvent<SystemLogEvent>().Publish($"打印失败: {receiptNo}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
MinHeight="400"
|
||||
MaxHeight="500">
|
||||
MaxHeight="400">
|
||||
<DataGrid.Columns>
|
||||
<!-- 工单信息列 -->
|
||||
<DataGridTextColumn Header="入库单号" Binding="{Binding ReceiptNo}" Width="160" />
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
"ServerPath": "http://192.168.60.251:8888"
|
||||
},
|
||||
"PrintConfigs": {
|
||||
"BaseLabelPath": "G:\\项目--2024\\干巷车镜git仓库\\涂装车间-GP12与后道-成品入库单打印\\Label\\成品入库单.btw",
|
||||
"LabelFrom":"GP12"
|
||||
"BaseLabelPath": "G:\\项目--2024\\干巷车镜git仓库\\涂装车间-GP12与后道-成品入库单打印\\shgx_tz_finished_product_print_wpf\\Label\\成品入库单.btw",
|
||||
"LabelFrom": "GP12"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user