private void OnButtonClick(object sender, EventArgs e) { Button button = sender as Button; switch (button.Name) { case "buttonSignUp": if (!RegistrationUtility.IsUsernameValid(textBoxUsername.Text, Form1.sqlConnection)) { RegistrationUtility.OnRegisterError(ERRORS.EMAIL, labelError); break; } if (!RegistrationUtility.IsPasswordValid(textBoxPassword.Text)) { RegistrationUtility.OnRegisterError(ERRORS.PASSWORD, labelError); break; } //if (!RegistrationUtility.IsDateValid(dateTimeDOB.Value, labelError)) //{ // OnRegisterError(ERRORS.DATE); // break; //} //Insert new user into database if (AddUserToDatabase(textBoxUsername.Text, textBoxPassword.Text, dateTimeDOB.Value, Form1.sqlConnection)) { labelError.Visible = true; labelError.ForeColor = Color.Green; labelError.Text = "User added with success."; } break; } }
private void OnClick(object sender, EventArgs e) { Button button = sender as Button; UsersManagement.UserData newUserData = userData; if (button == buttonSave) { //confirma os inputs para verificar quais os dados o utilizador quer mudar DataToChange dataToChange = ValidateUserNewInfo(); //compara a nova e a velha password if (dataToChange.password) { if (String.Compare(userData.password, textBox2.Text) != 0) { //se as passwords sao diferentes, confirma q a nova password é valida if (!RegistrationUtility.IsPasswordValid(textBox2.Text)) { MessageBox.Show("New Password not valid."); return; } else { newUserData.password = textBox2.Text; } } else { MessageBox.Show("Your new password is the same as the old one."); return; } } //comparar datas de nascimento if (dataToChange.dob) { if (!RegistrationUtility.IsDateValid(dateTimePicker1.Value)) { MessageBox.Show("Your new date isnt valid!"); return; } else { newUserData.dob = dateTimePicker1.Value; } } if (RegistrationUtility.UpdateUserInfo(Form1.sqlConnection, newUserData)) { MessageBox.Show("User info updated."); this.Close(); } else { MessageBox.Show("Command failed."); } } }