增加报警
This commit is contained in:
105
CapMachine.Wpf/Alarm/AlarmRunCell.cs
Normal file
105
CapMachine.Wpf/Alarm/AlarmRunCell.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// 报警运行单元
|
||||
/// </summary>
|
||||
public class AlarmRunCell : BindableBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化函数
|
||||
/// </summary>
|
||||
public AlarmRunCell(IFreeSql freeSql)
|
||||
{
|
||||
CurAlarmConfig = new AlarmConfig();
|
||||
FreeSql = freeSql;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新报警对应的值
|
||||
/// </summary>
|
||||
public void UpdateBoolValue(bool Value)
|
||||
{
|
||||
if (CurAlarmConfig.ActiveType == ActiveType.Bool)
|
||||
{
|
||||
if (CurAlarmConfig.BoolActiveValue == Value)
|
||||
{
|
||||
ActiveState = true;
|
||||
ActiveTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
ActiveState = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 布尔类型的变量 序号
|
||||
/// </summary>
|
||||
public long Index { get; set; }
|
||||
|
||||
private bool _ActiveState = false;
|
||||
/// <summary>
|
||||
/// 报警激活状态
|
||||
/// </summary>
|
||||
public bool ActiveState
|
||||
{
|
||||
get { return _ActiveState; }
|
||||
set
|
||||
{
|
||||
if (_ActiveState != value)
|
||||
{
|
||||
_ActiveState = value;
|
||||
RaisePropertyChanged();
|
||||
|
||||
//报警结束时保存报警
|
||||
if (ActiveState==false)
|
||||
{
|
||||
SaveAlarm();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存报警
|
||||
/// </summary>
|
||||
private void SaveAlarm()
|
||||
{
|
||||
FreeSql.Insert<HistoryAlarm>(new HistoryAlarm()
|
||||
{
|
||||
AlarmLevel = CurAlarmConfig.AlarmLevel,
|
||||
Category = CurAlarmConfig.Category,
|
||||
Message = CurAlarmConfig.Message,
|
||||
Name = CurAlarmConfig.Name,
|
||||
Duration = (long)(DateTime.Now - ActiveTime).TotalSeconds,
|
||||
CreateTime = ActiveTime,
|
||||
}).ExecuteAffrows();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 报警时长
|
||||
/// </summary>
|
||||
public int TimeDuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 激活时间
|
||||
/// </summary>
|
||||
public DateTime ActiveTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前的报警配置
|
||||
/// </summary>
|
||||
public AlarmConfig CurAlarmConfig { get; set; }
|
||||
public IFreeSql FreeSql { get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user