Пример #1
0
        public ActionResult Index(string terId = "")
        {
            string nowTerId;
            EmdataSearchModel esm = new EmdataSearchModel();

            if (string.IsNullOrEmpty(terId))
            {
                nowTerId = db.Terminals.FirstOrDefault().TerminalID;
                var result = db.Alarms.Where(p => p.AlarmTermID == nowTerId).OrderByDescending(p=>p.AlarmDate).Include(p => p.Terminal);

                List<Alarm> ls = new List<Alarm>();
                foreach (var item in result)
                {
                    Alarm newAlarmItem = new Alarm();
                    newAlarmItem.AlarmContent = item.AlarmContent;
                    newAlarmItem.AlarmDate = item.AlarmDate;
                    newAlarmItem.AlarmID = item.AlarmID;
                    newAlarmItem.IsRead = item.IsRead;
                    newAlarmItem.Terminal = item.Terminal;
                    ls.Add(newAlarmItem);
                    item.IsRead = 1;
                }
                db.SaveChanges();
                ViewBag.alarmData = ls;
            }
            else
            {
                nowTerId = terId;
                var result = db.Alarms.Include(p => p.Terminal).Where(p => p.AlarmTermID == terId).OrderByDescending(p => p.AlarmDate);
                List<Alarm> ls = new List<Alarm>();
                foreach (var item in result)
                {
                    Alarm newAlarmItem = new Alarm();
                    newAlarmItem.AlarmContent = item.AlarmContent;
                    newAlarmItem.AlarmDate = item.AlarmDate;
                    newAlarmItem.AlarmID = item.AlarmID;
                    newAlarmItem.IsRead = item.IsRead;
                    newAlarmItem.Terminal = item.Terminal;
                    ls.Add(newAlarmItem);
                    item.IsRead = 1;
                }
                db.SaveChanges();
                ViewBag.alarmData = ls;
            }

            esm.TerminalID = nowTerId;
            esm.StartTime = new DateTime(2010, 1, 1);
            esm.EndTime = DateTime.Now;
            Bindddl();

            return View(esm);
        }
Пример #2
0
 public ActionResult Index(EmdataSearchModel model)
 {
     if (this.ModelState.IsValid)
     {
         DateTime sTime = new DateTime(model.StartTime.Year, model.StartTime.Month, model.StartTime.Day, 0, 0, 0);
         DateTime eTime = new DateTime(model.EndTime.Year, model.EndTime.Month, model.EndTime.Day, 23, 59, 59);
         var result = db.Alarms.Where(p => p.AlarmDate >= sTime && p.AlarmDate <= eTime && p.AlarmTermID == model.TerminalID).OrderByDescending(p => p.AlarmDate).Include(p => p.Terminal);
         List<Alarm> ls = new List<Alarm>();
         foreach (var item in result)
         {
             Alarm newAlarmItem = new Alarm();
             newAlarmItem.AlarmContent = item.AlarmContent;
             newAlarmItem.AlarmDate = item.AlarmDate;
             newAlarmItem.AlarmID = item.AlarmID;
             newAlarmItem.IsRead = item.IsRead;
             newAlarmItem.Terminal = item.Terminal;
             ls.Add(newAlarmItem);
             item.IsRead = 1;
         }
         db.SaveChanges();
         ViewBag.alarmData = ls;
     }
     else
     {
         var result = db.Alarms.Where(p => p.AlarmTermID == model.TerminalID).OrderByDescending(p => p.AlarmDate).Include(p => p.Terminal);
         List<Alarm> ls = new List<Alarm>();
         foreach (var item in result)
         {
             Alarm newAlarmItem = new Alarm();
             newAlarmItem.AlarmContent = item.AlarmContent;
             newAlarmItem.AlarmDate = item.AlarmDate;
             newAlarmItem.AlarmID = item.AlarmID;
             newAlarmItem.IsRead = item.IsRead;
             newAlarmItem.Terminal = item.Terminal;
             ls.Add(newAlarmItem);
             item.IsRead = 1;
         }
         db.SaveChanges();
         ViewBag.alarmData = ls;
     }
     Bindddl();
     return View(model);
 }
Пример #3
0
        public ActionResult Receive(string terID, double tem, double humi, int pm25, int lum, int uv, int gas, double votal)
        {
            var terminal = db.Terminals.FirstOrDefault(p => p.TerminalID == terID);
            if (terminal == null)
            {
                Response.Write("Is not exist this terminal:TerminalID=" + terID);
                return View();
            }
            EMdata newData = new EMdata();
            newData.TerminalID = terID;
            newData.Temperature = tem;
            newData.Humidity = humi;
            newData.Pm25 = pm25;
            newData.Luminance = lum;
            newData.UV = uv;
            newData.GasIntensity = gas;
            newData.Update = DateTime.Now;
            db.EMdatas.Add(newData);
            terminal.TerminalVotal = votal;
            terminal.TerminalConnect = 1;
            db.SaveChanges();

            string alarmContent = "";
            int isAlarm = 0;
            if (tem >= terminal.TemMax)
            {
                isAlarm = 1;
                alarmContent += "温度超过警戒值;  ";
            }
            if (humi >= terminal.HumiMax)
            {
                isAlarm = 1;
                alarmContent += "湿度超过警戒值;  ";
            }
            if (pm25 >= terminal.Pm25Max)
            {
                isAlarm = 1;
                alarmContent += "PM2.5超过警戒值;  ";
            }
            if (lum >= terminal.LuminMax)
            {
                isAlarm = 1;
                alarmContent += "亮度超过警戒值;  ";
            }
            if (uv >= terminal.UVMax)
            {
                isAlarm = 1;
                alarmContent += "紫外强度超过警戒值;  ";
            }
            if (gas >= terminal.GasMax)
            {
                isAlarm = 1;
                alarmContent += "可燃气体浓度超过警戒值;  ";
            }
            if (isAlarm == 1)
            {
                Alarm newAlarm = new Alarm();
                newAlarm.AlarmContent = alarmContent;
                newAlarm.AlarmTermID = terminal.TerminalID;
                newAlarm.AlarmDate = DateTime.Now;
                newAlarm.IsRead = 0;
                db.Alarms.Add(newAlarm);
                db.SaveChanges();
                Response.Write("Upload succesful.Having alarm.");
            }
            else
            {
                Response.Write("Upload succesful");
            }
            return View();
        }