protected void Page_Load(object sender, EventArgs e) { if (!PageUtility.IsLogin) { Response.Redirect("~/logout.aspx"); return; } if (!IsPostBack) { var bll = new UserManagerBLL(); // ******************************************************************* // 检查id是否存在参数 UserInfo selectedUser = null; if (!string.IsNullOrEmpty(Request["id"])) { selectedUser = bll.GetUser(int.Parse(Request["id"])); // 未找到对象 if (selectedUser == null) { Response.Redirect("~/common/erroraccess.aspx"); } } // ******************************************************************* // 显示要修改的模块内容 bindOrg(); //显示构件数据 bindRoleList(bll); displayUser(PageUtility.User, selectedUser); } }
private UserInfo getUser(UserInfo loginedUser, UserManagerBLL BLL) { // 检查用户的输入情况 if (string.IsNullOrEmpty(txtUserName.Text.Trim()) || string.IsNullOrEmpty(txtAlias.Text.Trim())) { lblError.Text = "请输入用户账号和用户姓名!"; return(null); } if (!string.IsNullOrEmpty(txtEmail.Text.Trim()) && !ValidationUtility.IsValidEmail(txtEmail.Text.Trim())) { lblError.Text = "请输入有效的用户邮箱!"; return(null); } if (ddlOrg.SelectedItem == null || string.IsNullOrEmpty(ddlOrg.SelectedValue)) { lblError.Text = "请选择管理机构!"; return(null); } var ret = new UserInfo { ID = 0, EncryptedPassword = "", PasswordAnswer = string.Empty, PasswordQuestion = string.Empty, SessionIdentify = Guid.NewGuid().ToString(), IsSystem = false, IsAdmin = true, IsApproved = true, PopedomIDs = string.Empty, FailedPwdAttemptCount = 0, FailedPwdAttemptDate = DateTime.Now, FailedAnswerAttemptCount = 0, FailedAnswerAttemptDate = DateTime.Now, LastLoginDate = DateTime.Now, LastLockoutDate = DateTime.Now, LastActivityDate = DateTime.Now, LastPwdChangedDate = DateTime.Now, DisplayOrder = 100, CreatedByID = loginedUser.ID, CreatedByName = loginedUser.Alias, CreatedDate = DateTime.Now }; // 如果是修改,则获取要修改的对象 if (!string.IsNullOrEmpty(hdnEditingUserNo.Value.Trim())) { UserInfo existUser = BLL.GetUser(int.Parse(hdnEditingUserNo.Value.Trim())); if (existUser == null) { lblError.Text = "修改的对象未找到!请确认该对象是否被其它用户删除!"; return(null); } ret = existUser; } ret.UserName = txtUserName.Text.Trim(); ret.OrganizationId = Convert.ToInt32(ddlOrg.SelectedValue); ret.OrganizationName = ddlOrg.SelectedItem.Text; ret.Alias = txtAlias.Text.Trim(); ret.Email = txtEmail.Text.Trim(); ret.Description = txtDescription.Text.Trim(); ret.IsLockedOut = cbxIsLockout.Checked; // 加入会员的管理角色 var roleList = new List <RoleInfo>(); foreach (ListItem item in chklstRoleList.Items) { if (item.Selected) { ret.AddRole(int.Parse(item.Value.Trim())); } } ret.LastUpdByID = loginedUser.ID; ret.LastUpdByName = loginedUser.Alias; ret.LastUpdDate = DateTime.Now; return(ret); }