namespace BLL { using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; public static class Sys_RoleService { /// /// 获取角色信息 /// /// 角色Id /// public static Model.Sys_Role GetRole(string roleId) { return Funs.DB.Sys_Role.FirstOrDefault(x => x.RoleId == roleId); } /// /// 增加角色 /// /// /// public static void AddRole(string roleCode,string roleName, string def) { string newKeyID = SQLHelper.GetNewID(typeof(Model.Sys_Role)); Model.Sys_Role role = new Model.Sys_Role(); role.RoleId = newKeyID; role.RoleCode = roleCode; role.RoleName = roleName; role.Def = def; Funs.DB.Sys_Role.InsertOnSubmit(role); Funs.DB.SubmitChanges(); } /// /// 修改角色信息 /// /// /// /// public static void UpdateRole(string roleId,string roleCode, string roleName, string def) { Model.Sys_Role role = Funs.DB.Sys_Role.First(e => e.RoleId == roleId); role.RoleCode = roleCode; role.RoleName = roleName; role.Def = def; Funs.DB.SubmitChanges(); } /// /// 删除角色 /// /// public static void DeleteRole(string roleId) { Model.Sys_Role role = Funs.DB.Sys_Role.First(e => e.RoleId == roleId); Funs.DB.Sys_Role.DeleteOnSubmit(role); Funs.DB.SubmitChanges(); } /// /// 获取角色名称是否存在 /// /// 角色id /// 角色名称 /// 是否存在 public static bool IsExistRoleName(string roleId, string roleName) { bool isExist = false; var role = Funs.DB.Sys_Role.FirstOrDefault(x => x.RoleName == roleName && x.RoleId != roleId); if (role != null) { isExist = true; } return isExist; } /// /// 根据角色判断用户是否存在 /// /// 角色 /// true:存在;false:不存在 public static bool IsExistUserByRole(string roleId, string userId) { bool isExist = false; if (userId == BLL.Const.Gly) { isExist = true; } else { var m = from x in Funs.DB.Sys_User where x.RoleId == roleId select x; if (m.Count() > 0) { if ((m.Where(z => z.UserId == userId) != null)) { if (m.Where(z => z.UserId == userId).Count() > 0) { return true; } } } } return isExist; } /// /// 获取角色下拉选项 /// /// public static List GetRoleList() { var list = (from x in Funs.DB.Sys_Role orderby x.RoleName select x).ToList(); return list; } public static void InitRoleDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "RoleId"; dropName.DataTextField = "RoleName"; dropName.DataSource = GetRoleList(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } } }