From 11956c26f35a06ace96bec211de25afcb1bf31b1 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Wed, 3 Sep 2025 15:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=BC=96=E8=BE=91=E8=AE=BE?= =?UTF-8?q?=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DMS.WPF/Services/DataServices.cs | 24 ++++++++++++++++++++++++ DMS.WPF/ViewModels/DevicesViewModel.cs | 11 ++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/DMS.WPF/Services/DataServices.cs b/DMS.WPF/Services/DataServices.cs index 25fd8d6..a37be73 100644 --- a/DMS.WPF/Services/DataServices.cs +++ b/DMS.WPF/Services/DataServices.cs @@ -159,6 +159,28 @@ public partial class DataServices : ObservableObject } + public async Task UpdateDevice(DeviceItemViewModel device) + { + if (!_dataCenterService.Devices.TryGetValue(device.Id, out var deviceDto)) + { + return false; + } + + _mapper.Map(device, deviceDto); + if ( await _dataCenterService.UpdateDeviceAsync(deviceDto)> 0) + { + var menu = Menus.FirstOrDefault(m => + m.MenuType == MenuType.DeviceMenu && + m.TargetId == device.Id); + if (menu != null) + { + menu.Header = device.Name; + } + } + + return true; + } + public void DeleteVariableTableById(int id) { var variableTable = VariableTables.FirstOrDefault(vt => vt.Id == id); @@ -214,6 +236,8 @@ public partial class DataServices : ObservableObject } } + + public void AddMenuItem(MenuItemViewModel menuItemViewModel) { if (menuItemViewModel == null) diff --git a/DMS.WPF/ViewModels/DevicesViewModel.cs b/DMS.WPF/ViewModels/DevicesViewModel.cs index bf6b9c3..6e4d474 100644 --- a/DMS.WPF/ViewModels/DevicesViewModel.cs +++ b/DMS.WPF/ViewModels/DevicesViewModel.cs @@ -180,16 +180,9 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable return; } - int res = await _deviceAppService.UpdateDeviceAsync(_mapper.Map(device)); - if (res > 0) + if (await DataServices.UpdateDevice(device)) { - var menu = DataServices.Menus.FirstOrDefault(m => - m.MenuType == MenuType.DeviceMenu && - m.TargetId == device.Id); - if (menu != null) - { - menu.Header = device.Name; - } + NotificationHelper.ShowSuccess($"编辑设备成功:{device.Name}"); } } catch (Exception e)