1 feat: 为MqttServerDetailView添加取消关联功能
2 3 - 在MqttServerDetailView的DataGrid右键菜单中添加"取消关联"选项 4 - 实现UnassignAlias命令,允许用户从MQTT服务器取消关联变量 5 - 使用确认对话框以防止误操作 6 - 集成现有的删除API来实际移除变量与MQTT服务器的关联 7 - 更新UI以提供用户反馈 8 9 此功能允许用户通过右键菜单轻松取消MQTT服务器与变量的关联。
This commit is contained in:
@@ -133,21 +133,23 @@ public class MqttAliasDataService : IMqttAliasDataService
|
||||
public async Task<bool> DeleteMqttAlias(MqttAliasItem mqttAlias)
|
||||
{
|
||||
// 从数据库和内存中删除MQTT别名
|
||||
var result = await _mqttAliasManagementService.UpdateAsync(new MqttAlias
|
||||
{
|
||||
Id = mqttAlias.Id,
|
||||
VariableId = mqttAlias.VariableId,
|
||||
MqttServerId = mqttAlias.MqttServerId,
|
||||
Alias = null // Setting alias to null effectively removes the alias
|
||||
});
|
||||
var result = await _mqttAliasManagementService.DeleteAsync(mqttAlias.Id);
|
||||
|
||||
if (result > 0)
|
||||
if (result )
|
||||
{
|
||||
// 从界面删除MQTT别名
|
||||
_dataStorageService.MqttAliases.Remove(mqttAlias.Id);
|
||||
|
||||
if (_dataStorageService.MqttServers.TryGetValue(mqttAlias.MqttServerId, out var mqttServerItem))
|
||||
{
|
||||
mqttServerItem.VariableAliases.Remove(mqttAlias);
|
||||
}
|
||||
if (_dataStorageService.Variables.TryGetValue(mqttAlias.VariableId, out var variableItem))
|
||||
{
|
||||
variableItem.MqttAliases.Remove(mqttAlias);
|
||||
}
|
||||
_dataStorageService.MqttAliases.Remove(mqttAlias.Id, out _);
|
||||
}
|
||||
|
||||
return result > 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user