コード例 #1
0
        /********************************************************************************************************************/
        //
        // GET: /Device/Delete/5
        public ActionResult Delete(int id)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);

            var alerts = (from p in db.Alerts
                              where p.Device_Information.Device_Name.Contains(device.Device_Name)
                              select p).ToList();
            if (alerts.Count() > 0)
            {
                foreach (var alert in alerts)
                {
                    db.Alerts.Remove(alert);
                }
            }

            var monitor = (from p in db.Monitor
                          where p.Device_Information.Device_Name.Contains(device.Device_Name)
                          select p).ToList();
            if (monitor.Count() > 0)
            {
                foreach (var mon in monitor)
                {
                    db.Monitor.Remove(mon);
                }
            }

            db.Device_Information.Remove(device );
            db.SaveChanges();

            return RedirectToAction("Index");
            //return View();
        }
コード例 #2
0
        //
        // GET: /AlertLV/Details/5
        public string Details(int id)
        {
            string listresult = "";
            XMLalert result = new XMLalert();
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);

            var alerts = (from p in db.Alerts
                              where p.Device_Information.Device_Name.Contains(device.Device_Name)
                              select p).ToList();

            foreach (var alert in alerts)
            {
                result.Id = alert.Alert_Id;
                result.Name = alert.Device_Information.Device_Name;
                result.Alert = alert.Alert_Types.Alert_Description;
                result.Opendate = alert.Alert_Opendate;
                result.Closedate = alert.Alert_Closedate.ToString();

                listresult += result.XMLresult("AlertArray");
            }

            return listresult;
        }
コード例 #3
0
        //
        // GET: /MonitoringLV/Details/5
        public string Details(int id)
        {
            string listresult = "";
            XMLmonitoring result = new XMLmonitoring();
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);

            var monitors = (from p in db.Monitor
                          where p.Device_Information.Device_Name.Contains(device.Device_Name)
                          select p).ToList();

            foreach (var monitor in monitors)
            {
                result.Id = monitor.Monitor_Id;
                result.Name = monitor.Device_Information.Device_Name;
                result.Date = monitor.Monitor_Date.ToString();
                result.Current = (float)monitor.Monitor_Current;
                result.Voltage = (float)monitor.Monitor_Voltage;

                listresult += result.XMLresult("Array2");
            }

            return listresult;
        }
コード例 #4
0
        public string Ontime(int id)
        {
            string result = "";
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);

            result = result + "hr" + device.Device_OnTime.Value.Hours.ToString();//DateTime.Now.Hour.ToString();
            result = result + "mn" + device.Device_OnTime.Value.Minutes.ToString() + "$\r\n"; //DateTime.Now.Minute.ToString() + "$\r\n";
            return result;
        }
コード例 #5
0
        //GET: /DeviceLV/Control/?id=&mode=&status=
        public string Control(int id, int mode, int status)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);

            device.Device_Mode = mode;
            device.Device_Status = status;
            db.SaveChanges();

            return "OK";
        }
コード例 #6
0
        /********************************************************************************************************************/
        public ActionResult Changemode(int id, int mode, int status)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);
            device.Device_Mode = mode;
            device.Device_Status = status;
            db.SaveChanges();

            return RedirectToAction("Details", new { id = device.Device_Id });
            //return View();
        }
コード例 #7
0
        //
        // GET: /Monitoring/Details/5
        public ActionResult Details(int id)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);
            ViewBag.devicename = device.Device_Name;

            ViewBag.monitoring = (from p in db.Monitor
                              where p.Device_Information.Device_Name.Contains(device.Device_Name)
                              select p).ToList();
            return View();
        }
コード例 #8
0
        public string Create(int id, int type)
        {
            var db = new HefestoDevicesEntities();
            Alerts alert = new Alerts();
            Device_Information device = new Device_Information();
            Alert_Types mess = new Alert_Types();
            //Variables used for obtain information to the mail
            mess = db.Alert_Types.Find(type);
            device = db.Device_Information.Find(id);

            //Creation of new alert
            alert.Alert_Device = id;
            alert.Alert_Type = type;
            alert.Alert_Opendate = DateTime.Now;
            alert.Alert_Isread = 0;

            db.Alerts.Add(alert);
            db.SaveChanges();

            //Creation of the message and maps location
            string message = "Report from: " + device.Device_Name + " about: " + mess.Alert_Description;
            message += "\r\n Location: \r\n";
            message += "http://maps.googleapis.com/maps/api/staticmap?center=" + device.Device_Lat.ToString() + "," + device.DEvice_Long.ToString() + "&zoom=15&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C";
            message += device.Device_Lat.ToString() + "," + device.DEvice_Long.ToString() + "&sensor=false";

            //Creation of the mail's header
            string subject = "Alert from: " + device.Device_Name;
            string address = device.Device_Email;
            string email = "*****@*****.**";
            string password = "******";

            //Send Email  message
            var loginInfo = new NetworkCredential(email, password);
            var msg = new MailMessage();
            var smtpClient = new SmtpClient("smtp.gmail.com", 587);

            msg.From = new MailAddress(email);
            msg.To.Add(new MailAddress(address));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = true;

            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = loginInfo;
            smtpClient.Send(msg);

            //Shows the information of the device after create alert
            return "OK";
        }
コード例 #9
0
        //
        // GET: /DeviceLV/Create?name=&lat=&lon=&mode=&status=&zone=&email=
        public string Create(string name, float lat, float lon, int mode, int status, string zone, string email)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();

            device.Device_Name = name;
            device.Device_Lat = lat;
            device.DEvice_Long = lon;
            device.Device_Mode = mode;
            device.Device_Status = status;
            device.Device_Zone = zone;
            device.Device_Email = email;

            db.Device_Information.Add(device);
            db.SaveChanges();
            return "OK";
        }
コード例 #10
0
        /********************************************************************************************************************/
        //
        // GET: /Device/Create
        public ActionResult Create(string name, float lat, float lon, int mode, int status, string zone,string email)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();

            device.Device_Name = name;
            device.Device_Lat = lat;
            device.DEvice_Long = lon;
            device.Device_Mode = mode;
            device.Device_Status = status;
            device.Device_Zone = zone;
            device.Device_Email = email;

            db.Device_Information.Add(device);
            db.SaveChanges();
            return RedirectToAction("Details", new { id = device.Device_Id  });
            //return View();
        }
コード例 #11
0
        //
        // GET: /DeviceLV/Details/5
        public string Details(int id)
        {
            XMLparser  result= new XMLparser();

            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);

            result.Name = device.Device_Name;
            result.Email = device.Device_Email;
            result.Zone = device.Device_Zone;

            result.Id = device.Device_Id;
            result.Lat = (float) device.Device_Lat;
            result.Long =(float) device.DEvice_Long;
            result.Mode =(int) device.Device_Mode;
            result.Status = (int)device.Device_Status;

            return result.XMLresult("Value");
        }
コード例 #12
0
        /********************************************************************************************************************/
        //
        // GET: /Device/Edit/5
        public ActionResult Edit(int id)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device = db.Device_Information.Find(id);

            return View(device);
        }
コード例 #13
0
        public string GetHist(int id)
        {
            try
            {
                var db = new HefestoDevicesEntities();
                Device_Information device = new Device_Information();
                device = db.Device_Information.Find(id);

                return "st" + device.Device_Histerresys.ToString() + "$";
            }
            catch
            {
                return "ERROR";
            }
        }
コード例 #14
0
        /********************************************************************************************************************/
        //
        // GET: /Device/Details/5
        public ActionResult Details(int id)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();
            device=db.Device_Information.Find(id);
            ViewBag.device = device;
            string maps="http://maps.googleapis.com/maps/api/staticmap?center=" + device.Device_Lat.ToString() + "," + device.DEvice_Long.ToString() + "&zoom=15&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C";
            maps+= device.Device_Lat.ToString() + "," + device.DEvice_Long.ToString() + "&sensor=false";

            ViewBag.maps = maps;
            ViewBag.alerts = (from p in db.Alerts
                         where p.Device_Information.Device_Name.Contains(device.Device_Name )
                         select p).ToList();

            return View();
        }
コード例 #15
0
        public ActionResult New(Device_Information model)
        {
            if (ModelState.IsValid)
            {
                var db = new HefestoDevicesEntities();
                db.Device_Information.Add(model);
                db.SaveChanges();

                return RedirectToAction("Details", new { id = model.Device_Id });
            }

            // If we got this far, something failed, redisplay form
            return View("New");
        }
コード例 #16
0
        /********************************************************************************************************************/
        //
        // GET: /Device/New
        public ActionResult New()
        {
            var viewModel = new Device_Information();
            viewModel.Device_SetPoint = 12;
            viewModel.Device_Histerresys = 2;
            viewModel.Device_OffTime = DateTime.Now.TimeOfDay;
            viewModel.Device_OnTime = DateTime.Now.TimeOfDay;
            viewModel.Device_Port_In = 0;
            viewModel.Device_Port_Off_Under = 0;
            viewModel.Device_Port_On_Over = 0;

            return View(viewModel);
        }
コード例 #17
0
        public string GetPortOn(int id)
        {
            try
            {
                var db = new HefestoDevicesEntities();
                Device_Information device = new Device_Information();
                device = db.Device_Information.Find(id);

                return "st" + device.Device_Port_On_Over.ToString() + "$";
            }
            catch
            {
                return "ERROR";
            }
        }
コード例 #18
0
        public string GetMode(int id)
        {
            try
            {
                var db = new HefestoDevicesEntities();
                Device_Information device = new Device_Information();
                device = db.Device_Information.Find(id);

                return "<" + device.Device_Mode.ToString() + ">";
            }
            catch
            {
                return "ERROR";
            }
        }
コード例 #19
0
        public ActionResult Edit(Device_Information model)
        {
            var db = new HefestoDevicesEntities();
                Device_Information device = new Device_Information();

                device = db.Device_Information.Find(model.Device_Id);

              if (ModelState.IsValid)
            {
                device.Device_Name = model.Device_Name ;
                device.Device_Lat = model.Device_Lat ;
                device.DEvice_Long = model.DEvice_Long;
                device.Device_Mode = model.Device_Mode ;
                device.Device_Status =model.Device_Status ;
                device.Device_Email = model.Device_Email ;
                device.Device_Zone = model.Device_Zone;
                device.Device_OffTime = model.Device_OffTime;
                device.Device_OnTime = model.Device_OnTime;
                device.Device_Port_In = model.Device_Port_In;
                device.Device_Port_Off_Under = model.Device_Port_Off_Under;
                device.Device_Port_On_Over = model.Device_Port_On_Over;
                device.Device_SetPoint = model.Device_SetPoint;
                device.Device_Histerresys = model.Device_Histerresys;

                db.SaveChanges();

                return RedirectToAction("Details", new { id = device.Device_Id });
            }

            // If we got this far, something failed, redisplay form
            return View(device);
        }