131 lines
4.1 KiB
C#
131 lines
4.1 KiB
C#
using NPOI.SS.Formula.Atp;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web.Security;
|
|
|
|
namespace BLL
|
|
{
|
|
public class Sys_ButtonPowerService
|
|
{
|
|
///// <summary>
|
|
///// 获取按钮权限集合
|
|
///// </summary>
|
|
///// <param name="roleId">角色ID</param>
|
|
///// <param name="menuId">菜单ID</param>
|
|
///// <returns>按钮集合</returns>
|
|
//public static string[] GetButtonPowerList(string roleId, string menuId)
|
|
//{
|
|
// Model.EProject db = Funs.DB;
|
|
// var q = from x in db.Sys_ButtonPower where x.RoleId == roleId && x.MenuId == menuId select x;
|
|
// if (q != null)
|
|
// {
|
|
// string[] button = new string[q.Count()];
|
|
// int i = 0;
|
|
// foreach (var b in q)
|
|
// {
|
|
// Model.ButtonToMenu btn = db.ButtonToMenu.FirstOrDefault(e => e.ButtonToMenuId == b.ButtonToMenuId);
|
|
// button[i] = btn.ButtonName;
|
|
// i++;
|
|
// }
|
|
|
|
// return button;
|
|
// }
|
|
|
|
// else
|
|
// {
|
|
// return null;
|
|
// }
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 删除权限
|
|
/// </summary>
|
|
/// <param name="roleId"></param>
|
|
public static void DeleteButtonPower(string roleId)
|
|
{
|
|
var bt = from x in Funs.DB.Sys_ButtonPower
|
|
join y in Funs.DB.Sys_Menu on x.MenuId equals y.MenuId
|
|
where x.RoleId == roleId
|
|
select x;
|
|
|
|
if (bt.Count() > 0)
|
|
{
|
|
Funs.DB.Sys_ButtonPower.DeleteAllOnSubmit(bt);
|
|
}
|
|
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加按钮权限
|
|
/// </summary>
|
|
/// <param name="power"></param>
|
|
public static void SaveButtonPower(Model.Sys_ButtonPower btn)
|
|
{
|
|
string newKeyID = SQLHelper.GetNewID(typeof(Model.Sys_ButtonPower));
|
|
Model.Sys_ButtonPower button = new Model.Sys_ButtonPower();
|
|
button.ButtonPowerID = newKeyID;
|
|
button.RoleId = btn.RoleId;
|
|
button.MenuId = btn.MenuId;
|
|
button.ButtonToMenuId = btn.ButtonToMenuId;
|
|
|
|
Funs.DB.Sys_ButtonPower.InsertOnSubmit(button);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
/// <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;
|
|
//}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据用户id获取有ViewAll按钮权限用户
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
public static Model.Sys_User GetButtonPowerByUserId(string userId)
|
|
{
|
|
var q = (from x in Funs.DB.Sys_User
|
|
join y in Funs.DB.Sys_Role on x.RoleId equals y.RoleId
|
|
join z in Funs.DB.Sys_ButtonPower on y.RoleId equals z.RoleId
|
|
join w in Funs.DB.Sys_ButtonToMenu on z.ButtonToMenuId equals w.ButtonToMenuId
|
|
where w.ButtonEnName == "ViewAll"
|
|
&& x.UserId == userId
|
|
select x).FirstOrDefault();
|
|
return q;
|
|
}
|
|
}
|
|
}
|