2025-07-01 11:11:02 +08:00
|
|
|
using System.Collections.ObjectModel;
|
2025-06-30 14:19:22 +08:00
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2025-07-02 18:33:08 +08:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using PMSWPF.Data.Repositories;
|
|
|
|
|
using PMSWPF.Enums;
|
|
|
|
|
using PMSWPF.Helper;
|
2025-06-30 14:19:22 +08:00
|
|
|
using PMSWPF.Models;
|
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
namespace PMSWPF.ViewModels;
|
|
|
|
|
|
2025-06-30 14:19:22 +08:00
|
|
|
partial class VariableTableViewModel : ViewModelBase
|
2025-06-23 17:01:06 +08:00
|
|
|
{
|
2025-07-02 18:33:08 +08:00
|
|
|
// private readonly ILogger<VariableTableViewModel> _logger;
|
|
|
|
|
[ObservableProperty] private VariableTable variableTable;
|
2025-07-02 22:07:16 +08:00
|
|
|
[ObservableProperty] private ObservableCollection<VariableData> _dataVariables;
|
2025-07-02 18:33:08 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否是第一次加载,防止ToggleSwitch第一次加载触发改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsLoadCompletion { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
private readonly VarTableRepository _varTableRepository;
|
|
|
|
|
|
|
|
|
|
public VariableTableViewModel()
|
|
|
|
|
{
|
|
|
|
|
IsLoadCompletion = false;
|
|
|
|
|
// _logger = logger;
|
|
|
|
|
_varTableRepository = new VarTableRepository();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-02 12:01:20 +08:00
|
|
|
|
2025-07-02 18:33:08 +08:00
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
public override void OnLoaded()
|
|
|
|
|
{
|
2025-07-02 18:33:08 +08:00
|
|
|
|
|
|
|
|
if (VariableTable.DataVariables != null)
|
2025-07-01 11:11:02 +08:00
|
|
|
{
|
2025-07-02 22:07:16 +08:00
|
|
|
DataVariables = new ObservableCollection<VariableData>(VariableTable.DataVariables);
|
2025-07-01 11:11:02 +08:00
|
|
|
}
|
2025-07-02 18:33:08 +08:00
|
|
|
IsLoadCompletion = true;
|
2025-06-23 17:01:06 +08:00
|
|
|
}
|
2025-07-02 18:33:08 +08:00
|
|
|
|
|
|
|
|
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}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
}
|