2025-06-13 18:54:17 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
using AutoMapper;
|
2025-06-13 18:54:17 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2025-06-12 18:41:46 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
using DMS.Application.DTOs;
|
|
|
|
|
|
using DMS.Application.Interfaces;
|
2025-09-16 12:29:09 +08:00
|
|
|
|
using DMS.Application.Interfaces.Database;
|
2025-07-18 22:21:16 +08:00
|
|
|
|
using DMS.Core.Enums;
|
2025-10-03 22:28:58 +08:00
|
|
|
|
using DMS.Core.Models;
|
2025-09-03 18:22:01 +08:00
|
|
|
|
using DMS.WPF.Interfaces;
|
2025-07-19 11:11:01 +08:00
|
|
|
|
using DMS.WPF.Services;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
using DMS.WPF.ViewModels.Dialogs;
|
2025-10-06 18:17:56 +08:00
|
|
|
|
using DMS.WPF.ItemViewModel;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
using iNKORE.UI.WPF.Modern.Common.IconKeys;
|
2025-09-16 13:05:37 +08:00
|
|
|
|
using ObservableCollections;
|
2025-06-10 20:55:39 +08:00
|
|
|
|
|
2025-07-19 11:11:01 +08:00
|
|
|
|
namespace DMS.WPF.ViewModels;
|
2025-06-12 13:15:55 +08:00
|
|
|
|
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设备管理视图模型,负责设备的增删改查操作。
|
|
|
|
|
|
/// </summary>
|
2025-07-27 21:08:58 +08:00
|
|
|
|
public partial class DevicesViewModel : ViewModelBase, INavigatable
|
2025-06-10 20:55:39 +08:00
|
|
|
|
{
|
2025-09-09 13:35:16 +08:00
|
|
|
|
private readonly IWPFDataService _wpfDataService;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
private readonly IDeviceAppService _deviceAppService;
|
|
|
|
|
|
private readonly IMapper _mapper;
|
2025-09-09 13:35:16 +08:00
|
|
|
|
private readonly IDataStorageService _dataStorageService;
|
2025-07-03 13:17:25 +08:00
|
|
|
|
private readonly IDialogService _dialogService;
|
2025-07-30 12:09:00 +08:00
|
|
|
|
private readonly INavigationService _navigationService;
|
2025-07-26 10:05:43 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设备列表。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-06 18:17:56 +08:00
|
|
|
|
private INotifyCollectionChangedSynchronizedViewList<DeviceItem> _devices;
|
2025-07-03 13:17:25 +08:00
|
|
|
|
|
2025-07-27 21:08:58 +08:00
|
|
|
|
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当前选中的设备。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-06 18:17:56 +08:00
|
|
|
|
private DeviceItem _selectedDevice;
|
2025-07-03 13:17:25 +08:00
|
|
|
|
|
2025-09-04 19:59:35 +08:00
|
|
|
|
private readonly INotificationService _notificationService;
|
2025-09-04 17:29:24 +08:00
|
|
|
|
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化 <see cref="DevicesViewModel"/> 类的新实例。
|
|
|
|
|
|
/// </summary>
|
2025-09-12 13:25:39 +08:00
|
|
|
|
/// <param name="mapper">对象映射器。</param>
|
|
|
|
|
|
/// <param name="dataStorageService">数据存储服务。</param>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// <param name="dialogService">对话框服务。</param>
|
2025-09-12 13:25:39 +08:00
|
|
|
|
/// <param name="navigationService">导航服务。</param>
|
2025-09-09 13:35:16 +08:00
|
|
|
|
/// <param name="wpfDataService">主数据服务。</param>
|
2025-09-12 13:25:39 +08:00
|
|
|
|
/// <param name="deviceAppService">设备应用服务。</param>
|
|
|
|
|
|
/// <param name="notificationService">通知服务。</param>
|
2025-09-16 13:05:37 +08:00
|
|
|
|
public DevicesViewModel(IMapper mapper, IDataStorageService dataStorageService,
|
2025-07-30 12:09:00 +08:00
|
|
|
|
IDialogService dialogService, INavigationService navigationService,
|
2025-09-09 13:35:16 +08:00
|
|
|
|
IWPFDataService wpfDataService, IDeviceAppService deviceAppService,
|
2025-09-04 19:59:35 +08:00
|
|
|
|
INotificationService notificationService)
|
2025-06-12 13:15:55 +08:00
|
|
|
|
{
|
2025-07-27 21:08:58 +08:00
|
|
|
|
_mapper = mapper;
|
2025-09-09 13:35:16 +08:00
|
|
|
|
_dataStorageService = dataStorageService;
|
2025-06-26 19:36:27 +08:00
|
|
|
|
_dialogService = dialogService;
|
2025-07-30 12:09:00 +08:00
|
|
|
|
_navigationService = navigationService;
|
2025-09-09 13:35:16 +08:00
|
|
|
|
_wpfDataService = wpfDataService;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
_deviceAppService = deviceAppService;
|
2025-09-04 17:29:24 +08:00
|
|
|
|
_notificationService = notificationService;
|
2025-09-16 13:05:37 +08:00
|
|
|
|
Devices = _dataStorageService.Devices.ToNotifyCollectionChanged(x => x.Value);
|
2025-06-12 13:15:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-16 19:37:13 +08:00
|
|
|
|
|
2025-07-01 21:34:20 +08:00
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 添加设备命令。
|
2025-07-02 22:07:16 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
[RelayCommand]
|
2025-07-27 21:08:58 +08:00
|
|
|
|
public async Task AddDevice()
|
2025-07-02 18:33:08 +08:00
|
|
|
|
{
|
2025-07-27 21:08:58 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// 1. 显示添加设备对话框
|
2025-10-06 18:17:56 +08:00
|
|
|
|
DeviceItem device = await _dialogService.ShowDialogAsync(new DeviceDialogViewModel()
|
2025-09-03 15:16:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
Title = "添加设备",
|
|
|
|
|
|
PrimaryButText = "添加设备"
|
|
|
|
|
|
});
|
2025-07-27 21:58:50 +08:00
|
|
|
|
// 如果用户取消或对话框未返回设备,则直接返回
|
|
|
|
|
|
if (device == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-27 21:08:58 +08:00
|
|
|
|
|
|
|
|
|
|
CreateDeviceWithDetailsDto dto = new CreateDeviceWithDetailsDto();
|
2025-09-14 19:58:18 +08:00
|
|
|
|
// 添加null检查
|
|
|
|
|
|
if (_mapper != null)
|
|
|
|
|
|
{
|
2025-10-07 17:51:24 +08:00
|
|
|
|
dto.Device = _mapper.Map<Device>(device);
|
2025-09-14 19:58:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService?.ShowError("映射服务未初始化");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-07-27 21:08:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dto.DeviceMenu = new MenuBeanDto()
|
|
|
|
|
|
{
|
|
|
|
|
|
Header = device.Name,
|
|
|
|
|
|
Icon = SegoeFluentIcons.Devices2.Glyph,
|
2025-10-04 00:42:59 +08:00
|
|
|
|
TargetViewKey = nameof(DeviceDetailViewModel),
|
2025-09-03 15:16:07 +08:00
|
|
|
|
};
|
2025-09-14 19:58:18 +08:00
|
|
|
|
|
2025-07-28 11:08:56 +08:00
|
|
|
|
if (device.IsAddDefVarTable)
|
|
|
|
|
|
{
|
2025-10-07 17:51:24 +08:00
|
|
|
|
dto.VariableTable = new VariableTable()
|
2025-07-27 21:08:58 +08:00
|
|
|
|
{
|
2025-07-28 11:08:56 +08:00
|
|
|
|
Name = "默认变量表",
|
|
|
|
|
|
Description = "默认变量表",
|
|
|
|
|
|
IsActive = true
|
2025-07-27 21:08:58 +08:00
|
|
|
|
};
|
2025-07-28 11:08:56 +08:00
|
|
|
|
dto.VariableTableMenu = new MenuBeanDto()
|
|
|
|
|
|
{
|
|
|
|
|
|
Header = dto.VariableTable.Name,
|
|
|
|
|
|
Icon = SegoeFluentIcons.DataSense.Glyph,
|
2025-10-03 22:28:58 +08:00
|
|
|
|
TargetViewKey = nameof(VariableTableViewModel)
|
2025-07-28 11:08:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-03 15:16:07 +08:00
|
|
|
|
// 添加设备
|
2025-09-14 19:58:18 +08:00
|
|
|
|
// 添加null检查
|
|
|
|
|
|
if (_wpfDataService != null && _wpfDataService.DeviceDataService != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var addDto = await _wpfDataService.DeviceDataService.AddDevice(dto);
|
2025-09-16 13:05:37 +08:00
|
|
|
|
|
2025-09-14 19:58:18 +08:00
|
|
|
|
// 添加null检查
|
|
|
|
|
|
if (addDto != null && addDto.Device != null && _notificationService != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowSuccess($"设备添加成功:{addDto.Device.Name}");
|
2025-10-01 18:02:33 +08:00
|
|
|
|
|
2025-09-14 19:58:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (_notificationService != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError("设备添加失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (_notificationService != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError("数据服务未初始化");
|
|
|
|
|
|
}
|
2025-07-27 21:08:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(e);
|
2025-09-14 19:58:18 +08:00
|
|
|
|
// 添加null检查
|
|
|
|
|
|
if (_notificationService != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError($"添加设备的过程中发生错误:{e.Message}", e);
|
|
|
|
|
|
}
|
2025-07-27 21:08:58 +08:00
|
|
|
|
}
|
2025-06-10 22:13:06 +08:00
|
|
|
|
}
|
2025-06-13 18:54:17 +08:00
|
|
|
|
|
2025-07-01 21:34:20 +08:00
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 删除设备命令。
|
2025-07-01 21:34:20 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
[RelayCommand]
|
2025-10-06 18:17:56 +08:00
|
|
|
|
private async Task DeleteDevice(DeviceItem parmDeviceItem)
|
2025-07-01 21:34:20 +08:00
|
|
|
|
{
|
2025-07-28 13:06:36 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-09-19 07:27:56 +08:00
|
|
|
|
if (parmDeviceItem != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
SelectedDevice = parmDeviceItem;
|
|
|
|
|
|
}
|
2025-07-28 13:06:36 +08:00
|
|
|
|
if (SelectedDevice == null)
|
|
|
|
|
|
{
|
2025-09-04 17:29:24 +08:00
|
|
|
|
_notificationService.ShowError("你没有选择任何设备,请选择设备后再点击删除设备");
|
2025-07-28 13:06:36 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-03 15:16:07 +08:00
|
|
|
|
var viewModel = new ConfirmDialogViewModel("删除设备", $"确认要删除设备名为:{SelectedDevice.Name}", "删除设备");
|
|
|
|
|
|
if (await _dialogService.ShowDialogAsync(viewModel))
|
2025-07-28 13:06:36 +08:00
|
|
|
|
{
|
2025-09-03 15:16:07 +08:00
|
|
|
|
var deviceName = SelectedDevice.Name;
|
2025-09-09 13:35:16 +08:00
|
|
|
|
if (await _wpfDataService.DeviceDataService.DeleteDevice(SelectedDevice))
|
2025-07-28 13:06:36 +08:00
|
|
|
|
{
|
2025-09-04 17:29:24 +08:00
|
|
|
|
_notificationService.ShowSuccess($"删除设备成功,设备名:{deviceName}");
|
2025-07-28 13:06:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
2025-09-04 17:29:24 +08:00
|
|
|
|
_notificationService.ShowError($"删除设备的过程中发生错误:{e.Message}", e);
|
2025-07-28 13:06:36 +08:00
|
|
|
|
}
|
2025-07-01 21:34:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 编辑设备命令。
|
|
|
|
|
|
/// </summary>
|
2025-07-01 21:34:20 +08:00
|
|
|
|
[RelayCommand]
|
2025-10-06 18:17:56 +08:00
|
|
|
|
private async Task EditDevice(DeviceItem parmDeviceItem)
|
2025-07-01 21:34:20 +08:00
|
|
|
|
{
|
2025-07-29 20:02:09 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-09-19 07:27:56 +08:00
|
|
|
|
if (parmDeviceItem != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
SelectedDevice = parmDeviceItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-29 20:02:09 +08:00
|
|
|
|
if (SelectedDevice == null)
|
|
|
|
|
|
{
|
2025-09-04 17:29:24 +08:00
|
|
|
|
_notificationService.ShowError("你没有选择任何设备,请选择设备后再点击编辑设备");
|
2025-07-29 20:02:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceDialogViewModel deviceDialogViewModel = new DeviceDialogViewModel(SelectedDevice)
|
|
|
|
|
|
{
|
2025-09-03 15:16:07 +08:00
|
|
|
|
PrimaryButText = "编辑设备"
|
2025-07-29 20:02:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
// 1. 显示设备对话框
|
2025-10-06 18:17:56 +08:00
|
|
|
|
DeviceItem device = await _dialogService.ShowDialogAsync(deviceDialogViewModel);
|
2025-07-29 20:02:09 +08:00
|
|
|
|
// 如果用户取消或对话框未返回设备,则直接返回
|
|
|
|
|
|
if (device == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-09 13:35:16 +08:00
|
|
|
|
if (await _wpfDataService.DeviceDataService.UpdateDevice(device))
|
2025-07-29 20:02:09 +08:00
|
|
|
|
{
|
2025-09-04 17:29:24 +08:00
|
|
|
|
_notificationService.ShowSuccess($"编辑设备成功:{device.Name}");
|
2025-07-29 20:02:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
2025-09-04 17:29:24 +08:00
|
|
|
|
_notificationService.ShowError($"编辑设备的过程中发生错误:{e.Message}", e);
|
2025-07-29 20:02:09 +08:00
|
|
|
|
}
|
2025-07-01 21:34:20 +08:00
|
|
|
|
}
|
2025-07-27 21:08:58 +08:00
|
|
|
|
|
2025-07-16 18:39:00 +08:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
|
public void NavigateToDetail()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SelectedDevice == null) return;
|
2025-07-30 12:09:00 +08:00
|
|
|
|
|
2025-10-03 22:28:58 +08:00
|
|
|
|
_navigationService.NavigateToAsync(this,new NavigationParameter(nameof(DeviceDetailViewModel),SelectedDevice.Id,NavigationType.Device));
|
2025-07-16 18:39:00 +08:00
|
|
|
|
}
|
2025-07-26 18:58:52 +08:00
|
|
|
|
|
2025-09-12 13:25:39 +08:00
|
|
|
|
|
2025-10-03 10:49:13 +08:00
|
|
|
|
[RelayCommand]
|
2025-10-06 18:17:56 +08:00
|
|
|
|
private async Task AddVariableTable(DeviceItem device)
|
2025-10-03 10:49:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (device == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
VariableTableDialogViewModel variableTableDialogViewModel = new VariableTableDialogViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
PrimaryButText = "添加变量表"
|
|
|
|
|
|
};
|
|
|
|
|
|
// 显示添加变量表对话框
|
2025-10-06 18:17:56 +08:00
|
|
|
|
var VariableTableItem = await _dialogService.ShowDialogAsync(variableTableDialogViewModel);
|
2025-10-03 10:49:13 +08:00
|
|
|
|
// 如果用户取消或对话框未返回变量表,则直接返回
|
2025-10-06 18:17:56 +08:00
|
|
|
|
if (VariableTableItem == null)
|
2025-10-03 10:49:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-06 18:17:56 +08:00
|
|
|
|
VariableTableItem.DeviceId = device.Id;
|
2025-10-03 10:49:13 +08:00
|
|
|
|
var tableMenu = new MenuBeanDto()
|
|
|
|
|
|
{
|
2025-10-06 18:17:56 +08:00
|
|
|
|
Header = VariableTableItem.Name,
|
2025-10-03 10:49:13 +08:00
|
|
|
|
Icon = SegoeFluentIcons.DataSense.Glyph,
|
2025-10-03 22:28:58 +08:00
|
|
|
|
TargetViewKey = nameof(VariableTableViewModel)
|
2025-10-03 10:49:13 +08:00
|
|
|
|
};
|
|
|
|
|
|
int addVarTableId = await _wpfDataService.VariableTableDataService.AddVariableTable(
|
2025-10-07 17:51:24 +08:00
|
|
|
|
_mapper.Map<VariableTable>(VariableTableItem),
|
2025-10-03 10:49:13 +08:00
|
|
|
|
tableMenu, true);
|
|
|
|
|
|
|
|
|
|
|
|
if (addVarTableId > 0)
|
|
|
|
|
|
{
|
2025-10-06 18:17:56 +08:00
|
|
|
|
VariableTableItem.Id = addVarTableId;
|
|
|
|
|
|
if (_dataStorageService.Devices.TryGetValue(VariableTableItem.DeviceId, out var deviceModel))
|
2025-10-03 10:49:13 +08:00
|
|
|
|
{
|
2025-10-06 18:17:56 +08:00
|
|
|
|
VariableTableItem.Device = deviceModel;
|
|
|
|
|
|
deviceModel.VariableTables.Add(VariableTableItem);
|
|
|
|
|
|
_dataStorageService.VariableTables.Add(VariableTableItem.Id, VariableTableItem);
|
2025-10-03 10:49:13 +08:00
|
|
|
|
}
|
2025-10-06 18:17:56 +08:00
|
|
|
|
_notificationService.ShowSuccess($"添加变量表成功:{VariableTableItem.Name}");
|
2025-10-03 10:49:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-10-06 18:17:56 +08:00
|
|
|
|
_notificationService.ShowError($"添加变量表失败:{VariableTableItem.Name}!!");
|
2025-10-03 10:49:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError($"添加变量表时发生错误: {ex.Message}", ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
2025-10-06 18:17:56 +08:00
|
|
|
|
private async Task EditVariableTable(VariableTableItem variableTable)
|
2025-10-03 10:49:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (variableTable == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError("你没有选择任何变量表,请选择变量表后再点击编辑变量表");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
VariableTableDialogViewModel variableTableDialogViewModel
|
|
|
|
|
|
= new VariableTableDialogViewModel(variableTable)
|
|
|
|
|
|
{
|
|
|
|
|
|
PrimaryButText = "编辑变量表"
|
|
|
|
|
|
};
|
|
|
|
|
|
// 显示变量表对话框
|
2025-10-06 18:17:56 +08:00
|
|
|
|
VariableTableItem updatedVariableTable
|
2025-10-03 10:49:13 +08:00
|
|
|
|
= await _dialogService.ShowDialogAsync(variableTableDialogViewModel);
|
|
|
|
|
|
// 如果用户取消或对话框未返回变量表,则直接返回
|
|
|
|
|
|
if (updatedVariableTable == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (await _wpfDataService.VariableDataService.UpdateVariableTable(updatedVariableTable))
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowSuccess($"编辑变量表成功:{updatedVariableTable.Name}");
|
|
|
|
|
|
|
|
|
|
|
|
// Update the properties in the original variable table
|
|
|
|
|
|
variableTable.Name = updatedVariableTable.Name;
|
|
|
|
|
|
variableTable.Description = updatedVariableTable.Description;
|
|
|
|
|
|
variableTable.IsActive = updatedVariableTable.IsActive;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError($"编辑变量表失败:{updatedVariableTable.Name}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError($"编辑变量表的过程中发生错误:{e.Message}", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
2025-10-06 18:17:56 +08:00
|
|
|
|
private async Task DeleteVariableTable(VariableTableItem variableTable)
|
2025-10-03 10:49:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (variableTable == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError("你没有选择任何变量表,请选择变量表后再点击删除变量表");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string message = $"确认要删除变量表名为:{variableTable.Name} \n\n此操作将同时删除该变量表下的所有变量数据,且无法恢复!";
|
|
|
|
|
|
ConfirmDialogViewModel viewModel = new ConfirmDialogViewModel("删除变量表", message, "删除");
|
|
|
|
|
|
if (await _dialogService.ShowDialogAsync(viewModel))
|
|
|
|
|
|
{
|
|
|
|
|
|
var tableName = variableTable.Name;
|
|
|
|
|
|
if (await _wpfDataService.VariableDataService.DeleteVariableTable(variableTable, true))
|
|
|
|
|
|
{
|
|
|
|
|
|
// Remove from parent device's collection
|
2025-10-03 23:31:04 +08:00
|
|
|
|
if (variableTable.Device != null)
|
2025-10-03 10:49:13 +08:00
|
|
|
|
{
|
2025-10-03 23:31:04 +08:00
|
|
|
|
if (_dataStorageService.Devices.TryGetValue(variableTable.DeviceId ,out var device))
|
|
|
|
|
|
{
|
|
|
|
|
|
device.VariableTables.Remove(variableTable);
|
|
|
|
|
|
}
|
|
|
|
|
|
_dataStorageService.VariableTables.Remove(variableTable.Id);
|
|
|
|
|
|
|
2025-10-03 10:49:13 +08:00
|
|
|
|
variableTable.Device.VariableTables.Remove(variableTable);
|
|
|
|
|
|
}
|
|
|
|
|
|
_notificationService.ShowSuccess($"变量表:{tableName},删除成功。");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError($"变量表:{tableName},删除失败!!!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
_notificationService.ShowError($"删除变量表的过程中发生错误:{e.Message}", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-12 13:25:39 +08:00
|
|
|
|
private void OnDeviceIsActiveChanged(object? sender, bool isActive)
|
|
|
|
|
|
{
|
2025-10-06 18:17:56 +08:00
|
|
|
|
if (sender is DeviceItem DeviceItem)
|
2025-09-12 13:25:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2025-07-26 18:58:52 +08:00
|
|
|
|
}
|
2025-06-10 20:55:39 +08:00
|
|
|
|
}
|