refactor:完成重构设备的添加,删除,更新。

This commit is contained in:
2025-10-22 14:06:16 +08:00
parent e995ec7207
commit 54d040b45f
76 changed files with 1028 additions and 1161 deletions

View File

@@ -20,9 +20,9 @@ public partial class DeviceDetailViewModel : ViewModelBase
{
private readonly IMapper _mapper;
private readonly IDialogService _dialogService;
private readonly IWpfDataService _dataStorageService;
private readonly IViewDataService _viewDataService;
private readonly INavigationService _navigationService;
private readonly IWPFDataService _wpfDataService;
private readonly IViewCenterService _wpfDataService;
[ObservableProperty]
private DeviceItem _currentDevice;
@@ -36,13 +36,13 @@ public partial class DeviceDetailViewModel : ViewModelBase
private readonly INotificationService _notificationService;
public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, IWpfDataService dataStorageService,
public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, IViewDataService dataStorageService,
INavigationService navigationService,
IWPFDataService wpfDataService, INotificationService notificationService)
IViewCenterService wpfDataService, INotificationService notificationService)
{
_mapper = mapper;
_dialogService = dialogService;
_dataStorageService = dataStorageService;
_viewDataService = dataStorageService;
_navigationService = navigationService;
_notificationService = notificationService;
_wpfDataService = wpfDataService;
@@ -83,7 +83,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
VariableTableItem.Id = addVarTableId;
VariableTableItem.Device = CurrentDevice;
CurrentDevice.VariableTables.Add(VariableTableItem);
_dataStorageService.VariableTables.Add(VariableTableItem.Id, VariableTableItem);
_viewDataService.VariableTables.Add(VariableTableItem.Id, VariableTableItem);
_notificationService.ShowSuccess($"添加变量表成功:{VariableTableItem.Name}");
}
else
@@ -169,11 +169,11 @@ public partial class DeviceDetailViewModel : ViewModelBase
{
if (SelectedVariableTable.Device != null)
{
if (_dataStorageService.Devices.TryGetValue(SelectedVariableTable.DeviceId ,out var device))
if (_viewDataService.Devices.TryGetValue(SelectedVariableTable.DeviceId ,out var device))
{
device.VariableTables.Remove(SelectedVariableTable);
}
_dataStorageService.VariableTables.Remove(SelectedVariableTable.Id);
_viewDataService.VariableTables.Remove(SelectedVariableTable.Id);
SelectedVariableTable.Device.VariableTables.Remove(SelectedVariableTable);
}
_notificationService.ShowSuccess($"变量表:{tableName},删除成功。");
@@ -197,7 +197,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
public override async Task OnNavigatedToAsync(NavigationParameter parameter)
{
if (_dataStorageService.Devices.TryGetValue(parameter.TargetId, out var device))
if (_viewDataService.Devices.TryGetValue(parameter.TargetId, out var device))
{
CurrentDevice = device;
}
@@ -207,7 +207,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
public void NavigateToVariableTable()
{
if (SelectedVariableTable == null) return;
// var menu = _wpfDataService.Menus.FirstOrDefault(m => m.MenuType == MenuType.VariableTableMenu &&
// var menu = _viewCenterService.Menus.FirstOrDefault(m => m.MenuType == MenuType.VariableTableMenu &&
// m.TargetId == SelectedVariableTable.Id);
// if (menu == null) return;
_navigationService.NavigateToAsync(