using HighWayIot.Repository.service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Winform.Business
{
public class RoleBusiness
{
///
/// 当前登录人的姓名
///
public static string LoginUserName = string.Empty;
///
/// 用户数据业务实例
///
SysUserInfoService _sysUserInfoService = SysUserInfoService.Instance;
///
/// 角色数据业务实例
///
SysUserRoleService _sysUserRoleService = SysUserRoleService.Instance;
///
/// XML读取类
///
XmlUtil xmlUtil = XmlUtil.Instance;
///
/// 页面权限偏移量对应表
///
List RoleConfigs;
public RoleBusiness()
{
RoleConfigs = xmlUtil.ConfigReader();
}
///
/// 判断现在登录的用户是否有指定页面的访问权限
///
/// 页面名称
/// 有权限返回true,没权限返回false
public bool PageIsAccess(string pageName)
{
RoleConfig roleConfig = RoleConfigs.Where(x => x.PageName == pageName).FirstOrDefault();
//先判断页面是否配置过,没配置过的都默认有权限
if (roleConfig == null)
{
return true;
}
//获取当前用户的权限字符串
string roleString = _sysUserRoleService.GetRoleInfos(
_sysUserInfoService.GetUserInfoByUserName(LoginUserName).First().UserRole
).First().RoleSet;
//转换为Char数组
char[] chars = roleString.ToCharArray();
//返回权限结果
return chars[roleConfig.RoleIndex] == '1';
}
}
}