上传文件至「/」
This commit is contained in:
108
AlarmService.cs
Normal file
108
AlarmService.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
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.Runtime.Remoting.Contexts;
|
||||
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 TAlarm GetInAlarm(int tagId)
|
||||
{
|
||||
using (var Context = new BakingEntities())
|
||||
{
|
||||
return (from a in Context.Set<TAlarm>()
|
||||
where a.TagId == tagId && a.StopTime == null
|
||||
select a).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<TAlarm> GetInAlarms()
|
||||
{
|
||||
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(TAlarm alarm)
|
||||
{
|
||||
using (var Context = new BakingEntities())
|
||||
{
|
||||
Context.Set<TAlarm>().Add(alarm);
|
||||
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).OrderByDescending(x => x.StartTime).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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user