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 { /// /// 角色权限关联数据访问类 /// public static class UserRoleHandler { /// /// 将数据转换成实体类 /// 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; } /// /// 获得数据列表 /// public static List 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 m_lst = new List(); while (read.Read()) { User_In_Role item = DataReaderToEntites(read); if (item != null) { m_lst.Add(item); } } read.Close(); return m_lst; } /// /// 根据角色编号获取所有用户列表 /// /// public static List GetUserListByRoleID(int roleid) { return GetList(" (role_id=" + roleid.ToString() + ")"); } /// /// 根据用户编号获取所有角色列表 /// /// public static List GetRoleListByUserID(int userid) { return GetList(" (user_id=" + userid.ToString() + ")"); } } }