/// <summary> /// 根据RoleId查找出所有拥有该角色的用户 /// </summary> /// <param name="RoleId"></param> /// <returns></returns> public DataSet GetUserInfoByRoleID(int RoleId) { LabMS.BLL.UserRole BUR = new LabMS.BLL.UserRole(); List<LabMS.Model.UserRole> list = new List<LabMS.Model.UserRole>(); string str = "RoleID=" + RoleId; list = BUR.GetModelList(str); LabMS.BLL.UserTable BUserTable = new LabMS.BLL.UserTable(); DataSet ds = new DataSet(); int UserID; string strsql = ""; if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { UserID = int.Parse(list[i].UserID.Value.ToString()); if (i == list.Count - 1) { strsql += " UserID=" + UserID; } else { strsql += " UserID=" + UserID + " or "; } } } else { throw(new Exception("2"));//没有用户拥有该角色 } ds=BUserTable.GetList(strsql); return ds; }
/// <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> /// 根据userid,roleid从userrole表中删除对应记录 /// </summary> /// <param name="RoleID"></param> /// <param name="UserID"></param> public void DeleteByRoleIDUserID(int RoleID, int UserID) { string str = " RoleID=" + RoleID + " and UserID="+UserID+""; LabMS.BLL.UserRole BUR = new LabMS.BLL.UserRole(); int ID = BUR.GetModelList(str)[0].ID; BUR.Delete(ID); }
public static List<LabMS.Model.Function> GetManaFunctionByUserID(string strUserID) { List<LabMS.Model.UserRole> listuRole = new List<LabMS.Model.UserRole>(); LabMS.BLL.UserRole buRole = new LabMS.BLL.UserRole(); List<LabMS.Model.RoleFucntion> listRoleF = new List<LabMS.Model.RoleFucntion>(); LabMS.BLL.RoleFucntion bRoleF = new LabMS.BLL.RoleFucntion(); listuRole = buRole.GetModelList("UserID = " + strUserID); string strWhere = " 1<>1 "; foreach (LabMS.Model.UserRole ur in listuRole) { strWhere += " or RoleID = " + ur.RoleID.Value.ToString(); } listRoleF = bRoleF.GetModelList(strWhere); List<LabMS.Model.Function> listFunction = new List<LabMS.Model.Function>(); LabMS.BLL.Function bFunction = new LabMS.BLL.Function(); strWhere = " 1<>1 "; foreach (LabMS.Model.RoleFucntion rf in listRoleF) { strWhere += " or Code = '" + rf.FCode.ToString()+"'"; } listFunction = bFunction.GetModelList(strWhere); return listFunction; }
/// <summary> /// 添加角色 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddRoleForUser_Click(object sender, EventArgs e) { LabMS.BLL.UserRole BUR = new LabMS.BLL.UserRole(); LabMS.Model.UserRole MUR = new LabMS.Model.UserRole(); int UserID = int.Parse(Request.QueryString["UserID"].ToString()); CheckBox chk; bool success = false; for (int i = 0; i < gvRole.Rows.Count; i++) { chk = (CheckBox)gvRole.Rows[i].FindControl("chk"); if (chk.Checked) { int RoleID =int.Parse(gvRole.DataKeys[i].Value.ToString()); MUR.RoleID = RoleID; MUR.UserID = UserID; BUR.Add(MUR); success = true; } } if (success == true) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('增加角色信息成功!');window.opener.location.href=window.opener.location.href;self.close();</script>"); } else { Common.JShelper.JSAlert(this.Page, "", "增加角色信息失败!"); } }
/// <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; }