From 1cbd295691b15dfe481434985bcb88da9d0b1494 Mon Sep 17 00:00:00 2001 From: zhangzhuo <512464164@qq.com> Date: Mon, 14 Apr 2025 13:23:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Code=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/PalletManagerViewModel.cs | 9 ++++++--- .../ViewModels/VarietyManagerViewModel.cs | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Seyounth.Hyosung.Ava/ViewModels/PalletManagerViewModel.cs b/Seyounth.Hyosung.Ava/ViewModels/PalletManagerViewModel.cs index dff9674..c6b84b2 100644 --- a/Seyounth.Hyosung.Ava/ViewModels/PalletManagerViewModel.cs +++ b/Seyounth.Hyosung.Ava/ViewModels/PalletManagerViewModel.cs @@ -1,12 +1,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Threading.Tasks; using Avalonia.Controls.Notifications; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Services; +using Seyounth.Hyosung.Data.Services.Hyosung; using SukiUI.Toasts; namespace Seyounth.Hyosung.Ava.ViewModels; @@ -22,6 +24,7 @@ public partial class PalletManagerViewModel : ObservableObject private readonly IPalletService _palletService; + public PalletManagerViewModel(IPalletService palletService, ISukiToastManager toastManager) { _toastManager = toastManager; @@ -65,13 +68,13 @@ public partial class PalletManagerViewModel : ObservableObject } [RelayCommand] - private void OnSavePallet(object obj) + private async Task OnSavePallet(object obj) { if (obj is Pallet pallet) { if (pallet.Id == 0) { - var id = _palletService.AddPalletAsync(pallet).Result; + await _palletService.AddPalletAsync(pallet); _toastManager.CreateToast() .WithTitle("新增辅料成功") .Dismiss().After(TimeSpan.FromSeconds(3)) @@ -81,7 +84,7 @@ public partial class PalletManagerViewModel : ObservableObject } else { - _palletService.UpdatePalletAsync(pallet); + await _palletService.UpdatePalletAsync(pallet); _toastManager.CreateToast() .WithTitle("修改辅料成功") .Dismiss().After(TimeSpan.FromSeconds(3)) diff --git a/Seyounth.Hyosung.Ava/ViewModels/VarietyManagerViewModel.cs b/Seyounth.Hyosung.Ava/ViewModels/VarietyManagerViewModel.cs index 6788f70..48122d5 100644 --- a/Seyounth.Hyosung.Ava/ViewModels/VarietyManagerViewModel.cs +++ b/Seyounth.Hyosung.Ava/ViewModels/VarietyManagerViewModel.cs @@ -8,6 +8,7 @@ using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Services; +using Seyounth.Hyosung.Data.Services.Hyosung; using SukiUI.Toasts; namespace Seyounth.Hyosung.Ava.ViewModels; @@ -27,7 +28,7 @@ public partial class VarietyManagerViewModel : ObservableObject private readonly ISukiToastManager _toastManager; private readonly IVarietyService _varietyService; private readonly IPalletService _palletService; - + private readonly IHyosungWmsService _wmsService; public void Reload() { Pallets = new ObservableCollection(_palletService.GetPallets()); @@ -55,8 +56,9 @@ public partial class VarietyManagerViewModel : ObservableObject } public VarietyManagerViewModel(IVarietyService varietyService, ISukiToastManager toastManager, - IPalletService palletService) + IPalletService palletService,IHyosungWmsService wmsService) { + _wmsService = wmsService; _toastManager = toastManager; _palletService = palletService; _varietyService = varietyService; @@ -139,8 +141,20 @@ public partial class VarietyManagerViewModel : ObservableObject [RelayCommand] private async Task OnSavePallet(object obj) { + if (obj is Variety variety) { + var mod = await _wmsService.GetItemInfoByItemCode(variety.Code); + if(mod is null) + { + _toastManager.CreateToast() + .WithTitle("请检查产品代码是否错误") + .Dismiss().After(TimeSpan.FromSeconds(3)) + .OfType(NotificationType.Error) + .Dismiss().ByClicking() + .Queue(); + return; + } await _varietyService.AddVarietyAsync(variety); _toastManager.CreateToast() .WithTitle("保存成功")