using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeamAAS_VP.Core;
using TeamAAS_VP.Models;
namespace TeamAAS_VP.ViewModels.Home
{
public class SetAlarmValueViewModel : BindableBase, IDialogAware
{
#region 属性
private int _BitAlarmValue;
public int BitAlarmValue
{
get { return _BitAlarmValue; }
set { SetProperty(ref _BitAlarmValue, value); }
}
private int _NozzleAlarmValue;
public int NozzleAlarmValue
{
get { return _NozzleAlarmValue; }
set { SetProperty(ref _NozzleAlarmValue, value); }
}
private NumberStatistics _NumStatistics = new NumberStatistics();
///
/// 数量(批头、吸嘴、供料器)
///
public NumberStatistics NumStatistics
{
get { return _NumStatistics; }
set { SetProperty(ref _NumStatistics, value); }
}
#endregion
#region 命令
private DelegateCommand _ConfirmCommand;
public DelegateCommand ConfirmCommand =>
_ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
private DelegateCommand _CancelCommand;
public DelegateCommand CancelCommand =>
_CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
#endregion
void ExecuteCancelCommand()
{
IDialogParameters parameters = new DialogParameters();
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
}
void ExecuteConfirmCommand()
{
NumStatistics.NozzleAlarmValue = NozzleAlarmValue;
NumStatistics.HeaderAlarmValue = BitAlarmValue;
FileHelper.WriteJsonFile(NumStatistics, FilePath.NumberStatisticsPath);
IDialogParameters parameters = new DialogParameters();
RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
}
public string Title => "Set Bit/Nozzle Alarm Value";
public event Action RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
try
{
var res = FileHelper.ReadJsonFile(FilePath.NumberStatisticsPath);
if (res != null)
{
BitAlarmValue = res.HeaderAlarmValue;
NozzleAlarmValue = res.NozzleAlarmValue;
}
}
catch (Exception)
{
}
}
}
}