Пример #1
0
        public string DeleteNav(string navids)
        {
            var oldNavList = from n in NavigationDal.Instance.GetAll().ToList()
                             where navids.Split(',').Contains(n.KeyId.ToString())
                             select n;
            string msg = "删除失败。";
            int    k   = NavigationDal.Instance.Delete(navids);

            if (k > 0)
            {
                // 删除与导航菜单分配的按钮列表 2013-07-05
                DeleteNavButtons(navids);

                msg = "删除成功。";
                var log = new LogBll <Navigation>();
                foreach (var n in oldNavList)
                {
                    log.DeleteLog(n);
                }
            }

            return(new JsonMessage {
                Data = k.ToString(), Message = msg, Success = k > 0
            }.ToString());
        }
Пример #2
0
        public string AddNewNav(Navigation nav)
        {
            string msg = "添加失败.";

            if (HasNav(nav.NavTitle, nav.KeyId))
            {
                msg = "菜单名称已存在.";
            }
            var k = NavigationDal.Instance.Insert(nav);

            //if (k > 0)
            //    SetNavButtons(k, "18");  //添加菜单添加默认权限

            if (k > 0)
            {
                msg = "添加成功。";
                LogBll <Navigation> log = new LogBll <Navigation>();
                nav.KeyId = k;
                log.AddLog(nav);
            }

            return(new JsonMessage {
                Data = k.ToString(), Message = msg, Success = k > 0
            }.ToString());
        }
Пример #3
0
        public string Update(Role r)
        {
            string msg = "编辑失败";

            if (HasRoleName(r.RoleName, r.KeyId))
            {
                msg = "角色名称已存在。";
            }
            Role old = RoleDal.Instance.Get(r.KeyId);
            int  k   = RoleDal.Instance.Update(r);

            if (k > 0)
            {
                msg = "编辑成功";
                LogBll <Role> log = new LogBll <Role>();
                log.UpdateLog(old, r);
            }

            if (r.IsDefault == 1)
            {
                SetDefaultRole(r.KeyId);
            }

            return(new JsonMessage {
                Success = true, Data = k.ToString(), Message = msg
            }.ToString());
        }
Пример #4
0
        public string Delete(int roleid)
        {
            string msg = "删除失败。";

            //判断是否有用户在使用该角色
            if (HasUsers(roleid))
            {
                msg = "该角色使用中,不能删除!";
                return(new JsonMessage {
                    Success = true, Data = "0", Message = msg
                }.ToString());
            }

            var r = RoleDal.Instance.Get(roleid);

            //先删除角色中分配的权限
            SqlEasy.ExecuteNonQuery("delete Sys_RoleNavBtns where roleid=@roleid", new SqlParameter("@roleid", roleid));
            int k = RoleDal.Instance.Delete(roleid);

            if (k > 0)
            {
                msg = "删除成功。";
                LogBll <Role> log = new LogBll <Role>();
                log.DeleteLog(r);
            }
            return(new JsonMessage {
                Success = true, Data = k.ToString(), Message = msg
            }.ToString());
        }
Пример #5
0
        public string AddUser(User u, string roleIds)
        {
            int    uid = 0;
            string msg = "用户添加失败!";

            if (HasUserName(u.UserName, u.KeyId))
            {
                uid = -2;
                msg = "用户名已存在。";
            }
            else
            {
                u.Password = StringHelper.MD5string(u.Password + u.PassSalt);
                uid        = UserDal.Instance.Insert(u);
                if (!string.IsNullOrEmpty(roleIds))
                {
                    var roleIdArr  = roleIds.Split(',');
                    var roleIdList = roleIdArr.Select(n => PublicMethod.GetInt(n)).ToArray();
                    UserDal.Instance.AddUserTo(uid, roleIdList);
                }

                if (uid > 0)
                {
                    msg = "添加新用户成功!";
                    LogBll <User> log = new LogBll <User>();
                    u.KeyId = uid;
                    log.AddLog(u);
                }
            }
            return(new JsonMessage {
                Data = uid.ToString(), Message = msg, Success = uid > 0
            }.ToString());
        }
Пример #6
0
        public string Add(Role r)
        {
            string msg = "添加失败";

            if (HasRoleName(r.RoleName))
            {
                msg = "角色名称已存在。";
            }
            int k = RoleDal.Instance.Insert(r);

            if (k > 0)
            {
                msg = "添加成功";
                LogBll <Role> log = new LogBll <Role>();
                r.KeyId = k;
                log.AddLog(r);
            }
            if (r.IsDefault == 1)
            {
                SetDefaultRole(r.KeyId);
            }
            return(new JsonMessage {
                Success = true, Data = k.ToString(), Message = msg
            }.ToString());
        }
Пример #7
0
        public string EditDepartment(Department dep)
        {
            string msg    = "修改失败。";
            int    k      = 0;
            var    oldDep = DepartmentDal.Instance.Get(dep.KeyId);

            if (HasDepartmentBy(dep.DepartmentName, dep.KeyId))
            {
                msg = "部门名称已存在。";
            }
            else
            {
                k = DepartmentDal.Instance.Update(dep);
                if (k > 0)
                {
                    msg = "修改成功。";
                    LogBll <Department> log = new LogBll <Department>();
                    log.UpdateLog(oldDep, dep);
                }
            }

            return(new JsonMessage {
                Data = k.ToString(), Message = msg, Success = k > 0
            }.ToString());
        }
Пример #8
0
        public string EditUser(User u)
        {
            int    k;
            string msg = "用户编辑失败。";

            if (HasUserName(u.UserName, u.KeyId))
            {
                k   = -2;
                msg = "用户名已存在。";
            }
            else
            {
                var oldUser = UserDal.Instance.Get(u.KeyId);
                k = UserDal.Instance.Update(u);
                if (k > 0)
                {
                    msg = "用户编辑成功。";
                    LogBll <User> log = new LogBll <User>();
                    log.IgnoreFields(new[] { "keyid", "password", "passsalt", "configjson" }).UpdateLog(oldUser, u);
                }
            }
            return(new JsonMessage {
                Data = k.ToString(), Message = msg, Success = k > 0
            }.ToString());
        }
Пример #9
0
        public string AddNewDepartment(Department dep)
        {
            int    k   = 0;
            string msg = "添加失败!";

            if (HasDepartmentBy(dep.DepartmentName))
            {
                msg = "部门名称已存在!";
            }
            else
            {
                k = DepartmentDal.Instance.Insert(dep);
                if (k > 0)
                {
                    msg = "添加成功。";
                    LogBll <Department> log = new LogBll <Department>();
                    dep.KeyId = k;
                    log.AddLog(dep);
                }
            }

            return(new JsonMessage {
                Data = k.ToString(), Message = msg, Success = k > 0
            }.ToString());
        }
Пример #10
0
        public string DeleteDepartment(int depid)
        {
            int    k   = 0;
            string msg = "删除失败";
            var    dep = DepartmentDal.Instance.Get(depid);

            if (UserDal.Instance.GetUsersCountByDepartment(depid) > 0)
            {
                msg = "部门中有员工数据不能删除!";
            }
            else if (dep.children.Any())
            {
                msg = "有下级部门数据,不能删除。";
            }
            else
            {
                k = DepartmentDal.Instance.Delete(depid);
                if (k > 0)
                {
                    msg = "删除成功。";
                    LogBll <Department> log = new LogBll <Department>();
                    log.DeleteLog(dep);
                }
            }

            return(new JsonMessage {
                Data = k.ToString(), Message = msg, Success = k > 0
            }.ToString());
        }
Пример #11
0
        public int Delete(int dicid)
        {
            Dic d = DicDal.Instance.Get(dicid);

            if (d != null)
            {
                if (d.children.Any())
                {
                    return(2); //有子节点不能删除
                }

                int i = DicDal.Instance.Delete(dicid);
                if (i > 0)
                {
                    LogBll <Dic> log = new LogBll <Dic>();
                    log.DeleteLog(d);
                }
                return(i);
            }
            return(0); //参数错误
        }
Пример #12
0
        public string EditNav(Navigation nav)
        {
            string     msg    = "编辑失败。";
            Navigation oldNav = GetBy(nav.KeyId);

            if (HasNav(nav.NavTitle, nav.KeyId))
            {
                msg = "菜单名称已存在。";
            }

            int k = NavigationDal.Instance.Update(nav);

            if (k > 0)
            {
                msg = "编辑成功。";
                LogBll <Navigation> log = new LogBll <Navigation>();
                log.UpdateLog(oldNav, nav);
            }
            return(new JsonMessage {
                Data = k.ToString(), Message = msg, Success = k > 0
            }.ToString());
        }
Пример #13
0
        public int Add(Dic d)
        {
            if (HasDicCode(d.Code))
            {
                return(0); //字典编码已存在
            }

            int i = DicDal.Instance.Insert(d);

            if (i > 0)
            {
                if (d.IsDefault == 1)
                {
                    DicDal.Instance.UpdateDefaultState(i);
                }

                LogBll <Dic> log = new LogBll <Dic>();
                d.KeyId = i;
                log.AddLog(d);
            }
            return(i);
        }
Пример #14
0
        public int Edit(Dic d)
        {
            if (HasDicCode(d.Code, d.KeyId))
            {
                return(0); //字典编码已存在
            }

            Dic oldDic = DicDal.Instance.Get(d.KeyId);


            int i = DicDal.Instance.Update(d);

            if (i > 0)
            {
                if (d.IsDefault == 1)
                {
                    DicDal.Instance.UpdateDefaultState(d.KeyId);
                }

                LogBll <Dic> log = new LogBll <Dic>();
                log.UpdateLog(oldDic, d);
            }
            return(i);
        }