protected void btnNew_Click(object sender, EventArgs e) { string username = txtUsername.Text.Trim(); if (username.Equals("")) { lblMessage.Text = "Username cannot be empty!"; lblMessage.ForeColor = Color.Red; return; } string password = txtPassword.Text.Trim(); if (password.Equals("")) { lblMessage.Text = "Password cannot be empty!"; lblMessage.ForeColor = Color.Red; return; } string firstname = txtFirstname.Text.Trim(); string lastname = txtLastname.Text.Trim(); string phone = txtPhone.Text.Trim(); double phoneNum = 0; try { phoneNum = double.Parse(phone); } catch { lblMessage.Text = "Phone number not valid!"; lblMessage.ForeColor = Color.Red; } string email = txtEmail.Text.Trim(); if (!IsEmailValid(email)) { lblMessage.Text = "Email is not valid!"; lblMessage.ForeColor = Color.Red; return; } StaffDTO dto = new StaffDTO { Username = username, Password = password, FirstName = firstname, LastName = lastname, Phone = phone, Email = email, IsActive = true }; try { if (dao.AddNewStaff(username, password, firstname, lastname, phone, email, true)) { 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; } }