114 lines
3.5 KiB
C#
114 lines
3.5 KiB
C#
|
|
using Cowain.Bake.Common.Enums;
|
|||
|
|
using Cowain.Bake.Model;
|
|||
|
|
using Cowain.Bake.Model.Models;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Data.Entity;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Unity;
|
|||
|
|
|
|||
|
|
namespace Cowain.Bake.BLL
|
|||
|
|
{
|
|||
|
|
public class AlarmService : ServiceBase
|
|||
|
|
{
|
|||
|
|
public AlarmService(IUnityContainer unityContainer) : base(unityContainer)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public TAlarm GetInAlarm(Variable node, string desc)
|
|||
|
|
{
|
|||
|
|
using (var Context = new BakingEntities())
|
|||
|
|
{
|
|||
|
|
return (from a in Context.Set<TAlarm>()
|
|||
|
|
where a.Desc == desc
|
|||
|
|
&& a.StationId == node.StationId
|
|||
|
|
&& a.StopTime == null
|
|||
|
|
select a).FirstOrDefault();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<TAlarm> GetInAlarm(int stationId)
|
|||
|
|
{
|
|||
|
|
using (var Context = new BakingEntities())
|
|||
|
|
{
|
|||
|
|
return (from a in Context.Set<TAlarm>()
|
|||
|
|
where a.StationId == stationId
|
|||
|
|
&& a.StopTime == null
|
|||
|
|
select a).ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<TAlarm> GetAllInAlarms()
|
|||
|
|
{
|
|||
|
|
using (var Context = new BakingEntities())
|
|||
|
|
{
|
|||
|
|
return (from a in Context.Set<TAlarm>()
|
|||
|
|
where a.StopTime == null
|
|||
|
|
select a).ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public int CancelAlarm(TAlarm alarm)
|
|||
|
|
{
|
|||
|
|
alarm.Status = EAlarmStatus.Renew.GetDescription();
|
|||
|
|
alarm.StopTime = DateTime.Now;
|
|||
|
|
|
|||
|
|
using (var Context = new BakingEntities())
|
|||
|
|
{
|
|||
|
|
Context.Set<TAlarm>().Attach(alarm);//将数据附加到上下文,支持实体修改和新实体,重置为UnChanged
|
|||
|
|
Context.Entry<TAlarm>(alarm).State = EntityState.Modified;
|
|||
|
|
return Context.SaveChanges();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//一个信号报警
|
|||
|
|
public int Insert(Variable node)
|
|||
|
|
{
|
|||
|
|
TAlarm model = new TAlarm()
|
|||
|
|
{
|
|||
|
|
Desc = node.VarDesc,
|
|||
|
|
StationId = node.StationId,
|
|||
|
|
StartTime = DateTime.Now,
|
|||
|
|
Status = EAlarmStatus.Alert.GetDescription(),
|
|||
|
|
};
|
|||
|
|
using (var Context = new BakingEntities())
|
|||
|
|
{
|
|||
|
|
Context.Set<TAlarm>().Add(model);
|
|||
|
|
return Context.SaveChanges();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public List<TAlarm> GetAlarmReport(string startTime, string endTime)
|
|||
|
|
{
|
|||
|
|
DateTime startDateTime = DateTime.Parse(startTime + " 00:00:01");
|
|||
|
|
DateTime endDateTime = DateTime.Parse(endTime + " 23:59:59");
|
|||
|
|
using (var Context = new BakingEntities())
|
|||
|
|
{
|
|||
|
|
return (from a in Context.Set<TAlarm>()
|
|||
|
|
where a.StartTime >= startDateTime
|
|||
|
|
&& a.StartTime <= endDateTime
|
|||
|
|
select a).ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public int Insert(Variable node, string desc)
|
|||
|
|
{
|
|||
|
|
TAlarm model = new TAlarm()
|
|||
|
|
{
|
|||
|
|
Desc = desc,
|
|||
|
|
StationId = node.StationId,
|
|||
|
|
StartTime = DateTime.Now,
|
|||
|
|
Status = EAlarmStatus.Alert.GetDescription()
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
using (var Context = new BakingEntities())
|
|||
|
|
{
|
|||
|
|
Context.Set<TAlarm>().Add(model);
|
|||
|
|
return Context.SaveChanges();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|