Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace GlobalSanicElectronics
- {
- public partial class AccountCreation : Form
- {
- public AccountCreation()
- {
- InitializeComponent();
- }
- private void confirmButton_Click(object sender, EventArgs e)
- {
- //Username checking
- if (usernameTextBox.Text == "")
- {
- MessageBox.Show("Please enter a username");
- usernameTextBox.BackColor = Color.Red;
- usernameTextBox.ForeColor = Color.White;
- }
- else
- {
- usernameTextBox.BackColor = Color.White;
- usernameTextBox.ForeColor = Color.Black;
- }
- if (dOBTextBox.Text == "")
- {
- MessageBox.Show("Please enter a Birthdate");
- dOBTextBox.BackColor = Color.Red;
- dOBTextBox.ForeColor = Color.White;
- }
- else
- {
- dOBTextBox.BackColor = Color.White;
- dOBTextBox.ForeColor = Color.Black;
- }
- if (addressTextBox.Text == "")
- {
- MessageBox.Show("Please enter an address");
- addressTextBox.BackColor = Color.Red;
- addressTextBox.ForeColor = Color.White;
- }
- else
- {
- addressTextBox.BackColor = Color.White;
- addressTextBox.ForeColor = Color.Black;
- }
- if (cityTextBox.Text == "")
- {
- MessageBox.Show("Please enter a city");
- cityTextBox.BackColor = Color.Red;
- cityTextBox.ForeColor = Color.White;
- }
- else
- {
- cityTextBox.BackColor = Color.White;
- cityTextBox.ForeColor = Color.Black;
- }
- if (stateTextBox.Text == "")
- {
- MessageBox.Show("Please enter a state");
- stateTextBox.BackColor = Color.Red;
- stateTextBox.ForeColor = Color.White;
- }
- else
- {
- stateTextBox.BackColor = Color.White;
- stateTextBox.ForeColor = Color.Black;
- }
- if (zipTextBox.Text == "")
- {
- MessageBox.Show("Please enter a zip");
- zipTextBox.BackColor = Color.Red;
- zipTextBox.ForeColor = Color.White;
- }
- else
- {
- zipTextBox.BackColor = Color.White;
- zipTextBox.ForeColor = Color.Black;
- }
- if (checkPassword == true)
- {
- if (checkEmail == true)
- {
- try
- {
- CustomerInformation newCustomer = new CustomerInformation();
- newCustomer.Username = usernameTextBox.Text;
- newCustomer.Password = PasswordOperations.AccountPasswordHashing(passwordTextBox.Text);
- newCustomer.Email = emailTextBox.Text;
- newCustomer.DOB = dOBTextBox.Text;
- newCustomer.Address = addressTextBox.Text;
- newCustomer.City = cityTextBox.Text;
- newCustomer.State = stateTextBox.Text;
- newCustomer.Zip = zipTextBox.Text;
- DatabaseOperations.CreateUser(newCustomer);
- MessageBox.Show(usernameTextBox.Text + " has been created! Thank you for joining Global Sanic Electronics! An email has been sent to you to confirm your account registration!");
- EmailOperations.UserCreatedEmail(emailTextBox.Text, usernameTextBox.Text, dOBTextBox.Text, addressTextBox.Text, cityTextBox.Text, stateTextBox.Text, zipTextBox.Text);
- //Hide this form so the user can no longer see it as it is no longer needed
- this.Hide();
- //Go to the MainApplication since the user has successfully logged in and created there account
- MainApplication mainApplicationForm = new MainApplication();
- string username = usernameTextBox.Text;
- mainApplicationForm.mainApplicationUsername = username;
- mainApplicationForm.Show();
- }
- catch (SqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
- private void exitButton_Click(object sender, EventArgs e)
- {
- //Close the application out when the user clicks Exit
- this.Close();
- }
- protected override void OnFormClosing(FormClosingEventArgs e)
- {
- //Close the application if the user decides to push the big red X
- System.Windows.Forms.Application.Exit();
- }
- private void AccountCreation_Load(object sender, EventArgs e)
- {
- try
- {
- //Clear text fields of all information so user doesn't get information in first fields in CustomerInformation table in the GSEDatabase
- usernameTextBox.Text = "";
- passwordTextBox.Text = "";
- emailTextBox.Text = "";
- dOBTextBox.Text = "";
- addressTextBox.Text = "";
- cityTextBox.Text = "";
- stateTextBox.Text = "";
- zipTextBox.Text = "";
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- /**
- * This code is to check and make sure that the user is inputting a email that is
- * in the correct format IE sample@stuff.com
- */
- private bool validateEmail(string email)
- {
- var input = email; //Gets the string when the method is called and assigns it to input
- var validEmail = new Regex(@"[a-zA-Z0-9]{3,20}@[a-zA-Z0-9]{3,20}.[a-zA-Z0-9]{3}");
- if (!validEmail.IsMatch(input))
- {
- //MessageBox.Show("Ensure that yoor email is in the correct format \n correctformat@this.com");
- MessageBox.Show(this, "Correct format \n \n correctformat@this.com.",
- "Wrong Email Format", MessageBoxButtons.OK,
- MessageBoxIcon.Information,
- MessageBoxDefaultButton.Button1);
- emailTextBox.BackColor = Color.Red;
- emailTextBox.ForeColor = Color.White;
- return false;
- }
- else
- {
- emailTextBox.BackColor = Color.White;
- emailTextBox.ForeColor = Color.Black;
- return true;
- }
- }
- //Method to allow the user to push enter instead of actually Confirm.
- private void usernameTextBox_TextChanged(object sender, EventArgs e)
- {
- //Takes "Enter" key and allows it to be a substitute for the submit button or pushes the submit button for you instead of having to click it.
- this.AcceptButton = confirmButton;
- }
- //Method to allow the user to push enter instead of actually Confirm.
- private void passwordTextBox_TextChanged(object sender, EventArgs e)
- {
- //Takes "Enter" key and allows it to be a substitute for the submit button or pushes the submit button for you instead of having to click it.
- this.AcceptButton = confirmButton;
- }
- //Method to allow the user to push enter instead of actually Confirm.
- private void emailTextBox_TextChanged(object sender, EventArgs e)
- {
- //Takes "Enter" key and allows it to be a substitute for the submit button or pushes the submit button for you instead of having to click it.
- this.AcceptButton = confirmButton;
- }
- //Method to allow the user to push enter instead of actually Confirm.
- private void dOBTextBox_TextChanged(object sender, EventArgs e)
- {
- //Takes "Enter" key and allows it to be a substitute for the submit button or pushes the submit button for you instead of having to click it.
- this.AcceptButton = confirmButton;
- }
- //Method to allow the user to push enter instead of actually Confirm.
- private void addressTextBox_TextChanged(object sender, EventArgs e)
- {
- //Takes "Enter" key and allows it to be a substitute for the submit button or pushes the submit button for you instead of having to click it.
- this.AcceptButton = confirmButton;
- }
- //Method to allow the user to push enter instead of actually Confirm.
- private void cityTextBox_TextChanged(object sender, EventArgs e)
- {
- //Takes "Enter" key and allows it to be a substitute for the submit button or pushes the submit button for you instead of having to click it.
- this.AcceptButton = confirmButton;
- }
- //Method to allow the user to push enter instead of actually Confirm.
- private void stateTextBox_TextChanged(object sender, EventArgs e)
- {
- //Takes "Enter" key and allows it to be a substitute for the submit button or pushes the submit button for you instead of having to click it.
- this.AcceptButton = confirmButton;
- }
- //Method to allow the user to push enter instead of actually Confirm.
- private void zipTextBox_TextChanged(object sender, EventArgs e)
- {
- //Takes "Enter" key and allows it to be a substitute for the submit button or pushes the submit button for you instead of having to click it.
- this.AcceptButton = confirmButton;
- }
- private void passwordTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
- {
- bool checkPassword = Validation.PasswordValidation(passwordTextBox, errorProvider);
- }
- private void emailTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
- {
- bool checkEmail = validateEmail(emailTextBox.Text.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement