From 01a277a68e4e31a518c8d5a6f72f2f62fb05a09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AD=A3=E6=98=93?= Date: Wed, 19 Nov 2025 20:51:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=89=93=E5=8D=B0):=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E6=88=90=E5=93=81=E5=85=A5=E5=BA=93=E5=8D=95=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在PrintControlViewModel中集成FinishedProductService进行实际打印 - 完善FinishedProductService的打印逻辑,包括打印参数构建和状态更新 - 更新appsettings.json中的标签路径配置 - 调整MainControl.xaml中DataGrid的最大高度 - 清理和优化相关代码的using引用 --- .../Services/FinishedProductService.cs | 104 +++++++++++++----- .../ViewModels/PrintControlViewModel.cs | 33 ++++-- .../Views/MainControl.xaml | 2 +- .../RIZO_Application/appsettings.json | 4 +- 4 files changed, 104 insertions(+), 39 deletions(-) diff --git a/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/Services/FinishedProductService.cs b/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/Services/FinishedProductService.cs index e61fcf8..a7dbf31 100644 --- a/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/Services/FinishedProductService.cs +++ b/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/Services/FinishedProductService.cs @@ -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 _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().Publish($"添加成品入库单失败: {ex.Message}"); return false; } @@ -358,6 +360,7 @@ namespace RIZO_Application.Modules.ModuleName.Services } catch (Exception ex) { + //MessageBox.Show($"更新成品入库单失败: {ex.Message}"); _eventAggregator.GetEvent().Publish($"更新成品入库单失败: {ex.Message}"); return false; } @@ -397,6 +400,7 @@ namespace RIZO_Application.Modules.ModuleName.Services } catch (Exception ex) { + //MessageBox.Show($"删除成品入库单失败: {ex.Message}"); _eventAggregator.GetEvent().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() - .Publish($"模拟打印成品入库单成功: {receiptNo}"); - return await Task.FromResult(true); + return await Task.FromResult(false); } - return await Task.FromResult(false); } else { - int result = Context - .Updateable() - .SetColumns(it => new ProFinishedProductReceipt { LabelPrintStatus = "已打印" }) + product = await Context.Queryable() .Where(it => it.ReceiptNo == receiptNo) - .ExecuteCommand(); - if (result > 0) + .FirstAsync(); + if (product == null) { - _eventAggregator - .GetEvent() - .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() + .SetColumns(it => new ProFinishedProductReceipt { LabelPrintStatus = "已打印" }) + .Where(it => it.ReceiptNo == receiptNo) + .ExecuteCommand(); + if (result <= 0) + { + _eventAggregator.GetEvent().Publish($"更新打印状态失败: {receiptNo}"); + } + } + + _eventAggregator + .GetEvent() + .Publish($"打印成品入库单成功: {receiptNo}"); + return true; + } + else + { + _eventAggregator + .GetEvent() + .Publish($"打印成品入库单失败: {receiptNo}"); + return false; } } catch (Exception ex) { + MessageBox.Show($"打印成品入库单失败: {ex.Message}"); _eventAggregator.GetEvent().Publish($"打印成品入库单失败: {ex.Message}"); return false; } diff --git a/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/ViewModels/PrintControlViewModel.cs b/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/ViewModels/PrintControlViewModel.cs index 6ca6210..8102d2b 100644 --- a/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/ViewModels/PrintControlViewModel.cs +++ b/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/ViewModels/PrintControlViewModel.cs @@ -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(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().Publish($"打印成功: {receiptNo}"); + } + else + { + MessageBox.Show($"打印失败!"); + _eventAggregator.GetEvent().Publish($"打印失败: {receiptNo}"); + } } catch (Exception ex) { diff --git a/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/Views/MainControl.xaml b/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/Views/MainControl.xaml index 9541724..4fe92e2 100644 --- a/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/Views/MainControl.xaml +++ b/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/Views/MainControl.xaml @@ -64,7 +64,7 @@ HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="400" - MaxHeight="500"> + MaxHeight="400"> diff --git a/RIZO_Application/RIZO_Application/appsettings.json b/RIZO_Application/RIZO_Application/appsettings.json index 669668c..b172850 100644 --- a/RIZO_Application/RIZO_Application/appsettings.json +++ b/RIZO_Application/RIZO_Application/appsettings.json @@ -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" } } \ No newline at end of file