Esempio n. 1
0
        public ActionResult Create([Bind(Include = "id,type,settable")] dev_dict dev_dict)
        {
            if (ModelState.IsValid)
            {
                db.dev_dict.Add(dev_dict);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(dev_dict));
        }
        public ActionResult Apply(FormCollection formcollection) //基本设置的应用按钮
        {
            string name      = formcollection["Name"];
            string logo      = HttpContext.Server.MapPath(Request.Form["logo"].ToString());;//logo
            string uitype    = formcollection["OptionsUI"];
            string app       = formcollection["Appsupport"];
            string beep      = HttpContext.Server.MapPath(Request.Form["beep"].ToString());//beep
            string video     = formcollection["videosource"];
            string picpath   = formcollection["PrtScPath"];
            string videopath = formcollection["VideoPath"];//路径

            if (name != "" && logo != "" && uitype != "" && app != "" && beep != "" && video != "" && picpath != "" && videopath != "")
            {
                gensysEntities gensysdb = new gensysEntities();

                sys_basicconfig purge = new sys_basicconfig()
                {
                    id = 1
                };
                gensysdb.sys_basicconfig.Attach(purge);
                gensysdb.sys_basicconfig.Remove(purge);

                gensysdb.SaveChanges();

                string stralterSQL = @"ALTER TABLE `sys_basicconfig` DROP `id`; 
                                    ALTER TABLE `sys_basicconfig` ADD `id` int NOT NULL FIRST;
                                    ALTER TABLE `sys_basicconfig` MODIFY COLUMN `id` int NOT NULL AUTO_INCREMENT,ADD PRIMARY KEY(id);";
                /*重新使数据库的id归零*/
                gensysdb.Database.ExecuteSqlCommand(stralterSQL);

                sys_basicconfig config_add = new sys_basicconfig();//新表存储这些
                config_add.name        = name;
                config_add.logo        = logo;
                config_add.ui_type     = uitype;
                config_add.app_support = app;
                config_add.beep        = beep;
                config_add.video_src   = video;
                config_add.prtsc_path  = picpath;
                config_add.video_path  = videopath;

                gensysdb.sys_basicconfig.Add(config_add);

                gensysdb.SaveChanges();
            }
            else
            {
                var script = String.Format("<script>alert('请输入完整!');location.href='{0}'</script>", Url.Action("Index", "SystemConfig"));
                //Url.Action()用于指定跳转的路径
                return(Content(script, "text/html"));
            }

            return(RedirectToAction("Index"));
        }
 public ActionResult AddDevice([Bind(Include = "site, dev_type, dev_model, alias, ip, media_port, username, password")] device device)
 {
     if (ModelState.IsValid)
     {
         int count = db.device.Count();
         device.id = count + 1;
         db.device.Add(device);
         db.SaveChanges();
         //return RedirectToAction("Index");
     }
     String test = "location.reload()";
     return RedirectToAction("Index");//return Redirect("index");//return Json("fsdfds");// return JavaScript(test);
 }
        public ActionResult DeleteDevType(int ID) //设备配置页面的删除按钮
        {
            int            tag           = 0;
            gensysEntities gensysdb      = new gensysEntities();
            dev_dict       devtypedelete = new dev_dict()
            {
                id = ID
            };

            gensysdb.dev_dict.Attach(devtypedelete);
            gensysdb.dev_dict.Remove(devtypedelete);

            gensysdb.SaveChanges();

            string stralterSQL = @"ALTER TABLE `dev_dict` DROP `id`; 
                                    ALTER TABLE `dev_dict` ADD `id` int NOT NULL FIRST;
                                    ALTER TABLE `dev_dict` MODIFY COLUMN `id` int NOT NULL AUTO_INCREMENT,ADD PRIMARY KEY(id);";

            /*重新使数据库的id连续*/
            gensysdb.Database.ExecuteSqlCommand(stralterSQL);

            tag = 1; /*操作完成之后,传参到前端,前端得到了就刷新页面*/
            //return Response.Redirect("Index");
            //return RedirectToRoute(new { controller="Home" ,action="Index"});
            //return Index();
            //return RedirectToAction("Index");
            return(Content(tag.ToString()));
        }
        public ActionResult Delete(int ID)
        {
            int tag = 0;

            gensysEntities gensysdb     = new gensysEntities();
            sys_link       configdelete = new sys_link()
            {
                id = ID
            };

            gensysdb.sys_link.Attach(configdelete);
            gensysdb.sys_link.Remove(configdelete);

            gensysdb.SaveChanges();

            string stralterSQL = @"ALTER TABLE `sys_link` DROP `id`; 
                                    ALTER TABLE `sys_link` ADD `id` int NOT NULL FIRST;
                                    ALTER TABLE `sys_link` MODIFY COLUMN `id` int NOT NULL AUTO_INCREMENT,ADD PRIMARY KEY(id);";

            //重新使数据库的id连续
            gensysdb.Database.ExecuteSqlCommand(stralterSQL);

            tag = 1; /*操作完成之后,传参到前端,前端得到了就刷新页面*/
            //return Response.Redirect("Index");
            //return RedirectToRoute(new { controller="Home" ,action="Index"});
            //return Index();
            //return RedirectToAction("Index");
            return(Content(tag.ToString()));
        }
Esempio n. 6
0
        public ActionResult Confirm(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            genbox_alarm alarm = db.genbox_alarm.Find(int.Parse(id));   //要和数据库字段的类型一致

            if (alarm == null)
            {
                return(HttpNotFound());
            }
            alarm.is_confirmed = 1;
            //db.Entry(alarm).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 7
0
        public ActionResult AddDevice(device device)    //[Bind(Include = "alias, site, dev_type, dev_model, uuid, rtsp_url, account, password")
        {
            if (ModelState.IsValid)
            {
                if (device.uuid == null)
                {
                    var script = string.Format("<script>alert('识别编号未填写!');location.href='{0}'</script>", Url.Action("Index", "DeviceMana"));
                    //Url.Action()用于指定跳转的路径
                    return(Content(script, "text/html"));
                }
                else
                {
                    var distinctdev = (from d in db.device
                                       where d.uuid == device.uuid
                                       select d);
                    if (distinctdev.Count() != 0)
                    {
                        var script = string.Format("<script>alert('识别编号重复!');location.href='{0}'</script>", Url.Action("Index", "DeviceMana"));
                        //Url.Action()用于指定跳转的路径
                        return(Content(script, "text/html"));
                    }
                    else
                    {
                        //添加到device
                        int count = db.device.Count();
                        //device.id = count + 1;
                        db.device.Add(device);

                        if (device.dev_type != "GenBox" && device.dev_type != "声波盾")
                        {
                            AddIpcam(device.uuid, device.rtsp_url, device.account, device.password);
                        }
                        db.SaveChanges();
                        //GenboxHelper.ipcam_setup_set(db);
                    }
                }
            }
            return(RedirectToAction("Index"));//return Redirect("index");//return Json("fsdfds");// return JavaScript("location.reload()");
        }
        public ActionResult AddType(FormCollection formcollection) //设备配置页面的添加条目
        {
            string dev_type = formcollection["type"];
            string settable = formcollection["settable"];


            if (dev_type != "" && settable != "")
            {
                gensysEntities gensysdb        = new gensysEntities();
                var            distinctDevType = (from d in gensysdb.dev_dict
                                                  where d.type == dev_type
                                                  select d);
                if (distinctDevType.Count() == 0)
                {
                    dev_dict devadd = new dev_dict();
                    devadd.type     = dev_type;
                    devadd.settable = settable;


                    gensysdb.dev_dict.Add(devadd);

                    gensysdb.SaveChanges();
                }
                else
                {
                    var script = String.Format("<script>alert('用户名重复!');location.href='{0}'</script>", Url.Action("DeviceSettable", "SystemConfig"));
                    //Url.Action()用于指定跳转的路径
                    return(Content(script, "text/html"));
                }
            }
            else
            {
                ViewBag.SubmitForm = "输入数据有误";
                var script = String.Format("<script>alert('输入字段为空!');location.href='{0}'</script>", Url.Action("DeviceSettable", "SystemConfig"));
                //Url.Action()用于指定跳转的路径
                return(Content(script, "text/html"));
            }



            return(RedirectToAction("DeviceSettable"));
        }
        public ActionResult DeletePermission(int ID, string position) //设备配置页面的删除按钮
        {
            int            tag      = 0;
            gensysEntities gensysdb = new gensysEntities();

            //sys_relation rel = gensysdb.sys_relation.Where(c => c.role_id == ID).First
            //sys_relation rel = new sys_relation() { role_id = ID };
            //sys_relation rel = from u in gensysdb.sys_relation where u.role_id select u;
            //gensysdb.sys_relation.Attach(rel);
            //gensysdb.sys_relation.Remove(rel);
            //gensysdb.SaveChanges();
            var sql = @"delete from sys_relation WHERE role_id = @Id";

            gensysdb.Database.ExecuteSqlCommand(
                sql,

                new MySqlParameter("@Id", ID));

            gensysEntities gensysdb2 = new gensysEntities();
            sys_role       del       = gensysdb2.sys_role.Find(ID);

            if (del == null)
            {
                return(HttpNotFound());
            }
            gensysdb2.sys_role.Remove(del);



            gensysdb2.SaveChanges();



            tag = 1; /*操作完成之后,传参到前端,前端得到了就刷新页面*/
            //return Response.Redirect("Index");
            //return RedirectToRoute(new { controller="Home" ,action="Index"});
            //return Index();
            //return RedirectToAction("Index");
            return(Content(tag.ToString()));
        }
        public ActionResult Add(FormCollection formcollection)
        {
            string site = formcollection["Site"];

            System.DateTime time = new DateTime();
            time = DateTime.Now;


            /*属性剩余id ip 文件名三个属性,id自增 ip和文件名读取文件*/

            if (site != "") //后续加入联动规则文件不为空
            {
                gensysEntities gensysdb  = new gensysEntities();
                sys_link       configadd = new sys_link();

                configadd.site        = site;
                configadd.update_time = time;

                gensysdb.sys_link.Add(configadd);

                gensysdb.SaveChanges();
            }
            else
            {
                ViewBag.SubmitForm = "输入数据有误";
                var script = String.Format("<script>alert('输入数据有误!');location.href='{0}'</script>", Url.Action("Index", "LinkageConfig"));
                //Url.Action()用于指定跳转的路径
                return(Content(script, "text/html"));
            }


            //List<sys_user> list = gensysdb.sys_link.ToList();


            //return Json(newproduct.ToList(), JsonRequestBehavior.AllowGet);
            return(RedirectToAction("Index"));
        }
        public ActionResult AddPermission(FormCollection formcollection)
        {
            string pos           = formcollection["position"];
            string home          = formcollection["Home"];
            string systemconfig  = formcollection["SystemConfig"];
            string devicemena    = formcollection["DeviceMena"];
            string linkageconfig = formcollection["LinkageConfig"];
            string report        = formcollection["Report"];
            string log           = formcollection["Log"];
            string usermena      = formcollection["UserMena"];
            string digitalmap    = formcollection["DigitalMap"];
            string ticket        = formcollection["Ticket"];

            if (pos != "")
            {
                gensysEntities gensysdb         = new gensysEntities();
                var            distinctPosition = (from rol in gensysdb.sys_role
                                                   join rel in gensysdb.sys_relation on rol.id equals rel.role_id
                                                   where rol.name == pos
                                                   select rel
                                                   );
                if (distinctPosition.Count() == 0)
                {
                    sys_role roleadd = new sys_role();
                    roleadd.name = pos;
                    gensysdb.sys_role.Add(roleadd);
                    int newroleid = roleadd.id;


                    if (home == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 1;
                        gensysdb.sys_relation.Add(relationadd);
                    }
                    if (systemconfig == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 2;
                        gensysdb.sys_relation.Add(relationadd);
                    }
                    if (devicemena == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 3;
                        gensysdb.sys_relation.Add(relationadd);
                    }
                    if (linkageconfig == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 4;
                        gensysdb.sys_relation.Add(relationadd);
                    }
                    if (report == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 5;
                        gensysdb.sys_relation.Add(relationadd);
                    }
                    if (log == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 6;
                        gensysdb.sys_relation.Add(relationadd);
                    }
                    if (usermena == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 7;
                        gensysdb.sys_relation.Add(relationadd);
                    }
                    if (digitalmap == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 8;
                        gensysdb.sys_relation.Add(relationadd);
                    }
                    if (ticket == "1")
                    {
                        sys_relation relationadd = new sys_relation();
                        relationadd.role_id = newroleid;
                        relationadd.menu_id = 9;
                        gensysdb.sys_relation.Add(relationadd);
                    }


                    gensysdb.SaveChanges();
                }
                else
                {
                    var script = String.Format("<script>alert('职务名称重复!');location.href='{0}'</script>", Url.Action("Permission", "SystemConfig"));
                    //Url.Action()用于指定跳转的路径
                    return(Content(script, "text/html"));
                }
            }
            else
            {
                var script = String.Format("<script>alert('职务名称为空!');location.href='{0}'</script>", Url.Action("Permission", "SystemConfig"));
                //Url.Action()用于指定跳转的路径
                return(Content(script, "text/html"));
            }


            return(RedirectToAction("Permission"));
        }
Esempio n. 12
0
        public ActionResult UpdateGB(FormCollection formcollection, device device)    //[Bind(Include = "alias, site, dev_type, dev_model, uuid, rtsp_url, account, password")
        {
            gensysEntities gensysdb = new gensysEntities();

            if (ModelState.IsValid)
            {
                device device_old = gensysdb.device.Find(device.uuid);
                if (device == null)
                {
                    return(HttpNotFound());
                }
                gensysdb.device.Remove(device_old);
                gensysdb.device.Add(device);
            }

            string camuuid1 = formcollection["cam_uuid1"];
            string algo1    = formcollection["algo1"];
            string cpunum1  = formcollection["cpu_num1"];

            string camuuid2 = formcollection["cam_uuid2"];
            string algo2    = formcollection["algo2"];
            string cpunum2  = formcollection["cpu_num2"];

            string camuuid3 = formcollection["cam_uuid3"];
            string algo3    = formcollection["algo3"];
            string cpunum3  = formcollection["cpu_num3"];

            device availableuuid1 = gensysdb.device.Find(camuuid1);
            device availableuuid2 = gensysdb.device.Find(camuuid2);
            device availableuuid3 = gensysdb.device.Find(camuuid3);

            ipcam cam1, cam2, cam3;

            //判断,如果三个输入的uuid不是空,且查询device表,不存在这个uuid或者不是ipcam的话就不添加
            if (camuuid1 != "" && (availableuuid1 == null || availableuuid1.dev_type == "GenBox" || availableuuid1.dev_type == "声波盾") ||
                camuuid2 != "" && (availableuuid2 == null || availableuuid2.dev_type == "GenBox" || availableuuid2.dev_type == "声波盾") ||
                camuuid3 != "" && (availableuuid3 == null || availableuuid3.dev_type == "GenBox" || availableuuid3.dev_type == "声波盾"))
            {
                var script = string.Format("<script>alert('添加的uuid有问题,请检查后重新输入!');location.href='{0}'</script>", Url.Action("Index", "DeviceMana"));
                //Url.Action()用于指定跳转的路径
                return(Content(script, "text/html"));
            }
            else
            {
                if (camuuid1 != "" && cpunum1 != "")
                {
                    genbox_cpu add1 = new genbox_cpu();
                    add1.ipcam_uuid  = camuuid1;
                    add1.genbox_uuid = device.uuid;
                    add1.algo_value  = algo1;
                    add1.cpu_num     = cpunum1;
                    gensysdb.genbox_cpu.Add(add1);

                    cam1 = gensysdb.ipcam.Find(camuuid1);   //要和数据库字段的类型一致
                    if (cam1 == null)
                    {
                        return(HttpNotFound());
                    }
                    switch (algo1)
                    {
                    case "ebd":
                        cam1.ebd_cpu = int.Parse(cpunum1); break;

                    case "fsd":
                        cam1.fsd_cpu = int.Parse(cpunum1); break;

                    case "opa4t":
                        cam1.opa4t_cpu = int.Parse(cpunum1); break;

                    case "pfr":
                        cam1.pfr_cpu = int.Parse(cpunum1); break;

                    case "ssc":
                        cam1.ssc_cpu = int.Parse(cpunum1); break;

                    case "wca":
                        cam1.wca_cpu = int.Parse(cpunum1); break;
                    }
                    gensysdb.Entry(cam1).State = System.Data.Entity.EntityState.Modified;
                    gensysdb.SaveChanges();
                }
                else if (camuuid1 == "" && cpunum1 == "")
                {
                }
                else
                {
                    var script = string.Format("<script>alert('有表格项未填写完整!');location.href='{0}'</script>", Url.Action("Index", "DeviceMana"));
                    //Url.Action()用于指定跳转的路径
                    return(Content(script, "text/html"));
                }
                if (camuuid2 != "" && cpunum2 != "")
                {
                    genbox_cpu add2 = new genbox_cpu();
                    add2.ipcam_uuid  = camuuid2;
                    add2.genbox_uuid = device.uuid;
                    add2.algo_value  = algo2;
                    add2.cpu_num     = cpunum2;
                    gensysdb.genbox_cpu.Add(add2);

                    cam2 = gensysdb.ipcam.Find(camuuid2);   //要和数据库字段的类型一致
                    if (cam2 == null)
                    {
                        return(HttpNotFound());
                    }
                    switch (algo2)
                    {
                    case "ebd":
                        cam2.ebd_cpu = int.Parse(cpunum2); break;

                    case "fsd":
                        cam2.fsd_cpu = int.Parse(cpunum2); break;

                    case "opa4t":
                        cam2.opa4t_cpu = int.Parse(cpunum2); break;

                    case "pfr":
                        cam2.pfr_cpu = int.Parse(cpunum2); break;

                    case "ssc":
                        cam2.ssc_cpu = int.Parse(cpunum2); break;

                    case "wca":
                        cam2.wca_cpu = int.Parse(cpunum2); break;
                    }
                    //gensysdb.Entry(cam2).State = System.Data.Entity.EntityState.Modified;
                    gensysdb.SaveChanges();
                }
                else if (camuuid2 == "" && cpunum2 == "")
                {
                }
                else
                {
                    var script = string.Format("<script>alert('有表格项未填写完整!');location.href='{0}'</script>", Url.Action("Index", "DeviceMana"));
                    //Url.Action()用于指定跳转的路径
                    return(Content(script, "text/html"));
                }
                if (camuuid3 != "" && cpunum3 != "")
                {
                    genbox_cpu add3 = new genbox_cpu();
                    add3.ipcam_uuid  = camuuid3;
                    add3.genbox_uuid = device.uuid;
                    add3.algo_value  = algo3;
                    add3.cpu_num     = cpunum3;
                    gensysdb.genbox_cpu.Add(add3);

                    cam3 = gensysdb.ipcam.Find(camuuid3);   //要和数据库字段的类型一致
                    if (cam3 == null)
                    {
                        return(HttpNotFound());
                    }
                    switch (algo3)
                    {
                    case "ebd":
                        cam3.ebd_cpu = int.Parse(cpunum3); break;

                    case "fsd":
                        cam3.fsd_cpu = int.Parse(cpunum3); break;

                    case "opa4t":
                        cam3.opa4t_cpu = int.Parse(cpunum3); break;

                    case "pfr":
                        cam3.pfr_cpu = int.Parse(cpunum3); break;

                    case "ssc":
                        cam3.ssc_cpu = int.Parse(cpunum3); break;

                    case "wca":
                        cam3.wca_cpu = int.Parse(cpunum3); break;
                    }
                    //gensysdb.Entry(cam3).State = System.Data.Entity.EntityState.Modified;
                    gensysdb.SaveChanges();
                }
                else if (camuuid3 == "" && cpunum3 == "")
                {
                }
                else
                {
                    var script = string.Format("<script>alert('有表格项未填写完整!');location.href='{0}'</script>", Url.Action("Index", "DeviceMana"));
                    //Url.Action()用于指定跳转的路径
                    return(Content(script, "text/html"));
                }
            }
            gensysdb.SaveChanges();

            GenboxHelper.ipcam_setup_set(db, device);

            return(RedirectToAction("Index"));//return Redirect("index");//return Json("fsdfds");// return JavaScript("location.reload()");
        }
Esempio n. 13
0
        public ActionResult Add(FormCollection formcollection)
        {
            string usertype      = formcollection["role_id"];
            string userid        = formcollection["username"];
            string password      = formcollection["password"];
            string name          = formcollection["name"];
            string department    = formcollection["dept_id"];
            string position      = formcollection["position"];
            string qualification = formcollection["qualification"];
            string idnum         = formcollection["id_number"];
            string phone         = formcollection["phone_number"];

            System.DateTime time = new DateTime();
            time = DateTime.Now;

            System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
            byte[] saltBytes = new byte[36];
            rng.GetBytes(saltBytes);
            string salt = Convert.ToBase64String(saltBytes);

            //string salt = ToHexString(saltBytes);
            //ViewBag.salt = salt;
            /*属性剩余id photo salt三个属性,id自增 salt随机生成 photo路径*/

            if (usertype != "" && userid != "" && password != "" && name != "" && department != "" &&
                position != "" && qualification != "" && idnum != "" && phone != "")
            {
                ViewBag.SubmitForm = usertype + " " + userid + " " + password + " " + name + " " +
                                     department + " " + position + " " + qualification + " " + idnum + " " + phone + " " + time;

                gensysEntities gensysdb     = new gensysEntities();
                var            distinctUser = (from d in gensysdb.sys_user
                                               where d.username == userid
                                               select d);
                if (distinctUser.Count() == 0)
                {
                    sys_user useradd = new sys_user();

                    useradd.role_id       = usertype;
                    useradd.username      = userid;
                    useradd.password      = password;
                    useradd.salt          = salt;
                    useradd.name          = name;
                    useradd.dept_id       = department;
                    useradd.position      = position;
                    useradd.qualification = qualification;
                    useradd.id_number     = idnum;
                    useradd.phone_number  = phone;
                    useradd.register_date = time;

                    gensysdb.sys_user.Add(useradd);

                    gensysdb.SaveChanges();
                }
                else
                {
                    var script = String.Format("<script>alert('用户名重复!');location.href='{0}'</script>", Url.Action("Index", "UserMana"));
                    //Url.Action()用于指定跳转的路径
                    return(Content(script, "text/html"));
                }
            }
            else
            {
                ViewBag.SubmitForm = "输入数据有误";
                var script = String.Format("<script>alert('输入数据有误!');location.href='{0}'</script>", Url.Action("Index", "UserMana"));
                //Url.Action()用于指定跳转的路径
                return(Content(script, "text/html"));
            }


            //List<sys_user> list = gensysdb.sys_user.ToList();


            //return Json(newproduct.ToList(), JsonRequestBehavior.AllowGet);

            return(RedirectToAction("Index"));
        }
Esempio n. 14
0
        public ActionResult AddTrg(FormCollection collection)
        {
            //生成repeat
            var Mon  = collection["Mon"];
            var Tues = collection["Tues"];
            var Wed  = collection["Wed"];
            var Thur = collection["Thur"];
            var Fri  = collection["Fri"];
            var Sat  = collection["Sat"];
            var Sun  = collection["Sun"];
            //过滤 hidden false
            var repeat = "";

            if (Mon.Contains("true"))
            {
                repeat += "1";
            }
            else
            {
                repeat += "0";
            }
            if (Tues.Contains("true"))
            {
                repeat += "1";
            }
            else
            {
                repeat += "0";
            }
            if (Wed.Contains("true"))
            {
                repeat += "1";
            }
            else
            {
                repeat += "0";
            }
            if (Thur.Contains("true"))
            {
                repeat += "1";
            }
            else
            {
                repeat += "0";
            }
            if (Fri.Contains("true"))
            {
                repeat += "1";
            }
            else
            {
                repeat += "0";
            }
            if (Sat.Contains("true"))
            {
                repeat += "1";
            }
            else
            {
                repeat += "0";
            }
            if (Sun.Contains("true"))
            {
                repeat += "1";
            }
            else
            {
                repeat += "0";
            }

            linkage_trigger trg = new linkage_trigger();

            trg.delay   = int.Parse(collection["delay1"]);
            trg.repeat  = repeat;
            trg.trigger = collection["trigger1"];

            db.linkage_trigger.Add(trg);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 15
0
        //[ValidateAntiForgeryToken]
        public JObject RecvAlarm()
        {
            /* 获取报警信息 */
            var ip = Request.UserHostAddress;

            string deviceID  = null;
            string p2pID     = null;
            string token     = null;
            string algID     = null;
            long   timestamp = 0;
            string image     = null;
            string msg       = null;
            string appendix  = null;

            Request.InputStream.Position = 0;
            using (StreamReader inputStream = new StreamReader(Request.InputStream))
            {
                String  str = inputStream.ReadToEnd();
                JObject jo  = (JObject)JsonConvert.DeserializeObject(str);

                try { deviceID = jo["deviceID"].ToString(); }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
                try { p2pID = jo["p2pID"].ToString(); }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
                try { token = jo["token"].ToString(); }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
                try { algID = jo["algID"].ToString(); }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
                try { timestamp = long.Parse(jo["timestamp"].ToString()); }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
                try { image = jo["image"].ToString(); }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
                try { msg = jo["msg"].ToString(); }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
                try { appendix = jo["appendix"].ToString(); }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
            }

            /* 存储报警 */
            if (deviceID != null || p2pID != null)
            {
                //保存目录
                string dir = "Public/AlarmSnap/";
                //站点文件目录
                string fileDir = HttpRuntime.AppDomainAppPath + dir;   // HttpContext.Current.Server.MapPath("~" + dir);
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }

                //文件名称
                string fileName = DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_" + timestamp.ToString() + ".jpg";
                //保存文件所在站点位置
                string filePath = Path.Combine(fileDir, fileName);

                try
                {
                    if (image != null)  //保存报警截图
                    {
                        byte[]       b      = Convert.FromBase64String(image);
                        MemoryStream ms     = new MemoryStream(b);
                        Bitmap       bitmap = new Bitmap(ms);
                        bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace + ex.Message);
                }

                try
                {
                    alarm alarm = new alarm();
                    //alarm.id = db.alarm.Count() + 1;
                    alarm.device_id    = deviceID;
                    alarm.p2p_id       = p2pID;
                    alarm.ip           = ip;
                    alarm.token        = token;
                    alarm.algorithm_id = algID;
                    alarm.timestamp    = timestamp;
                    alarm.image        = filePath;
                    alarm.message      = msg;
                    alarm.appendix     = appendix;

                    alarm.state = "red";
                    var query = from device in db.device
                                where device.ip == ip
                                select new
                    { device.site, device.alias };
                    var queryList = query.ToList();
                    if (queryList.Count > 0)
                    {
                        alarm.site  = queryList[0].site;  //tostring
                        alarm.alias = queryList[0].alias; //tostring
                    }
                    //alarm.type
                    DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                    TimeSpan toNow   = new TimeSpan(timestamp);
                    alarm.datetime  = dtStart.Add(toNow);
                    alarm.confirmed = 0;

                    db.alarm.Add(alarm);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace + ex.Message);
                }
            }

            /* 发送返回信息 */
            JObject postedJObject = new JObject();

            if (token == null || token == "")
            {
                postedJObject.Add("err", 411);
                postedJObject.Add("errMsg", "token错误");
            }
            else
            {
                postedJObject.Add("err", 0);
                postedJObject.Add("errMsg", "ok");
            }
            return(postedJObject);
        }