using CapMachine.Model.Alarm; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CapMachine.Wpf.Alarm { /// /// 报警运行单元 /// public class AlarmRunCell : BindableBase { /// /// 实例化函数 /// public AlarmRunCell(IFreeSql freeSql) { CurAlarmConfig = new AlarmConfig(); FreeSql = freeSql; } /// /// 更新报警对应的值 /// public void UpdateBoolValue(bool Value) { if (CurAlarmConfig.ActiveType == ActiveType.Bool) { if (CurAlarmConfig.BoolActiveValue == Value) { ActiveState = true; ActiveTime = DateTime.Now; } else { ActiveState = false; } } } /// /// 布尔类型的变量 序号 /// public long Index { get; set; } private bool _ActiveState = false; /// /// 报警激活状态 /// public bool ActiveState { get { return _ActiveState; } set { if (_ActiveState != value) { _ActiveState = value; RaisePropertyChanged(); //报警结束时保存报警 if (ActiveState==false) { SaveAlarm(); } } } } /// /// 保存报警 /// private void SaveAlarm() { FreeSql.Insert(new HistoryAlarm() { AlarmLevel = CurAlarmConfig.AlarmLevel, Category = CurAlarmConfig.Category, Message = CurAlarmConfig.Message, Name = CurAlarmConfig.Name, Duration = (long)(DateTime.Now - ActiveTime).TotalSeconds, CreateTime = ActiveTime, }).ExecuteAffrows(); } /// /// 报警时长 /// public int TimeDuration { get; set; } /// /// 激活时间 /// public DateTime ActiveTime { get; set; } /// /// 当前的报警配置 /// public AlarmConfig CurAlarmConfig { get; set; } public IFreeSql FreeSql { get; } } }