namespace BLL { using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Data.Linq; using System.Web.Security; using System.Web.UI.WebControls; using Model; using BLL; public static class Sys_RoleService { public static Model.SGGLDB db = Funs.DB; /// /// 记录数 /// private static int count { get; set; } /// /// 定义变量 /// private static IQueryable qq = from x in db.Sys_Role orderby x.SortIndex select x; /// /// 获取分页列表 /// /// /// /// public static IEnumerable getListData(int startRowIndex, int maximumRows) { IQueryable q = qq; count = q.Count(); if (count == 0) { return new object[] { "" }; } return from x in q.Skip(startRowIndex).Take(maximumRows) select new { x.RoleId, x.RoleName, x.Def, IsAPPLeaderRole = x.IsAPPLeaderRole == true ? "是" : "否", }; } /// /// 获取列表数 /// /// public static int getListCount() { return count; } /// /// 获取角色信息 /// /// 角色Id /// public static Model.Sys_Role GetRole(string roleId) { return Funs.DB.Sys_Role.FirstOrDefault(x => x.RoleId == roleId); } /// /// 增加角色 /// /// /// public static void AddRole(string roleName, string def, string roleType, bool? isAuditFlow, bool? isAPPLeaderRole) { Model.SGGLDB db = Funs.DB; string newKeyID = SQLHelper.GetNewID(typeof(Model.Sys_Role)); Model.Sys_Role role = new Model.Sys_Role(); role.RoleId = newKeyID; role.RoleName = roleName; role.RoleType = roleType; role.Def = def; role.IsAuditFlow = isAuditFlow; role.IsAPPLeaderRole = isAPPLeaderRole; role.IsHeadRole = false; db.Sys_Role.InsertOnSubmit(role); db.SubmitChanges(); } /// /// 修改角色信息 /// /// /// /// public static void UpdateRole(string roleId, string roleName, string def, bool? isAuditFlow, bool? isAPPLeaderRole) { Model.SGGLDB db = Funs.DB; Model.Sys_Role role = db.Sys_Role.First(e => e.RoleId == roleId); role.RoleName = roleName; role.Def = def; role.IsAuditFlow = isAuditFlow; role.IsAPPLeaderRole = isAPPLeaderRole; role.IsHeadRole = false; db.SubmitChanges(); } /// /// 删除角色 /// /// public static void DeleteRole(string roleId) { Model.SGGLDB db = Funs.DB; Model.Sys_Role role = db.Sys_Role.First(e => e.RoleId == roleId); db.Sys_Role.DeleteOnSubmit(role); 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 ListItem[] GetAllRoleList() { var q = (from x in Funs.DB.Sys_Role orderby x.RoleName select x).ToList(); ListItem[] lis = new ListItem[q.Count()]; for (int i = 0; i < q.Count(); i++) { lis[i] = new ListItem(q[i].RoleName ?? "", q[i].RoleId.ToString()); } return lis; } /// /// 获取角色列表 /// /// //public static ListItem[] GetRoleList(bool isAuditFlow) //{ // var q = (from x in Funs.DB.Sys_Role where x.IsAuditFlow==isAuditFlow && x.IsHeadRole==false orderby x.SortIndex select x).ToList(); // ListItem[] lis = new ListItem[q.Count()]; // for (int i = 0; i < q.Count(); i++) // { // lis[i] = new ListItem(q[i].RoleName ?? "", q[i].RoleId.ToString()); // } // return lis; //} } }