302 lines
12 KiB
C#
302 lines
12 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 获取多项目系统
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
//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;
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 获取本部和现场系统
|
|
///// </summary>
|
|
///// <returns></returns>
|
|
//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;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 判断菜单是否存在
|
|
/// </summary>
|
|
/// <param name="postId"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断按键对应菜单是否存在
|
|
/// </summary>
|
|
/// <param name="postId"></param>
|
|
/// <returns></returns>
|
|
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 获取当前人是否具有按钮操作权限
|
|
/// <summary>
|
|
/// 本项目用这个方法来获取按钮操作权限(不按项目角色和项目用户来获取按钮操作权限)
|
|
/// </summary>
|
|
/// <param name="userId">用户id</param>
|
|
/// <param name="menuId">按钮id</param>
|
|
/// <param name="buttonName">按钮名称</param>
|
|
/// <returns>是否具有权限</returns>
|
|
public static bool GetAllButtonPowerList(string userId, string menuId, string buttonName)
|
|
{
|
|
Model.FCLDB 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;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 根据登陆id和系统id得到菜单列表
|
|
|
|
|
|
/// <summary>
|
|
/// 本项目用这个方法来获取权限(不按项目角色和项目用户来获取权限)
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="menuModule"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.Sys_Menu> GetMenuByRoleRower(string userId)
|
|
{
|
|
List<Model.Sys_Menu> reMenuList = new List<Model.Sys_Menu>(); ////要返回的菜单列表
|
|
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();
|
|
|
|
// 对主协调员权限特殊处理
|
|
List<string> mc = (from x in Funs.DB.FC_SESRelatedData select x.Main_Coordinator).ToList();
|
|
if (mc.Contains(user.UserId))
|
|
{
|
|
Model.Sys_Menu addSupMenu = (from x in Funs.DB.Sys_Menu where x.MenuId == "21FCD41E-2E96-4DE0-8F5F-BDD0C967134F" select x).First();
|
|
Model.Sys_Menu addMenu = (from x in Funs.DB.Sys_Menu where x.MenuId == Const.ContractorQualificationMenuId select x).First();
|
|
reMenuList.Add(addMenu);
|
|
}
|
|
}
|
|
}
|
|
reMenuList = reMenuList.Distinct().OrderBy(x => x.SortIndex).ToList();
|
|
return reMenuList;
|
|
}
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 抽取权限到项目
|
|
/// </summary>
|
|
/// <param name="projectId"></param>
|
|
//public static void ExtractionPower(string projectId)
|
|
//{
|
|
// /////增加项目上这个角色的菜单权限
|
|
// var rolePower = from x in Funs.DB.Sys_RolePower
|
|
// join y in Funs.DB.Sys_Menu on x.MenuId equals y.MenuId
|
|
// where (y.MenuModule == Const.System_3 || y.MenuModule == Const.System_5)
|
|
// select x;
|
|
|
|
// if (rolePower.Count() > 0)
|
|
// {
|
|
// foreach (var roleItem in rolePower)
|
|
// {
|
|
// var proRolePower = Funs.DB.Project_RolePower.FirstOrDefault(x => x.ProjectId == projectId && x.RoleId == roleItem.RoleId && x.MenuId == roleItem.MenuId);
|
|
// if (proRolePower == null)
|
|
// {
|
|
// Model.Project_RolePower newPower = new Model.Project_RolePower();
|
|
// newPower.RoleId = roleItem.RoleId;
|
|
// newPower.ProjectId =projectId;
|
|
// newPower.MenuId = roleItem.MenuId;
|
|
// BLL.Project_RolePowerService.SaveProject_RolePower(newPower);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// /////增加项目上这个角色的按钮权限
|
|
// var buttonPower = from x in Funs.DB.Sys_ButtonPower
|
|
// join y in Funs.DB.Sys_Menu on x.MenuId equals y.MenuId
|
|
// where (y.MenuModule == Const.System_3 || y.MenuModule == Const.System_5)
|
|
// select x;
|
|
|
|
// if (buttonPower.Count() > 0)
|
|
// {
|
|
// foreach (var buttonItem in buttonPower)
|
|
// {
|
|
// var proButtonPower = Funs.DB.Project_RoleButtonPower.FirstOrDefault(x => x.ProjectId == projectId && x.RoleId == buttonItem.RoleId
|
|
// && x.MenuId == buttonItem.MenuId && x.ButtonToMenuId == buttonItem.ButtonToMenuId);
|
|
// if (proButtonPower == null)
|
|
// {
|
|
// Model.Project_RoleButtonPower newRoleButtonPower = new Model.Project_RoleButtonPower();
|
|
// newRoleButtonPower.RoleId = buttonItem.RoleId;
|
|
// newRoleButtonPower.ProjectId = projectId;
|
|
// newRoleButtonPower.MenuId = buttonItem.MenuId;
|
|
// newRoleButtonPower.ButtonToMenuId = buttonItem.ButtonToMenuId;
|
|
// BLL.Project_RoleButtonPowerService.SaveProject_RoleButtonPower(newRoleButtonPower);
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
/// <summary>
|
|
/// Base64加密
|
|
/// </summary>
|
|
/// <param name="Message"></param>
|
|
/// <returns></returns>
|
|
public static string Base64Code(string Message)
|
|
{
|
|
byte[] bytes = Encoding.Default.GetBytes(Message);
|
|
return Convert.ToBase64String(bytes);
|
|
}
|
|
/// <summary>
|
|
/// Base64解密
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <returns></returns>
|
|
public static string Base64Decode(string message)
|
|
{
|
|
byte[] bytes = Convert.FromBase64String(message);
|
|
return Encoding.Default.GetString(bytes);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户菜单按钮权限
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="menuId"></param>
|
|
/// <returns></returns>
|
|
public static List<string> GetAllButtonList(string userId, string menuId)
|
|
{
|
|
Model.FCLDB db = Funs.DB;
|
|
List<string> buttonList = new List<string>();
|
|
List<Model.Sys_ButtonToMenu> buttons = new List<Model.Sys_ButtonToMenu>();
|
|
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)
|
|
{
|
|
//var menu =menuse.GetSysMenuByMenuId(menuId);
|
|
//if (menu != null && menu.MenuType == BLL.Const.Menu_Resource)
|
|
//{
|
|
// for (int p = buttons.Count - 1; p > -1; p--)
|
|
// {
|
|
// if (buttons[p].ButtonName == BLL.Const.BtnSaveUp || buttons[p].ButtonName == BLL.Const.BtnUploadResources || buttons[p].ButtonName == BLL.Const.BtnAuditing)
|
|
// {
|
|
// buttons.Remove(buttons[p]);
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
buttonList = buttons.Select(x => x.ButtonEnName).ToList();
|
|
}
|
|
|
|
return buttonList;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |