예제 #1
0
        /// <summary>
        /// 绑定数据。
        /// 作者:董帅 创建时间:2012-8-27 17:24:18
        /// </summary>
        private void bindData()
        {
            try
            {
                //获取配置文件路径。
                string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName;

                //创建数据库操作对象。
                RoleOperater roleOper = RoleOperater.createRoleOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey);
                if (roleOper != null)
                {
                    List <UserRoleInfo> roles = roleOper.getChouseRoles(Convert.ToInt32(this.hidUserId.Value));
                    if (roles != null)
                    {
                        this.rolesRepeater.DataSource = roles;
                        this.rolesRepeater.DataBind();
                    }
                    else
                    {
                        YMessageBox.show(this, "查询出错!错误信息:[" + roleOper.errorMessage + "]");
                    }
                }
            }
            catch (Exception ex)
            {
                YMessageBox.show(this, "查询出错!错误信息:[" + ex.Message + "]");
            }
        }
예제 #2
0
        protected void butDeleteRoles_Click(object sender, EventArgs e)
        {
            try
            {
                string[] ids = Request["chkItem"].Split(',');

                if (ids.Length > 0)
                {
                    //获取配置文件路径。
                    string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName;

                    //创建数据库操作对象。
                    RoleOperater roleOper = RoleOperater.createRoleOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey);
                    if (roleOper != null)
                    {
                        //删除数据
                        int[] intIds = new int[ids.Length];
                        for (int i = 0; i < intIds.Length; i++)
                        {
                            intIds[i] = Convert.ToInt32(ids[i]);
                        }

                        if (roleOper.deleteRoles(intIds))
                        {
                            this.Response.Redirect("role_list.aspx");
                            //YMessageBox.showAndResponseScript(this, "删除数据成功!", "", "window.parent.menuButtonOnClick('角色管理','icon-role','sys/role/role_list.aspx')");
                        }
                        else
                        {
                            YMessageBox.show(this, "删除数据失败!请确认是否有用户设置了该角色!");
                        }
                    }
                    else
                    {
                        YMessageBox.show(this, "获取数据库实例失败!");
                    }
                }
                else
                {
                    YMessageBox.show(this, "没有选择要删除的角色!");
                }
            }
            catch (Exception ex)
            {
                YMessageBox.show(this, "系统运行异常!异常信息[" + ex.Message + "]");
            }
        }
예제 #3
0
        protected void butChouse_Click(object sender, EventArgs e)
        {
            try
            {
                string   strIds = Request["chkItem"];
                string[] ids    = new string[0];
                if (!string.IsNullOrEmpty(strIds))
                {
                    ids = strIds.Split(',');
                }

                //获取配置文件路径。
                string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName;

                //创建数据库操作对象。
                RoleOperater roleOper = RoleOperater.createRoleOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey);
                if (roleOper != null)
                {
                    //删除数据
                    int[] intIds = new int[ids.Length];
                    for (int i = 0; i < intIds.Length; i++)
                    {
                        intIds[i] = Convert.ToInt32(ids[i]);
                    }

                    if (roleOper.chouseRoleMenus(Convert.ToInt32(this.hidRoleId.Value), intIds))
                    {
                        YMessageBox.showAndResponseScript(this, "选择菜单成功!", "", "window.parent.menuButtonOnClick('角色管理','icon-role','sys/role/role_list.aspx');window.parent.closePopupsWindow('#popups');");
                    }
                    else
                    {
                        YMessageBox.show(this, "选择菜单失败!错误信息[" + roleOper.errorMessage + "]");
                    }
                }
                else
                {
                    YMessageBox.show(this, "获取数据库实例失败!");
                }
            }
            catch (Exception ex)
            {
                YMessageBox.show(this, "系统运行异常!异常信息[" + ex.Message + "]");
            }
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //获取菜单
                try
                {
                    //获取id,没有id表示新增,否则为修改
                    string roleId = Request.QueryString["id"];
                    if (!string.IsNullOrEmpty(roleId))
                    {
                        this.hidRoleId.Value = roleId;
                    }
                    //获取配置文件路径。
                    string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName;

                    //获取数据库实例。
                    YDataBase orgDb = YDataBaseConfigFile.createDataBase(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey);

                    if (orgDb != null)
                    {
                        RoleOperater roleOper = new RoleOperater();
                        roleOper.roleDataBase = orgDb;

                        List <RoleMenuInfo> menus = roleOper.getChouseMenus(Convert.ToInt32(this.hidRoleId.Value));
                        this.menuGroup.DataSource = menus;
                        this.menuGroup.DataBind();
                    }
                    else
                    {
                        YMessageBox.show(this, "获取数据库实例失败!");
                    }
                }
                catch (Exception ex)
                {
                    YMessageBox.showAndRedirect(this, "系统运行异常!异常信息[" + ex.Message + "]", "sys/login.aspx");
                }
            }
        }
예제 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                try
                {
                    //获取id,没有id表示新增,否则为修改
                    string roleId = Request.QueryString["id"];
                    if (!string.IsNullOrEmpty(roleId))
                    {
                        this.hidRoleId.Value = roleId;
                        //获取配置文件路径。
                        string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName;

                        //创建数据库操作对象。
                        RoleOperater roleOper = RoleOperater.createRoleOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey);
                        if (roleOper != null)
                        {
                            RoleInfo role = roleOper.getRole(Convert.ToInt32(roleId));
                            if (role != null)
                            {
                                this.txtRoleName.Value    = role.name;
                                this.txtRoleExplain.Value = role.explain;
                            }
                        }
                        else
                        {
                            YMessageBox.show(this, "创建数据库对象失败!");
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    YMessageBox.show(this, "错误信息:[" + ex.Message + "]");
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 保存菜单。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butSave_Click(object sender, EventArgs e)
        {
            try
            {
                //创建角色对象
                RoleInfo role = new RoleInfo();

                role.name = this.txtRoleName.Value;
                if (string.IsNullOrEmpty(role.name) || role.name.Length > 20)
                {
                    YMessageBox.show(this, "角色名称不合法!");
                    return;
                }

                role.explain = this.txtRoleExplain.Value;
                if (role.explain.Length > 50)
                {
                    YMessageBox.show(this, "角色说明不合法!");
                    return;
                }

                //获取配置文件路径。
                string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName;

                //创建数据库操作对象。
                RoleOperater roleOper = RoleOperater.createRoleOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey);
                if (roleOper != null)
                {
                    if (string.IsNullOrEmpty(this.hidRoleId.Value))
                    {
                        //新增
                        int retId = roleOper.createNewRole(role);
                        if (retId > 0)
                        {
                            YMessageBox.showAndResponseScript(this, "保存成功!", "", "window.parent.menuButtonOnClick('角色管理','icon-role','sys/role/role_list.aspx');window.parent.closePopupsWindow('#popups');");
                        }
                        else
                        {
                            YMessageBox.show(this, "创建角色失败!错误信息:[" + roleOper.errorMessage + "]");
                            return;
                        }
                    }
                    else
                    {
                        //修改
                        role.id = Convert.ToInt32(this.hidRoleId.Value);
                        bool bRet = roleOper.changeRole(role);
                        if (bRet)
                        {
                            YMessageBox.showAndResponseScript(this, "保存成功!", "", "window.parent.menuButtonOnClick('角色管理','icon-role','sys/role/role_list.aspx');window.parent.closePopupsWindow('#popups');");
                        }
                        else
                        {
                            YMessageBox.show(this, "修改角色失败!错误信息:[" + roleOper.errorMessage + "]");
                            return;
                        }
                    }
                }
                else
                {
                    YMessageBox.show(this, "创建数据库对象失败!");
                    return;
                }
            }
            catch (Exception ex)
            {
                YMessageBox.show(this, "保存出错!错误信息:[" + ex.Message + "]");
            }
        }
예제 #7
0
        protected void Application_AcquireRequestState(object sender, EventArgs e)
        {
            string reqFile = Request.Path.ToString();

            //判断请求是否在background里。
            if ("/" != Request.ApplicationPath.ToString())
            {
                reqFile = reqFile.Replace(Request.ApplicationPath.ToString(), "");
            }

            if (reqFile.IndexOf("/background") == 0 && reqFile.IndexOf("/background/sys/login.aspx") != 0)
            {
                string   strNoFilterFiles = System.Configuration.ConfigurationManager.AppSettings["noFilterFiles"].ToString();
                string[] noFilterFiles    = null;
                if (!string.IsNullOrEmpty(strNoFilterFiles))
                {
                    noFilterFiles = strNoFilterFiles.Split(',');
                }

                if (noFilterFiles != null && noFilterFiles.Length > 0)
                {
                    //判断请求文件是否不在过滤范围之内。
                    string extName = reqFile.Substring(reqFile.LastIndexOf("."));
                    for (int i = 0; i < noFilterFiles.Length; i++)
                    {
                        if (extName == noFilterFiles[i])
                        {
                            return;
                        }
                    }
                }

                HttpApplication app  = (HttpApplication)sender;
                UserInfo        user = (UserInfo)app.Session["UserInfo"];
                if (null != user)
                {
                    if (user.id == 1)
                    {
                        return;
                    }



                    //查询页面是否与菜单关联。
                    string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName;

                    MenuOperater oper = MenuOperater.createMenuOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey);
                    if (oper != null)
                    {
                        if (oper.pageExists(reqFile))
                        {
                            //页面关联,需要进行权限验证。
                            RoleOperater roleOper = RoleOperater.createRoleOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey);
                            if (roleOper != null)
                            {
                                if (!roleOper.pageAllowRequest(user.id, reqFile))
                                {
                                    //页面不允许访问。
                                    Response.Redirect("~/background/sys/stop.aspx?waringText=你正试图访问未经授权的页面!", true);
                                }
                            }
                            else
                            {
                                //访问权限数据库初始化出错。
                                Response.Redirect("~/background/sys/stop.aspx?waringText=访问权限数据库初始失败!", true);
                            }
                        }
                    }
                    else
                    {
                        //页面数据库初始化失败。
                        Response.Redirect("~/background/sys/stop.aspx?waringText=页面关联数据库初始失败!", true);
                    }
                }
                else
                {
                    //登陆超时。
                    //Response.Write("用户登陆超时!");
                    Response.Redirect("~/background/sys/login.aspx", true);
                }
            }
        }