protected void btnSearchUser_Click(object sender, EventArgs e) { QJVRMS.Business.Group userGroup = new QJVRMS.Business.Group(CurrentGroupId); DataTable dt = userGroup.SelectUsers(this.txtloginName.Text.Trim(), this.txtUserName.Text.Trim()); Hashtable userRules = new Hashtable(); Dictionary <int, string> methodDict = WebUI.UIBiz.CommonInfo.GetMethodDict(); foreach (DataRow row in dt.Rows) { ISecurityObject securityObj = new SecurityObject(new Guid(this.hiCurrentCataId.Value), SecurityObjectType.Items); List <ObjectRule> rules = new List <ObjectRule>(); User user = new User(new Guid(row["userId"].ToString())); foreach (KeyValuePair <int, string> methodEntry in methodDict) { OperatorMethod method = (OperatorMethod)((int)methodEntry.Key); ObjectRule rule = new ObjectRule(securityObj, user, method); rules.Add(rule); } userRules.Add(user, rules); ObjectRule.CheckRules(rules); } foreach (KeyValuePair <int, string> methodEntry in methodDict) { string mIndex = methodEntry.Key.ToString(); dt.Columns.Add(mIndex, typeof(bool)); } foreach (DictionaryEntry entry in userRules) { User user = entry.Key as User; List <ObjectRule> rules = entry.Value as List <ObjectRule>; DataRow[] users = dt.Select("userId='" + user.UserId.ToString() + "'"); foreach (IRule rule in rules) { string methodKey = ((int)rule.Method).ToString(); users[0][methodKey] = rule.IsValidate; } } this.userList.DataSource = dt; this.userList.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { PageBar1.PageSize = NowPageCount(); // UIBiz.CommonInfo.PageCount; PageBar2.PageSize = NowPageCount(); //UIBiz.CommonInfo.PageCount; isChangePageSize = this.Search_ReSetPageSize1.isChangePageSize; string showCata = Request.QueryString["showCata"] == null ? "" : Request.QueryString["showCata"]; this.catalogID = Request.QueryString["CatalogID"] == null ? "00000000-0000-0000-0000-000000000000" : Request.QueryString["CatalogID"].ToString(); //分类检索 if (showCata == "1") { List <ObjectRule> rules = new List <ObjectRule>(1); ISecurityObject securityObj = new SecurityObject(new Guid(this.catalogID), SecurityObjectType.Items); ObjectRule or = new ObjectRule(securityObj, new User(CurrentUser.UserId), OperatorMethod.Deny); rules.Add(or); ObjectRule.CheckRules(rules); // if (!Catalog.GetCataRight(CurrentUser.UserId, new Guid(this.catalogID))) if (rules[0].IsValidate) { ShowMessage("您没有权限浏览此分类!"); Response.Redirect(FormsAuthentication.DefaultUrl, true); } // this.cataNav.Visible = true; this.BindCataNav(); } //关键字或高级搜索 else { this.keyword = Request.QueryString["keyword"] == null ? "" : Request.QueryString["keyword"].ToString(); this.keyword = Server.UrlDecode(this.keyword); this.beginDate = Request.QueryString["BeginDate"].ToString(); //上传时间起始日期 this.endDate = Request.QueryString["EndDate"].ToString(); //上传时间结束日期 // this.cataNav.Visible = false; ; } if (isChangePageSize == "1") { this.Search_ReSetPageSize1.isChangePageSize = string.Empty; _curpage = 0; } if (!Page.IsPostBack || isChangePageSize == "1") { BindData(PageBar1.PageSize, _curpage); } }
/// <summary> /// 判断某个用户对某个资源是否具有某个操作权限 /// </summary> /// <param name="userId"></param> /// <param name="resourceId"></param> /// <returns></returns> public bool IsUserResource(Guid userId, Guid resourceId, int method) { bool _b = false; DataSet ds = this.GetResourceCatalogByItemId(resourceId.ToString()); int icount = ds.Tables[0].Rows.Count; List <ObjectRule> rules = new List <ObjectRule>(icount); foreach (DataRow dr in ds.Tables[0].Rows) { ISecurityObject securityObj = new SecurityObject(new Guid(dr["CatalogId"].ToString()), SecurityObjectType.Items); ObjectRule or = new ObjectRule(securityObj, new User(userId), (OperatorMethod)method); rules.Add(or); } ObjectRule.CheckRules(rules); foreach (ObjectRule obj in rules) { _b = _b || obj.IsValidate; } return(_b); }
/// <summary> /// 绑定用户组定义功能 /// </summary> void BindRoleControlList() { Dictionary <int, string> methodDict = WebUI.UIBiz.CommonInfo.GetMethodDict(); //注意修改 当为superadmin时 RoleCollection roles = Role.GetRoleCollection(CurrentGroupId); Hashtable roleRules = new Hashtable(); foreach (Role role in roles) { ISecurityObject securityObj = new SecurityObject(new Guid(this.hiCurrentCataId.Value), SecurityObjectType.Items); List <ObjectRule> rules = new List <ObjectRule>(); foreach (KeyValuePair <int, string> methodEntry in methodDict) { OperatorMethod method = (OperatorMethod)((int)methodEntry.Key); ObjectRule rule = new ObjectRule(securityObj, role, method); rules.Add(rule); } roleRules.Add(role, rules); ObjectRule.CheckRules(rules); } DataTable roleMethod = new DataTable(); DataColumn dc = new DataColumn("roleName"); roleMethod.Columns.Add(dc); dc = new DataColumn("roleId"); roleMethod.Columns.Add(dc); foreach (KeyValuePair <int, string> methodEntry in methodDict) { string mIndex = methodEntry.Key.ToString(); roleMethod.Columns.Add(mIndex, typeof(bool)); } //foreach (KeyValuePair<int, string> methodEntry in methodDict) //{ // TemplateField field = new TemplateField(); // // CheckBoxField field = new CheckBoxField(); // WebUI.UIBiz.GridViewTempla template = new WebUI.UIBiz.GridViewTempla(ListItemType.Item, string.Empty); // field.HeaderText = methodEntry.Value.ToString(); // // field.DataField = methodEntry.Key.ToString(); // // field.ReadOnly = false; // field.ItemTemplate = template; // roleGroupList.Columns.Add(field); // DataColumn methodDc = new DataColumn(methodEntry.Key.ToString()); // roleMethod.Columns.Add(methodDc); //} foreach (DictionaryEntry entry in roleRules) { Role role = entry.Key as Role; List <ObjectRule> rules = entry.Value as List <ObjectRule>; DataRow dr = roleMethod.NewRow(); dr["roleName"] = role.RoleName; dr["roleId"] = role.RoleId.ToString(); foreach (IRule rule in rules) { string methodKey = ((int)rule.Method).ToString(); dr[methodKey] = rule.IsValidate; } roleMethod.Rows.Add(dr); } DataView dv = roleMethod.DefaultView; dv.Sort = "RoleName"; roleGroupList.DataSource = dv; roleGroupList.DataBind(); // TemplateColumn roleColumn = new TemplateColumn(); }