85 lines
2.4 KiB
C#
85 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using NOVA.DevFx.Security.Model;
|
|
using System.Data.SqlClient;
|
|
using NOVA.DevFx.Data.Utils;
|
|
using System.Data;
|
|
|
|
namespace NOVA.DevFx.Security.DataHandler
|
|
{
|
|
/// <summary>
|
|
/// 角色权限关联数据访问类
|
|
/// </summary>
|
|
public static class UserRoleHandler
|
|
{
|
|
|
|
/// <summary>
|
|
/// 将数据转换成实体类
|
|
/// </summary>
|
|
public static User_In_Role DataReaderToEntites(IDataReader dr)
|
|
{
|
|
User_In_Role model = new User_In_Role();
|
|
if (dr["id"].ToString() != "")
|
|
{
|
|
model.id = int.Parse(dr["id"].ToString());
|
|
}
|
|
if (dr["user_id"].ToString() != "")
|
|
{
|
|
model.user_id = int.Parse(dr["user_id"].ToString());
|
|
}
|
|
if (dr["role_id"].ToString() != "")
|
|
{
|
|
model.role_id = int.Parse(dr["role_id"].ToString());
|
|
}
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得数据列表
|
|
/// </summary>
|
|
public static List<User_In_Role> GetList(string strWhere)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select id,user_id,role_id ");
|
|
strSql.Append(" FROM s_user_in_role ");
|
|
if (strWhere.Trim() != "")
|
|
{
|
|
strSql.Append(" where " + strWhere);
|
|
}
|
|
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString());
|
|
|
|
List<User_In_Role> m_lst = new List<User_In_Role>();
|
|
while (read.Read())
|
|
{
|
|
User_In_Role item = DataReaderToEntites(read);
|
|
if (item != null)
|
|
{
|
|
m_lst.Add(item);
|
|
}
|
|
}
|
|
read.Close();
|
|
return m_lst;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据角色编号获取所有用户列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<User_In_Role> GetUserListByRoleID(int roleid)
|
|
{
|
|
return GetList(" (role_id=" + roleid.ToString() + ")");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据用户编号获取所有角色列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<User_In_Role> GetRoleListByUserID(int userid)
|
|
{
|
|
return GetList(" (user_id=" + userid.ToString() + ")");
|
|
}
|
|
|
|
}
|
|
}
|