Example #1
0
        public ActionResult chart(string terId = "")
        {
            string nowTerId;
            EmdataSearchModel esm = new EmdataSearchModel();

            if (string.IsNullOrEmpty(terId))
            {
                nowTerId = db.Terminals.FirstOrDefault().TerminalID;
                var result = db.EMdatas.Where(p => p.TerminalID == nowTerId).OrderBy(p => p.Update).Include(p => p.Terminal);
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                ViewBag.recentData = recent;
                ViewBag.emData = result;
            }
            else
            {
                nowTerId = terId;
                var result = db.EMdatas.Include(p => p.Terminal).Where(p => p.TerminalID == terId);
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                ViewBag.recentData = recent;
                ViewBag.emData = result;
            }

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

            return View(esm);
        }
Example #2
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);
        }
Example #3
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.EMdatas.Where(p => p.Update >= sTime && p.Update <= eTime && p.TerminalID == model.TerminalID).OrderByDescending(p => p.Update).Include(p => p.Terminal);
         ViewBag.emData = result;
     }
     else
     {
         var result = db.EMdatas.Where(p => p.TerminalID == model.TerminalID).Include(p => p.Terminal).OrderByDescending(p => p.Update);
         ViewBag.emData = result;
     }
     Bindddl();
     return View(model);
 }
Example #4
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);
 }
Example #5
0
        public ActionResult dayChart(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.EMdatas.Where(p => p.Update >= sTime && p.Update <= eTime && p.TerminalID == model.TerminalID).Include(p => p.Terminal);
                if (result.Count() == 0)
                {
                    return View("HaveNoData");
                }
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                DateTime sDate = result.FirstOrDefault().Update;
                DateTime rDate = recent.Update;
                DateTime i = sDate;
                DateTime a = sDate;
                List<EMdata> ls = new List<EMdata>();
                int count = 0;
                for (; i <= rDate; i = i.AddDays(1))
                {
                    EMdata em = new EMdata();
                    em.Update = new DateTime(i.Year, i.Month, i.Day, 12, 0, 0);
                    em.GasIntensity = em.UV = em.Luminance = em.Pm25 = 0;
                    em.Temperature = em.Humidity = 0;
                    foreach (var item in result)
                    {
                        em.TerminalID = item.TerminalID;
                        em.Terminal = item.Terminal;
                        TimeSpan ts = item.Update - i;
                        if (ts.Days >= 0 && ts.Days < 1)
                        {
                            em.Temperature += item.Temperature;
                            em.Humidity += item.Humidity;
                            em.Luminance += item.Luminance;
                            em.Pm25 += item.Pm25;
                            em.UV += item.UV;
                            em.GasIntensity += item.GasIntensity;
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        continue;
                    }
                    em.Temperature = em.Temperature / count;
                    em.Humidity = em.Humidity / count;
                    em.Luminance = em.Luminance / count;
                    em.Pm25 = em.Pm25 / count;
                    em.UV = em.UV / count;
                    em.GasIntensity = em.GasIntensity / count;
                    ls.Add(em);
                    count = 0;
                }

                ViewBag.recentData = ls.LastOrDefault();
                ViewBag.emData = ls;
            }
            else
            {
                var result = db.EMdatas.Where(p => p.TerminalID == model.TerminalID).Include(p => p.Terminal);
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                DateTime sDate = result.FirstOrDefault().Update;
                DateTime rDate = recent.Update;
                DateTime i = sDate;
                DateTime a = sDate;
                List<EMdata> ls = new List<EMdata>();
                int count = 0;
                for (; i <= rDate; i = i.AddDays(1))
                {
                    EMdata em = new EMdata();
                    em.Update = new DateTime(i.Year, i.Month, i.Day, 12, 0, 0);
                    em.GasIntensity = em.UV = em.Luminance = em.Pm25 = 0;
                    em.Temperature = em.Humidity = 0;
                    foreach (var item in result)
                    {
                        em.TerminalID = item.TerminalID;
                        em.Terminal = item.Terminal;
                        TimeSpan ts = item.Update - i;
                        if (ts.Days >= 0 && ts.Days < 1)
                        {
                            em.Temperature += item.Temperature;
                            em.Humidity += item.Humidity;
                            em.Luminance += item.Luminance;
                            em.Pm25 += item.Pm25;
                            em.UV += item.UV;
                            em.GasIntensity += item.GasIntensity;
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        continue;
                    }
                    em.Temperature = em.Temperature / count;
                    em.Humidity = em.Humidity / count;
                    em.Luminance = em.Luminance / count;
                    em.Pm25 = em.Pm25 / count;
                    em.UV = em.UV / count;
                    em.GasIntensity = em.GasIntensity / count;
                    ls.Add(em);
                    count = 0;
                }

                ViewBag.recentData = ls.LastOrDefault();
                ViewBag.emData = ls;
            }
            Bindddl();
            return View(model);
        }
Example #6
0
        public ActionResult dayChart(string terId = "")
        {
            string nowTerId;
            EmdataSearchModel esm = new EmdataSearchModel();

            if (string.IsNullOrEmpty(terId))
            {
                nowTerId = db.Terminals.FirstOrDefault().TerminalID;
                var result = db.EMdatas.Where(p => p.TerminalID == nowTerId).OrderBy(p => p.Update).Include(p => p.Terminal);
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                if (result.Count() == 0)
                {
                    return View("HaveNoData");
                }
                DateTime sDate = result.FirstOrDefault().Update;
                DateTime rDate = recent.Update;
                DateTime i = sDate;
                DateTime a = sDate;
                List<EMdata> ls = new List<EMdata>();
                int count = 0;
                for (; i <= rDate; i = i.AddDays(1))
                {
                    EMdata em = new EMdata();
                    em.Update = new DateTime(i.Year, i.Month, i.Day, 12, 0, 0);
                    em.GasIntensity = em.UV = em.Luminance = em.Pm25 = 0;
                    em.Temperature = em.Humidity = 0;
                    foreach (var item in result)
                    {
                        em.TerminalID = item.TerminalID;
                        em.Terminal = item.Terminal;
                        TimeSpan ts = item.Update - i;
                        if (ts.Days >= 0 && ts.Days < 1)
                        {
                            em.Temperature += item.Temperature;
                            em.Humidity += item.Humidity;
                            em.Luminance += item.Luminance;
                            em.Pm25 += item.Pm25;
                            em.UV += item.UV;
                            em.GasIntensity += item.GasIntensity;
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        continue;
                    }
                    em.Temperature = em.Temperature / count;
                    em.Humidity = em.Humidity / count;
                    em.Luminance = em.Luminance / count;
                    em.Pm25 = em.Pm25 / count;
                    em.UV = em.UV / count;
                    em.GasIntensity = em.GasIntensity / count;
                    ls.Add(em);
                    count = 0;
                }

                ViewBag.recentData = ls.LastOrDefault();
                ViewBag.emData = ls;
            }
            else
            {
                nowTerId = terId;
                var result = db.EMdatas.Include(p => p.Terminal).Where(p => p.TerminalID == terId);
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                ViewBag.recentData = recent;
                ViewBag.emData = result;
            }

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

            return View(esm);
        }
Example #7
0
 public ActionResult chart(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.EMdatas.Where(p => p.Update >= sTime && p.Update <= eTime && p.TerminalID == model.TerminalID).Include(p => p.Terminal);
         if (result.Count() == 0)
         {
             return View("HaveNoData");
         }
         ViewBag.emData = result;
         var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
         ViewBag.recentData = recent;
     }
     else
     {
         var result = db.EMdatas.Where(p => p.TerminalID == model.TerminalID).Include(p => p.Terminal);
         ViewBag.emData = result;
         var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
         ViewBag.recentData = recent;
     }
     Bindddl();
     return View(model);
 }