protected void btnRegister_Click(object sender, EventArgs e) { MemberDAO dao = new MemberDAO(); string username = txtUsername.Text.Trim(); if (dao.IsUsernameExist(username)) { string message = "Username already exists.\\nPlease choose a different username."; ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true); this.txtUsername.ForeColor = System.Drawing.Color.Red; this.txtUsername.Focus(); return; } string password = txtPass.Text.Trim(); string phone = txtPhone.Text.Trim(); string firstname = txtFirstName.Text.Trim(); string lastname = txtLastName.Text.Trim(); string email = txtEmail.Text.Trim(); string picture = txtPicture.Value; int day = int.Parse(dlDay.Text); int month = int.Parse(dlMonth.Text); int year = int.Parse(dlYear.Text); DateTime birthday = new DateTime(year, month, day); MemberDTO member = new MemberDTO { Username = username, Password = password, PhoneNum = phone, FirstName = firstname, LastName = lastname, Email = email, ImageLink = picture, IsActive = true, Birthdate = birthday, }; bool result = dao.AddNewMemberAdmin(member); if (result) { string message = "Regiter SUCCESSFULLY.\\nPlease login to continue."; ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true); } else { Response.Redirect("../ErrorPages/ErrorPage.aspx"); } }
protected void btnNew_Click(object sender, EventArgs e) { string username = txtUsername.Text.Trim(); //check null username if (username.Equals("")) { lblMessage.Text = "Username cannot be null!"; lblMessage.ForeColor = Color.Red; return; } string password = txtPassword.Text.Trim(); //check null password if (password.Equals("")) { lblMessage.Text = "Password cannot be null!"; lblMessage.ForeColor = Color.Red; return; } string firstname = txtFirstname.Text.Trim(); string lastname = txtLastname.Text.Trim(); string phone = txtPhone.Text.Trim(); double phoneNum = 0; //try phone number try { phoneNum = double.Parse(phone); } catch { lblMessage.Text = "Phone number must be numbers"; lblMessage.ForeColor = Color.Red; return; } string email = txtEmail.Text.Trim(); // check email if (!IsEmailValid(email)) { lblMessage.Text = "Email is not valid."; lblMessage.ForeColor = Color.Red; return; } DateTime birth = new DateTime(); // check birthdate try { birth = Convert.ToDateTime(txtBirth.Text.Trim()); } catch { lblMessage.Text = "Wrong format for Date of Birth, must be MM/dd/yyyy"; return; } MemberDTO dto = new MemberDTO(username, password, firstname, lastname, phone, email, birth, "", true); try { if (dao.AddNewMemberAdmin(dto)) { lblMessage.Text = "Successfully added"; lblMessage.ForeColor = Color.Green; } else { lblMessage.Text = "Failed to add"; lblMessage.ForeColor = Color.Red; } } catch { lblMessage.Text = "Username is already existed, please choose another one"; lblMessage.ForeColor = Color.Red; } }