/// <summary> /// 根据UserID获得没有被分配过的角色 /// </summary> /// <param name="UserID"></param> /// <returns></returns> public List<LabMS.Model.RoleTable> GetRoleTableExpect(int UserID) { LabMS.BLL.UserRole BUR = new LabMS.BLL.UserRole(); List<LabMS.Model.UserRole> list = new List<LabMS.Model.UserRole>(); string str = "UserID="+UserID; list = BUR.GetModelList(str); LabMS.BLL.RoleTable BRT = new LabMS.BLL.RoleTable(); List<LabMS.Model.RoleTable> listRoleT = new List<LabMS.Model.RoleTable>(); string strsql = ""; int RoleID; if (list.Count == 0)//没有分配角色 { strsql = "1=1"; } else { for (int i = 0; i < list.Count; i++) { RoleID =int.Parse(list[i].RoleID.Value.ToString()); if (i == list.Count - 1) { strsql += " RoleID!=" + RoleID; } else { strsql += " RoleID!="+RoleID+" and "; } } } listRoleT = BRT.GetModelList(strsql); return listRoleT; }
/// <summary> /// 根据RoleId取得角色名称RoleName /// </summary> /// <param name="RoleId"></param> /// <returns></returns> public string GetRoleNameByRoleID(int RoleId) { string str = "RoleId="+RoleId; LabMS.BLL.RoleTable BRT = new LabMS.BLL.RoleTable(); string name = BRT.GetModelList(str)[0].RoleName; return name; }
/// <summary> /// 根据RoleName找到RoleID的值 /// </summary> /// <param name="RoleName"></param> /// <returns></returns> public int GetRoleIDByRoleName(string RoleName) { int RoleID; string str = "RoleName='"+RoleName+"'"; LabMS.BLL.RoleTable BRt = new LabMS.BLL.RoleTable(); RoleID=int.Parse(BRt.GetModelList(str)[0].RoleId.ToString()); return RoleID; }
/// <summary> /// 根据UserID找出已经赋给此用户的角色信息 /// </summary> /// <param name="UserID"></param> /// <returns></returns> public List<LabMS.Model.RoleTable> GetUserRoleByUserID(int UserID) { LabMS.BLL.UserRole BUR = new LabMS.BLL.UserRole(); List<LabMS.Model.UserRole> listMUR = new List<LabMS.Model.UserRole>(); #region 用户是否存在 string str1 = "UserID="+UserID; LabMS.BLL.UserTable BUT = new LabMS.BLL.UserTable(); List<LabMS.Model.UserTable> list = new List<LabMS.Model.UserTable>(); list = BUT.GetModelList(str1); if (list.Count == 0) { throw(new Exception("1"));//用户不存在 } #endregion #region 用户是否有角色 string str = "UserID="+UserID; listMUR=BUR.GetModelList(str);//在UserRole表中找出RoleID if (listMUR.Count == 0) { throw(new Exception("2"));//用户没有对应角色 } #endregion LabMS.BLL.RoleTable BRT = new LabMS.BLL.RoleTable(); List<LabMS.Model.RoleTable> listMRT = new List<LabMS.Model.RoleTable>(); int RoleID; string sqlstr = ""; for (int i = 0; i < listMUR.Count; i++) { RoleID =int.Parse(listMUR[i].RoleID.Value.ToString()); if (i == listMUR.Count - 1) { sqlstr += " RoleId=" + RoleID; } else { sqlstr += " RoleId="+RoleID+" or "; } } listMRT = BRT.GetModelList(sqlstr); return listMRT; }
/// <summary> /// 搜索 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void search_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbRoleNameSerach.Text.Trim())) { Common.JShelper.JSAlert(this.Page, "", "请输入要搜索的角色名称!"); tbRoleNameSerach.Focus(); } else { LabMS.BLL.RoleTable BRT = new LabMS.BLL.RoleTable(); string str = "RoleName like '%" + tbRoleNameSerach.Text.Trim() + "%'"; gvRole.DataSource = BRT.GetModelList(str); gvRole.DataBind(); } }