コード例 #1
0
        protected void btAdd_Click(object sender, EventArgs e)
        {
            String RoleResName = Request.QueryString["RoleResName"].ToString();
            int    RoleID      = int.Parse(Request.QueryString["RoleID"].ToString());

            //若原来没有则新增
            //若原来已分配资源则更新
            int             ResID            = int.Parse(this.DropDownRes.SelectedValue.ToString());
            RoleResourceBLL _RoleResourceBLL = new RoleResourceBLL();
            RoleResource    _RoleResource    = new RoleResource();

            _RoleResource.RoleID     = RoleID;
            _RoleResource.ResourceID = ResID;
            bool IsTrue = false;

            if ("".Equals(RoleResName))   //原来没有,新增
            {
                if (_RoleResourceBLL.AddRoleResource(_RoleResource))
                {
                    IsTrue = true;
                }
            }
            else     //原来有,更新
            {
                if (_RoleResourceBLL.UpdateRoleRes(RoleID, ResID))
                {
                    IsTrue = true;
                }
            }

            if (IsTrue)
            {
                Response.Write("<script language='javascript'>");
                Response.Write("alert('更新成功');");
                Response.Write("document.location.href='RoleResList.aspx';");
                Response.Write("</script>");
            }
            else
            {
                Response.Write("<script language='javascript'>");
                Response.Write("alert('更新失败');");
                Response.Write("</script>");
            }
        }
コード例 #2
0
        //根据角色ID删除角色信息
        protected void deleteThis()
        {
            try
            {
                Array delWitch = rqid.Split('|');
                bool  isTrue   = false;
                for (int i = 0; i < delWitch.Length - 1; i++)
                {
                    int delid = Convert.ToInt32(delWitch.GetValue(i));

                    RoleBLL         _RoleBLL         = new RoleBLL();
                    AdminRoleBLL    _AdminRoleBLL    = new AdminRoleBLL();
                    RoleResourceBLL _RoleResourceBLL = new RoleResourceBLL();


                    if (_RoleBLL.DeleteRole(delid))
                    {
                        isTrue = true;
                    }
                    else
                    {
                        isTrue = false;
                    }

                    //判断管理员角色表中还有该角色没
                    int AdminRoleCount = _AdminRoleBLL.GetCountByRoleID(delid);

                    if (AdminRoleCount > 0)
                    {
                        if (_AdminRoleBLL.DeleteAdminRoleByRoleID(delid))
                        {
                            isTrue = true;
                        }
                        else
                        {
                            isTrue = false;
                        }
                    }

                    //判断角色资源表中还有该角色没
                    int RoleResourceCount = _RoleResourceBLL.GetRoleResourceCountByRoleID(delid);
                    if (AdminRoleCount > 0)
                    {
                        if (_RoleResourceBLL.DeleteRoleAllResource(delid))
                        {
                            isTrue = true;
                        }
                        else
                        {
                            isTrue = false;
                        }
                    }
                    if (isTrue == false)
                    {
                        break;
                    }
                }
                if (!(isTrue == false))
                {
                    Response.Write("<script language='javascript'>");
                    Response.Write("alert('删除成功!');");
                    Response.Write("document.location.href='RoleList.aspx';");
                    Response.Write("</script>");
                }
                else
                {
                    Response.Write("<script language='javascript'>");
                    Response.Write("alert('删除失败!');");
                    Response.Write("document.location.href='RoleList.aspx';");
                    Response.Write("</script>");
                }
            }
            catch
            {
                Response.Write("<script language='javascript'>");
                Response.Write("alert('删除失败!');");
                Response.Write("document.location.href='RoleList.aspx';");
                Response.Write("</script>");
            }
        }