using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.Web.UI.WebControls; namespace BLL { public class CommonService { /// /// 获取多项目系统 /// /// //public static ListItem[] GetIsMoreProjectSystemList() //{ // var q = (from x in Funs.DB.Sys_System // where x.IsMoreProject == true && x.IsEnable == true // orderby x.SorIndex // select x).ToList(); // ListItem[] lis = new ListItem[q.Count()]; // for (int i = 0; i < q.Count(); i++) // { // lis[i] = new ListItem(q[i].SystemName ?? "", q[i].SystemId); // } // return lis; //} ///// ///// 获取本部和现场系统 ///// ///// //public static ListItem[] GetHeadAndProjectSystemList(string systemId) //{ // var system = (from x in Funs.DB.Sys_System // where x.IsEnable == true // orderby x.SorIndex // select x).ToList(); // if (systemId != Const.System_1) // { // string projectSystemId = (Funs.GetNewInt(systemId) + 1).ToString(); // system = system = system.Where(x => (x.SystemId == systemId || x.SystemId == projectSystemId)).OrderBy(x => x.SorIndex).ToList(); // } // ListItem[] lis = new ListItem[system.Count()]; // for (int i = 0; i < system.Count(); i++) // { // lis[i] = new ListItem(system[i].SystemName ?? "", system[i].SystemId); // } // return lis; //} /// /// 判断菜单是否存在 /// /// /// public static bool IsExistMenu(string menuId) { Model.Sys_Menu m = Funs.DB.Sys_Menu.FirstOrDefault(e => e.MenuId == menuId); if (m != null) { return true; } else { return false; } } /// /// 判断按键对应菜单是否存在 /// /// /// public static bool isExistButtonToMenu(string buttonToMenuId) { Model.Sys_ButtonToMenu b = Funs.DB.Sys_ButtonToMenu.FirstOrDefault(e => e.ButtonToMenuId == buttonToMenuId); if (b != null) { return true; } else { return false; } } #region 获取当前人是否具有按钮操作权限 /// /// 本项目用这个方法来获取按钮操作权限(不按项目角色和项目用户来获取按钮操作权限) /// /// 用户id /// 按钮id /// 按钮名称 /// 是否具有权限 public static bool GetAllButtonPowerList(string userId, string menuId, string buttonName) { Model.EProjectDB db = Funs.DB; bool isPower = false; ////定义是否具备按钮权限 var user = BLL.Sys_UserService.GetUsersByUserId(userId); ////用户 if (user != null) { if (user.UserId == Const.GlyId) { isPower = true; } // 根据角色判断是否有按钮权限 if (!string.IsNullOrEmpty(user.RoleId) && !isPower) { var buttonToMenu = from x in db.Sys_ButtonToMenu join y in db.Sys_ButtonPower on x.ButtonToMenuId equals y.ButtonToMenuId where y.RoleId == user.RoleId && y.MenuId == menuId && x.ButtonName == buttonName && x.MenuId == menuId select x; if (buttonToMenu.Count() > 0) { isPower = true; } } } return isPower; } // 分项目时使用 //public static bool GetAllButtonPowerList1(string projectId, string userId, string menuId, string buttonName) //{ // Model.EProjectDB db = Funs.DB; // bool isPower = false; ////定义是否具备按钮权限 // if (buttonName == Const.BtnSelect) // { // return true; // } // var pro = BLL.Base_ProjectService.GetProjectByProjectId(projectId); // if (pro != null && pro.IsClosed == true) // { // return false; // } // var user = BLL.Sys_UserService.GetUsersByUserId(userId); ////用户 // if (user != null) // { // if (user.UserId == Const.GlyId) // { // isPower = true; // } // ////根据角色判断是否有按钮权限 // if (string.IsNullOrEmpty(projectId) // && !string.IsNullOrEmpty(user.RoleId) && !isPower) // { // var buttonToMenu = from x in db.ButtonToMenu // join y in db.Sys_ButtonPower on x.ButtonToMenuId equals y.ButtonToMenuId // where y.RoleId == user.RoleId && y.MenuId == menuId // && x.ButtonName == buttonName && x.MenuId == menuId // select x; // if (buttonToMenu.Count() > 0) // { // isPower = true; // } // } // ////项目不为空的时候 // if (!string.IsNullOrEmpty(projectId) && !isPower) // { // ////判断项目用户是否具有按钮权限 // var userButtonToMenu = from x in db.ButtonToMenu // join y in db.Project_UserButtonPower on x.ButtonToMenuId equals y.ButtonToMenuId // where y.UserId == userId && y.MenuId == menuId && y.ProjectId == projectId // && x.ButtonName == buttonName && x.MenuId == menuId // select x; // if (userButtonToMenu.Count() > 0) // { // isPower = true; // } // if (!isPower) // { // ////判断项目角色是否具有按钮权限 // var projectRoleId = BLL.Project_UserService.GetProjectRoleIdByUserId(projectId, userId); ////项目用户角色 // if (!string.IsNullOrEmpty(projectRoleId)) ////根据角色判断是否有按钮权限 // { // var pbuttonToMenu = from x in db.ButtonToMenu // join y in db.Project_RoleButtonPower on x.ButtonToMenuId equals y.ButtonToMenuId // where y.RoleId == projectRoleId && y.MenuId == menuId && y.ProjectId == projectId // && x.ButtonName == buttonName && x.MenuId == menuId // select x; // if (pbuttonToMenu.Count() > 0) // { // isPower = true; // } // } // } // } // } // return isPower; //} #endregion #region 根据登陆id和系统id得到菜单列表 /// /// 根据登陆id和系统id得到菜单列表 /// /// /// /// //public static List GetMenu(string projectId, string userId, string menuModule) //{ // List reMenuList = new List(); ////要返回的菜单列表 // var user = BLL.Sys_UserService.GetUsersByUserId(userId); ////用户 // if (user != null) // { // if (user.UserId == Const.GlyId) //// 如果是管理员或者本部人员返回所有菜单 // { // var sysMenu = from x in Funs.DB.Sys_Menu where x.MenuModule == menuModule orderby x.SortIndex select x; // reMenuList = sysMenu.ToList(); // } // else // { // if (string.IsNullOrEmpty(projectId)) // { // ////得到非项目菜单 // var sysMenuRole = from x in Funs.DB.Sys_Menu // join y in Funs.DB.Sys_RolePower on x.MenuId equals y.MenuId // where x.MenuModule == menuModule && y.RoleId == user.RoleId // orderby x.SortIndex // select x; // reMenuList = sysMenuRole.ToList(); // } // else // { // // 项目角色 权限菜单 // var projectUser = BLL.Project_UserService.GetProject_UserByProjectIdUserId(projectId, userId); // if (projectUser != null) // { // var sysMenuProjectRole = from x in Funs.DB.Sys_Menu // join y in Funs.DB.Project_RolePower on x.MenuId equals y.MenuId // where x.MenuModule == menuModule && y.RoleId == projectUser.RoleId // && y.ProjectId == projectId // orderby x.SortIndex // select x; // if (sysMenuProjectRole.Count() > 0) // { // reMenuList.AddRange(sysMenuProjectRole); // } // } // // 项目人员 权限菜单 // var sysMenuProjectUser = from x in Funs.DB.Sys_Menu // join y in Funs.DB.Project_UserPower on x.MenuId equals y.MenuId // where x.MenuModule == menuModule && y.UserId == user.UserId && y.ProjectId == projectId // orderby x.SortIndex // select x; // if (sysMenuProjectUser.Count() > 0) // { // reMenuList.AddRange(sysMenuProjectUser); // } // } // } // } ////var deskMenu = GetDeskDesktopMenuId(menuModule); ////if (deskMenu != null) ////{ //// // 得到首页导航菜单列表 用于空权限登陆加载 //// var sysMenuDesk = from x in Funs.DB.Sys_Menu where deskMenu.Contains(x.MenuId) select x; //// reMenuList.AddRange(sysMenuDesk); ////} // reMenuList = reMenuList.Distinct().OrderBy(x => x.SortIndex).ToList(); // ////对于菜单集合 去重复返回 // return reMenuList; //} /// /// 本项目用这个方法来获取权限(不按项目角色和项目用户来获取权限) /// /// /// /// public static List GetMenuByRoleRower(string userId) { List reMenuList = new List(); ////要返回的菜单列表 var user = BLL.Sys_UserService.GetUsersByUserId(userId); ////用户 if (user != null) { if (user.UserId == Const.GlyId) //// 如果是管理员或者本部人员返回所有菜单 { var sysMenu = from x in Funs.DB.Sys_Menu orderby x.SortIndex select x; reMenuList = sysMenu.ToList(); } else { var sysMenuRole = from x in Funs.DB.Sys_Menu join y in Funs.DB.Sys_ButtonPower on x.MenuId equals y.MenuId where y.RoleId == user.RoleId orderby x.SortIndex select x; reMenuList = sysMenuRole.ToList(); // PM,EM,CM权限特殊处理 List pm = (from x in Funs.DB.Editor_EProject select x.ProjectControl_ProjectManagerId).ToList(); List cm = (from x in Funs.DB.Editor_EProject select x.ProjectControl_ConstManagerId).ToList(); List em = (from x in Funs.DB.Editor_EProject select x.ProjectControl_EMManagerId).ToList(); if (pm.Contains(user.UserId) || em.Contains(user.UserId)) { Model.Sys_Menu addSupMenu = (from x in Funs.DB.Sys_Menu where x.MenuId == "1FA19FE4-D8B9-4D1B-8EB0-CAC05B71AFBB" select x).First(); Model.Sys_Menu addMenu = (from x in Funs.DB.Sys_Menu where x.MenuId == Const.PMEditorMenuId select x).First(); reMenuList.Add(addMenu); } if (cm.Contains(user.UserId)) { Model.Sys_Menu addSupMenu = (from x in Funs.DB.Sys_Menu where x.MenuId == "1FA19FE4-D8B9-4D1B-8EB0-CAC05B71AFBB" select x).First(); Model.Sys_Menu addMenu = (from x in Funs.DB.Sys_Menu where x.MenuId == Const.CMEditorMenuId select x).First(); reMenuList.Add(addMenu); } // 对资源模块的特殊处理:CTE/M具有RP权限 if (user.DepartId == Const.CTEM_DepartId) { Model.Sys_Menu addSupMenu = (from x in Funs.DB.Sys_Menu where x.MenuId == "72CDB9E2-F44B-4F96-A578-3271211FDC15" select x).First(); Model.Sys_Menu addMenu = (from x in Funs.DB.Sys_Menu where x.MenuId == Const.ResourcePlanMenuId select x).First(); reMenuList.Add(addSupMenu); reMenuList.Add(addMenu); } } } reMenuList = reMenuList.Distinct().OrderBy(x => x.SortIndex).ToList(); return reMenuList; } #endregion /// /// Base64加密 /// /// /// public static string Base64Code(string Message) { byte[] bytes = Encoding.Default.GetBytes(Message); return Convert.ToBase64String(bytes); } /// /// Base64解密 /// /// /// public static string Base64Decode(string message) { byte[] bytes = Convert.FromBase64String(message); return Encoding.Default.GetString(bytes); } /// /// 获取用户菜单按钮权限 /// /// /// /// public static List GetAllButtonList(string userId, string menuId) { Model.EProjectDB db = Funs.DB; List buttonList = new List(); List buttons = new List(); if (userId == Const.GlyId) { buttons = (from x in db.Sys_ButtonToMenu where x.MenuId == menuId select x).ToList(); } else { var user = BLL.Sys_UserService.GetUsersByUserId(userId); ////用户 if (user != null) { buttons = (from x in db.Sys_ButtonToMenu join y in db.Sys_ButtonPower on x.ButtonToMenuId equals y.ButtonToMenuId where y.RoleId == user.RoleId && y.MenuId == menuId && x.MenuId == menuId select x).ToList(); } } if (buttons.Count() > 0) { buttonList = buttons.Select(x => x.ButtonEnName).ToList(); } return buttonList; } } }