添加了变量表的停用和启用功能,并优化了添加变量表和添加设备的逻辑
This commit is contained in:
@@ -1,21 +1,61 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PMSWPF.Data.Repositories;
|
||||
using PMSWPF.Enums;
|
||||
using PMSWPF.Helper;
|
||||
using PMSWPF.Models;
|
||||
|
||||
namespace PMSWPF.ViewModels;
|
||||
|
||||
partial class VariableTableViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private VariableTable variableTable;
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<DataVariable> _dataVariables;
|
||||
// private readonly ILogger<VariableTableViewModel> _logger;
|
||||
[ObservableProperty] private VariableTable variableTable;
|
||||
[ObservableProperty] private ObservableCollection<DataVariable> _dataVariables;
|
||||
|
||||
/// <summary>
|
||||
/// 是否是第一次加载,防止ToggleSwitch第一次加载触发改变事件
|
||||
/// </summary>
|
||||
public bool IsLoadCompletion { get; set; } = false;
|
||||
|
||||
private readonly VarTableRepository _varTableRepository;
|
||||
|
||||
public VariableTableViewModel()
|
||||
{
|
||||
IsLoadCompletion = false;
|
||||
// _logger = logger;
|
||||
_varTableRepository = new VarTableRepository();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void OnLoaded()
|
||||
{
|
||||
if (VariableTable.DataVariables!=null )
|
||||
|
||||
if (VariableTable.DataVariables != null)
|
||||
{
|
||||
DataVariables = new ObservableCollection<DataVariable>(VariableTable.DataVariables);
|
||||
}
|
||||
IsLoadCompletion = true;
|
||||
}
|
||||
|
||||
public async Task OnIsActiveChanged(bool active)
|
||||
{
|
||||
|
||||
var res = await _varTableRepository.Edit(VariableTable);
|
||||
if (res > 0)
|
||||
{
|
||||
var statusMessage = active ? "已启用" : "已停用";
|
||||
NotificationHelper.ShowMessage($"变量表:{VariableTable.Name},{statusMessage}", NotificationType.Success);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
NotificationHelper.ShowMessage($"变量表:{VariableTable.Name},状态修改失败,状态:{active}", NotificationType.Error);
|
||||
// _logger.LogInformation($"变量表:{VariableTable.Name},状态修改失败,状态:{active}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user