修复删除设备时的错误
This commit is contained in:
@@ -23,6 +23,18 @@ public interface IEventService
|
|||||||
/// <param name="e">设备状态改变事件参数</param>
|
/// <param name="e">设备状态改变事件参数</param>
|
||||||
void RaiseDeviceActiveChanged(object sender, DeviceActiveChangedEventArgs e);
|
void RaiseDeviceActiveChanged(object sender, DeviceActiveChangedEventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备添加事件
|
||||||
|
/// </summary>
|
||||||
|
event EventHandler<DeviceChangedEventArgs> OnDeviceChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 触发设备添加事件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">事件发送者</param>
|
||||||
|
/// <param name="e">设备变更事件参数</param>
|
||||||
|
void RaiseDeviceChanged(object sender, DeviceChangedEventArgs e);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 变量事件
|
#region 变量事件
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ public class EventService : IEventService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<DeviceConnectChangedEventArgs> OnDeviceConnectChanged;
|
public event EventHandler<DeviceConnectChangedEventArgs> OnDeviceConnectChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备添加事件
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<DeviceChangedEventArgs> OnDeviceChanged;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 触发设备状态改变事件
|
/// 触发设备状态改变事件
|
||||||
@@ -58,6 +63,16 @@ public class EventService : IEventService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 触发设备添加事件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">事件发送者</param>
|
||||||
|
/// <param name="e">设备变更事件参数</param>
|
||||||
|
public void RaiseDeviceChanged(object sender, DeviceChangedEventArgs e)
|
||||||
|
{
|
||||||
|
OnDeviceChanged?.Invoke(sender, e);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 变量事件
|
#region 变量事件
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Windows.Threading;
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using DMS.Application.DTOs;
|
using DMS.Application.DTOs;
|
||||||
|
using DMS.Application.Events;
|
||||||
using DMS.Application.Interfaces;
|
using DMS.Application.Interfaces;
|
||||||
using DMS.Core.Enums;
|
using DMS.Core.Enums;
|
||||||
using DMS.Core.Events;
|
using DMS.Core.Events;
|
||||||
@@ -133,6 +134,7 @@ public class DeviceDataService : IDeviceDataService
|
|||||||
// 添加null检查
|
// 添加null检查
|
||||||
_menuDataService.BuildMenuTrees();
|
_menuDataService.BuildMenuTrees();
|
||||||
|
|
||||||
|
|
||||||
return addDto;
|
return addDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +154,8 @@ public class DeviceDataService : IDeviceDataService
|
|||||||
|
|
||||||
|
|
||||||
// 从界面删除设备相关数据集
|
// 从界面删除设备相关数据集
|
||||||
foreach (var variableTable in device.VariableTables)
|
var variableTablesCopy = device.VariableTables.ToList();
|
||||||
|
foreach (var variableTable in variableTablesCopy)
|
||||||
{
|
{
|
||||||
await _variableTableDataService.DeleteVariableTable(variableTable);
|
await _variableTableDataService.DeleteVariableTable(variableTable);
|
||||||
}
|
}
|
||||||
@@ -164,6 +167,7 @@ public class DeviceDataService : IDeviceDataService
|
|||||||
}
|
}
|
||||||
_dataStorageService.Devices.Remove(device.Id);
|
_dataStorageService.Devices.Remove(device.Id);
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
|||||||
if (addDto != null && addDto.Device != null && _notificationService != null)
|
if (addDto != null && addDto.Device != null && _notificationService != null)
|
||||||
{
|
{
|
||||||
_notificationService.ShowSuccess($"设备添加成功:{addDto.Device.Name}");
|
_notificationService.ShowSuccess($"设备添加成功:{addDto.Device.Name}");
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (_notificationService != null)
|
else if (_notificationService != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user