Ejemplo n.º 1
0
        public async Task <ActionResult> Delete(string id)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "LoginUI"));
            }
            long pwdID = 0;

            if (long.TryParse(id, out pwdID) == false)
            {
                return(Content("入参错误", "text/html"));
            }
            using (mlrmsEntities db = new mlrmsEntities())
            {
                sysadmin matchOne = db.sysadmin.Where(m => m.AdminID == pwdID).ToList().First();
                db.sysadmin.Attach(matchOne);
                db.Entry(matchOne).State = System.Data.Entity.EntityState.Deleted;
                await db.SaveChangesAsync();

                return(RedirectToAction("", "administrator"));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Delete(string id, string serialCode, string port)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "Device"));
            }
            int slaveID     = int.Parse(id);
            int servicePort = int.Parse(port);

            using (mlrmsEntities db = new mlrmsEntities())
            {
                device matchOne = db.device.Where(m => m.slaveid == slaveID && m.servicecode == serialCode && m.port == servicePort).ToList().First();
                db.device.Attach(matchOne);
                db.Entry(matchOne).State = System.Data.Entity.EntityState.Deleted;
                await db.SaveChangesAsync();

                //通知客户端已经移除;
                MvcApplication.Client.Refresh(slaveID, false);
            }
            return(RedirectToAction("Index", "Device"));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Index(Manager info)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            try
            {
                if (ModelState.IsValid)
                {
                    using (mlrmsEntities db = new mlrmsEntities())
                    {
                        var userList = db.sysadmin.Where(m => m.AdminID == info.AdminId);
                        if (userList == null || userList.Count() <= 0)
                        {
                            return(Content("Not Found", "text/html"));
                        }
                        sysadmin item = userList.First();
                        string   pwd  = EncryptHelper.GetEncrypt(info.Passwd);
                        if (pwd != item.AdminPwd)   //如果密码验证不通过
                        {
                            ModelState.AddModelError("Passwd", "密码错误");
                            return(View());
                        }
                        item.AdminPwd = EncryptHelper.GetEncrypt(info.NewPwd);
                        db.sysadmin.Attach(item);
                        db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        await db.SaveChangesAsync();

                        ViewData["status"] = "true";
                        return(RedirectToAction("Logout", "LoginUI"));
                    }
                }
            }
            catch
            {
                ViewData["status"] = "false";
            }
            Manager manager = new Manager();

            manager.UserName = info.UserName;
            //系统登出
            return(View(manager));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create(NewAdmin info)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            try
            {
                using (mlrmsEntities db = new mlrmsEntities())
                {
                    var userList = db.sysadmin.Where(m => m.AdminCode == info.UserCode);

                    if (userList.Count() > 0)
                    {
                        ModelState.AddModelError("UserCode", "该管理员已存在");
                        return(View(info));
                    }
                    sysadmin item = new sysadmin();
                    item.AdminName  = info.UserName;
                    item.CreateDate = DateTime.Now;
                    item.AdminCode  = info.UserCode;
                    item.AdminType  = 1;
                    item.AdminPwd   = EncryptHelper.GetEncrypt("123456");
                    db.sysadmin.Add(item);

                    int result = await db.SaveChangesAsync();

                    return(RedirectToAction("", "administrator"));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("创建管理员失败", ex);
                ViewData["status"] = "false";
            }
            return(View(info));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Delete(string id)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "serialport"));
            }
            try
            {
                using (mlrmsEntities db = new mlrmsEntities())
                {
                    if (db.device.Where(m => m.servicecode == id).Count() > 0)
                    {
                        return(Content("1", "text/html"));
                    }
                    else
                    {
                        serialservice matchOne = db.serialservice.Where(m => m.code == id).ToList().First();
                        db.serialservice.Attach(matchOne);
                        db.Entry(matchOne).State = System.Data.Entity.EntityState.Deleted;
                        await db.SaveChangesAsync();

                        return(Content("0", "text/html"));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("串口服务器删除异常", ex);
                return(Content("2", "text/html"));
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Create(serialservice info)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            if (ModelState.IsValid)
            {
                using (mlrmsEntities db = new mlrmsEntities())
                {
                    if (db.serialservice.Where(m => m.code == info.code || m.name == info.name).Count() > 0)
                    {
                        ModelState.AddModelError("Title", "相同设备编号或设备名称的串口服务器已存在,请更换后重新添加");
                        return(View(info));
                    }

                    try
                    {
                        db.serialservice.Add(info);
                        await db.SaveChangesAsync();

                        //MvcApplication.Client.Refresh(dev.slaveid, true);
                        return(RedirectToAction("Index", "serialport"));
                    }
                    catch
                    {
                        ModelState.AddModelError("Title", "数据保存失败");
                        return(View(info));
                    }
                }
            }
            return(View(info));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Create(DeviceInfo info, string dptName1List, string subList, string serialList)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            info.type = int.Parse(dptName1List);
            if (info.type == (int)DeviceType.MainEngine || info.type == (int)DeviceType.WaterPump)
            {
                info.subType = int.Parse(subList);
            }
            List <DeviceEnumType> list = new List <DeviceEnumType>();

            list.Add(new DeviceEnumType()
            {
                code = "1", name = "热泵主机"
            });
            list.Add(new DeviceEnumType()
            {
                code = "3", name = "水表"
            });
            list.Add(new DeviceEnumType()
            {
                code = "4", name = "电表"
            });
            list.Add(new DeviceEnumType()
            {
                code = "2", name = "热能表"
            });

            SelectList dptSelectlist1 = new SelectList(list, "code", "name", dptName1List);

            ViewData["dptName1List"] = dptSelectlist1;

            List <DeviceEnumType> list2 = new List <DeviceEnumType>();

            list2.Add(new DeviceEnumType()
            {
                code = "5", name = "25P"
            });
            list2.Add(new DeviceEnumType()
            {
                code = "6", name = "50P"
            });

            SelectList dptSelectlist2 = new SelectList(list2, "code", "name", subList);

            ViewData["subList"] = dptSelectlist2;

            SelectList    serialListx = null;
            serialservice seviceItem  = null;

            using (mlrmsEntities db = new mlrmsEntities())
            {
                var slist = db.serialservice.ToList();

                serialListx            = new SelectList(slist, "code", "name", serialList);
                ViewData["serialList"] = serialListx;
                if (slist != null || slist.Count > 0)
                {
                    seviceItem = slist.Where(m => m.code == serialList).First();
                }
            }
            if (info.port > seviceItem.portcount)
            {
                ModelState.AddModelError("Title", "配置的端口号不能大于该串口服务器的串口数,请重新配置");
                return(View(info));
            }
            info.serviceCode = seviceItem.code;
            info.serviceName = seviceItem.name;

            if (ModelState.IsValid)
            {
                using (mlrmsEntities db = new mlrmsEntities())
                {
                    if (db.device.Where(m => m.port == info.port && m.servicecode == info.serviceCode).Count() > 0)
                    {
                        ModelState.AddModelError("Title", "串口服务器的端口已配置,请更换端口号重新添加");
                        return(View(info));
                    }
                    if (db.device.Where(m => m.slaveid == info.slaveID && m.port == info.port && m.servicecode == info.serviceCode).Count() > 0)
                    {
                        ModelState.AddModelError("Title", "相同设备地址的设备已存在,请更换设备地址后重新添加");
                        return(View(info));
                    }

                    device dev = new device();
                    dev.note        = info.note;
                    dev.slaveid     = info.slaveID;
                    dev.servicecode = info.serviceCode;
                    dev.servicename = info.serviceName;
                    dev.port        = info.port;
                    dev.type        = int.Parse(dptName1List);
                    dev.subtype     = info.subType == 0 ? null : (int?)int.Parse(subList);
                    dev.name        = info.devName;
                    dev.note        = info.note;
                    db.device.Add(dev);
                    try
                    {
                        await db.SaveChangesAsync();

                        MvcApplication.Client.Refresh(dev.slaveid, true);
                        return(RedirectToAction("Index", "Device"));
                    }
                    catch
                    {
                        ModelState.AddModelError("Title", "数据保存失败");
                        return(View(info));
                    }
                }
            }
            return(View(info));
        }