示例#1
0
        private void AddAdmin()
        {
            UserInfo usersByUserName = Users.GetUsersByUserName(this.TxtUserName.Text.Trim());

            if (usersByUserName.IsNull)
            {
                AdminPage.WriteErrMsg("此前台用户名不存在!");
            }
            AdministratorInfo adminInfo = new AdministratorInfo();

            adminInfo.AdminName            = this.TxtAdminName.Text.Trim();
            adminInfo.UserName             = this.TxtUserName.Text.Trim();
            adminInfo.IsLock               = this.ChkIsLock.Checked;
            adminInfo.EnableModifyPassword = this.ChkEnableModifyPassword.Checked;
            if (string.IsNullOrEmpty(this.TxtPassword.Text.Trim()))
            {
                AdminPage.WriteErrMsg("管理员密码不能为空");
            }
            else
            {
                adminInfo.AdminPassword = StringHelper.MD5(this.TxtPassword.Text);
            }
            adminInfo.EnableMultiLogOn = this.ChkEnableMultiLogin.Checked;
            if (Administrators.IsExist(adminInfo.AdminName))
            {
                AdminPage.WriteErrMsg("已经存在同样的管理员名!");
            }
            if (!Administrators.GetAdministratorByUserName(usersByUserName.UserName).IsNull)
            {
                AdminPage.WriteErrMsg("此前台用户已经被添加为管理员了!");
            }
            if (Administrators.Add(adminInfo))
            {
                if (this.RadPurview1.Checked)
                {
                    RoleMembers.AddMemberToRoles(adminInfo.AdminId, "0");
                }
                else
                {
                    RoleMembers.AddMemberToRoles(adminInfo.AdminId, this.HdnBelongToRole.Value);
                }
                AdminPage.WriteSuccessMsg("添加管理员成功!", "AdministratorManage.aspx");
            }
            else
            {
                AdminPage.WriteErrMsg("添加管理员失败!");
            }
        }