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()));
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            dev_dict dev_dict = db.dev_dict.Find(id);

            db.dev_dict.Remove(dev_dict);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
 public ActionResult Edit([Bind(Include = "id,type,settable")] dev_dict dev_dict)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dev_dict).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dev_dict));
 }
Esempio n. 4
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));
        }
Esempio n. 5
0
        // GET: dev_dict/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            dev_dict dev_dict = db.dev_dict.Find(id);

            if (dev_dict == null)
            {
                return(HttpNotFound());
            }
            return(View(dev_dict));
        }
        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"));
        }