修改了触发器的问题

This commit is contained in:
2025-09-14 19:58:18 +08:00
parent 8e039e657a
commit ebf67b98fa
16 changed files with 144 additions and 56 deletions

View File

@@ -89,7 +89,16 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
CreateDeviceWithDetailsDto dto = new CreateDeviceWithDetailsDto();
dto.Device = _mapper.Map<DeviceDto>(device);
// 添加null检查
if (_mapper != null)
{
dto.Device = _mapper.Map<DeviceDto>(device);
}
else
{
_notificationService?.ShowError("映射服务未初始化");
return;
}
dto.DeviceMenu = new MenuBeanDto()
@@ -98,6 +107,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
Icon = SegoeFluentIcons.Devices2.Glyph,
TargetViewKey = "DeviceDetailView"
};
if (device.IsAddDefVarTable)
{
dto.VariableTable = new VariableTableDto()
@@ -116,14 +126,34 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
// 添加设备
var addDto = await _wpfDataService.DeviceDataService.AddDevice(dto);
_notificationService.ShowSuccess($"设备添加成功:{addDto.Device.Name}");
// 添加null检查
if (_wpfDataService != null && _wpfDataService.DeviceDataService != null)
{
var addDto = await _wpfDataService.DeviceDataService.AddDevice(dto);
// 添加null检查
if (addDto != null && addDto.Device != null && _notificationService != null)
{
_notificationService.ShowSuccess($"设备添加成功:{addDto.Device.Name}");
}
else if (_notificationService != null)
{
_notificationService.ShowError("设备添加失败");
}
}
else if (_notificationService != null)
{
_notificationService.ShowError("数据服务未初始化");
}
}
catch (Exception e)
{
Console.WriteLine(e);
_notificationService.ShowError($"添加设备的过程中发生错误:{e.Message}", e);
// 添加null检查
if (_notificationService != null)
{
_notificationService.ShowError($"添加设备的过程中发生错误:{e.Message}", e);
}
}
}

View File

@@ -54,7 +54,7 @@ namespace DMS.WPF.ViewModels.Dialogs
if (parameter is TriggerDefinitionDto triggerDto)
{
Trigger = triggerDto;
Title = Trigger.Id == Guid.Empty ? "新建触发器" : "编辑触发器";
Title = Trigger.Id == default(int) ? "新建触发器" : "编辑触发器";
PrimaryButText = "保存";
// Load available variables for selection dropdown
@@ -109,7 +109,7 @@ namespace DMS.WPF.ViewModels.Dialogs
private async Task SaveAsync()
{
// Basic validation
if (Trigger.VariableId == Guid.Empty)
if (Trigger.VariableId == default(int))
{
_notificationService.ShowWarn("请选择关联的变量");
return;
@@ -187,10 +187,10 @@ namespace DMS.WPF.ViewModels.Dialogs
// Set timestamps
Trigger.UpdatedAt = DateTime.UtcNow;
if (Trigger.Id == Guid.Empty)
if (Trigger.Id == default(int))
{
Trigger.CreatedAt = DateTime.UtcNow;
Trigger.Id = Guid.NewGuid();
Trigger.Id = 0; // 对于自增ID设置为0让数据库自动生成
}
// Close dialog with the updated trigger DTO

View File

@@ -63,7 +63,6 @@ namespace DMS.WPF.ViewModels.Triggers
{
var newTrigger = new TriggerDefinitionDto
{
Id = Guid.NewGuid(),
IsActive = true,
Condition = Core.Models.Triggers.ConditionType.GreaterThan,
Action = Core.Models.Triggers.ActionType.SendEmail,