Пример #1
0
        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);
            }

        }
Пример #2
0
   /// <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;
       
   }
Пример #3
0
        protected void btnSetUserFun_Click(object sender, EventArgs e)
        {
            List<ObjectRule> rules = new List<ObjectRule>(100);
            User user = null;
            SecurityObject secObj = null;

            Guid objId = new Guid(this.hiCurrentCataId.Value);
            secObj = new SecurityObject(objId, SecurityObjectType.Items);
            ArrayList opers = new ArrayList(100);

            foreach (GridViewRow row in userList.Rows)
            {
                Guid userId = new Guid(userList.DataKeys[row.RowIndex].Value.ToString());
                user = new User(userId);
                opers.Add(user);

                ObjectRule newRule;


                CheckBox chk = row.FindControl("funUpChk") as CheckBox;
                newRule = new ObjectRule(secObj, user, OperatorMethod.Write);
                rules.Add(newRule);
                if (chk.Checked)
                {
                    newRule.IsValidate = true;
                }
                else
                {
                    newRule.IsValidate = false;
                }

                CheckBox echk = row.FindControl("funEditChk") as CheckBox;
                newRule = new ObjectRule(secObj, user, OperatorMethod.Modify);
                rules.Add(newRule);
                if (echk.Checked)
                {
                    newRule.IsValidate = true;
                }
                else
                {
                    newRule.IsValidate = false;
                }

                CheckBox dchk = row.FindControl("funReadChk") as CheckBox;
                newRule = new ObjectRule(secObj, user, OperatorMethod.Deny);
                rules.Add(newRule);
                if (dchk.Checked)
                {
                    newRule.IsValidate = true;
                }
                else
                {
                    newRule.IsValidate = false;
                }

                CheckBox downChk = row.FindControl("funDownChk") as CheckBox;
                newRule = new ObjectRule(secObj, user, OperatorMethod.Download);
                rules.Add(newRule);
                newRule.IsValidate = downChk.Checked;

                //针对当前类的子类设置权限(子类应自动继承父类权限)
                DataTable childCatalog = Catalog.GetCatalogTableByParentId(objId);
                foreach (DataRow cata in childCatalog.Rows)
                {
                    SecurityObject cSecObj = new SecurityObject(new Guid(cata["catalogId"].ToString()),
                        SecurityObjectType.Items);

                    ObjectRule cOrUp = new ObjectRule(cSecObj, user, OperatorMethod.Write);
                    cOrUp.IsValidate = chk.Checked;


                    rules.Add(cOrUp);

                    ObjectRule cOrEdit = new ObjectRule(cSecObj, user, OperatorMethod.Modify);
                    cOrEdit.IsValidate = echk.Checked;

                    rules.Add(cOrEdit);


                    ObjectRule cOrDeny = new ObjectRule(cSecObj, user, OperatorMethod.Deny);
                    cOrDeny.IsValidate = dchk.Checked;
                    rules.Add(cOrDeny);


                    ObjectRule cOrDown = new ObjectRule(cSecObj, user, OperatorMethod.Download);
                    cOrDown.IsValidate = downChk.Checked;
                    rules.Add(cOrDown);

                    
                }

            }

            if (ObjectRule.SetRules(rules, secObj, opers))
            {
                ShowMessage("用户权限设置成功");
            }
            else
            {
                ShowMessage("用户权限设置失败");
            }
        }
Пример #4
0
        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();
        }
Пример #5
0
        //设定权限
        protected void btnSetRoleFun_Click(object sender, EventArgs e)
        {
            List<ObjectRule> rules = new List<ObjectRule>(100);
            Role role = null;
            SecurityObject secObj = null;

            Guid objId = new Guid(this.hiCurrentCataId.Value);
            secObj = new SecurityObject(objId, SecurityObjectType.Items);
            ArrayList opers = new ArrayList(100);

            foreach (GridViewRow row in roleGroupList.Rows)
            {
                Guid roleId = new Guid(roleGroupList.DataKeys[row.RowIndex].Value.ToString());
                role = new Role();
                role.RoleId = roleId;
                opers.Add(role);

                ObjectRule newRule;

                CheckBox chkRead = row.FindControl("funReadChk") as CheckBox;
                newRule = new ObjectRule(secObj, role, OperatorMethod.Deny);
                rules.Add(newRule);
                newRule.IsValidate = chkRead.Checked;



                CheckBox chkWrite = row.FindControl("funUpChk") as CheckBox;
                newRule = new ObjectRule(secObj, role, OperatorMethod.Write);
                rules.Add(newRule);
                newRule.IsValidate = chkWrite.Checked;


                CheckBox chkEdit = row.FindControl("funEditChk") as CheckBox;
                newRule = new ObjectRule(secObj, role, OperatorMethod.Modify);
                rules.Add(newRule);
                newRule.IsValidate = chkEdit.Checked;

                CheckBox chkDownload = row.FindControl("funDownChk") as CheckBox;
                newRule = new ObjectRule(secObj, role, OperatorMethod.Download);
                rules.Add(newRule);
                newRule.IsValidate = chkDownload.Checked;

                //针对当前类的子类设置权限(子类应自动继承父类权限)
                DataTable childCatalog = Catalog.GetCatalogTableByParentId(objId);
                foreach (DataRow cata in childCatalog.Rows)
                {
                    SecurityObject cSecObj = new SecurityObject(new Guid(cata["catalogId"].ToString()),
                        SecurityObjectType.Items);

                    ObjectRule cOrRead = new ObjectRule(cSecObj, role, OperatorMethod.Deny);
                    cOrRead.IsValidate = chkRead.Checked;
                    ObjectRule cOrWrite = new ObjectRule(cSecObj, role, OperatorMethod.Write);
                    cOrWrite.IsValidate = chkWrite.Checked;
                    ObjectRule cOrEdit = new ObjectRule(cSecObj, role, OperatorMethod.Modify);
                    cOrEdit.IsValidate = chkEdit.Checked;
                    ObjectRule cOrDown = new ObjectRule(cSecObj, role, OperatorMethod.Download);
                    cOrDown.IsValidate = chkDownload.Checked;

                    rules.Add(cOrRead);
                    rules.Add(cOrWrite);
                    rules.Add(cOrEdit);
                    rules.Add(cOrDown);
                }
              
            }

            if (ObjectRule.SetRules(rules, secObj, opers))
            {
                ShowMessage("角色权限设置成功");
            }
            else
            {
                ShowMessage("角色权限设置失败");
            }
        }
Пример #6
0
        /// <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();

        }