Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.44 KB | None | 0 0
  1. namespace GlobalSanicElectronics
  2. {
  3.     public partial class AccountCreation : Form
  4.     {
  5.         public AccountCreation()
  6.         {
  7.             InitializeComponent();  
  8.         }
  9.  
  10.         private void confirmButton_Click(object sender, EventArgs e)
  11.         {
  12.             //Username checking
  13.             if (usernameTextBox.Text == "")
  14.             {
  15.                 MessageBox.Show("Please enter a username");
  16.                 usernameTextBox.BackColor = Color.Red;
  17.                 usernameTextBox.ForeColor = Color.White;
  18.             }
  19.             else
  20.             {
  21.                 usernameTextBox.BackColor = Color.White;
  22.                 usernameTextBox.ForeColor = Color.Black;
  23.             }
  24.  
  25.             if (dOBTextBox.Text == "")
  26.             {
  27.                 MessageBox.Show("Please enter a Birthdate");
  28.                 dOBTextBox.BackColor = Color.Red;
  29.                 dOBTextBox.ForeColor = Color.White;
  30.             }
  31.             else
  32.             {
  33.                 dOBTextBox.BackColor = Color.White;
  34.                 dOBTextBox.ForeColor = Color.Black;
  35.             }
  36.  
  37.             if (addressTextBox.Text == "")
  38.             {
  39.                 MessageBox.Show("Please enter an address");
  40.                 addressTextBox.BackColor = Color.Red;
  41.                 addressTextBox.ForeColor = Color.White;
  42.             }
  43.             else
  44.             {
  45.                 addressTextBox.BackColor = Color.White;
  46.                 addressTextBox.ForeColor = Color.Black;
  47.             }
  48.  
  49.             if (cityTextBox.Text == "")
  50.             {
  51.                 MessageBox.Show("Please enter a city");
  52.                 cityTextBox.BackColor = Color.Red;
  53.                 cityTextBox.ForeColor = Color.White;
  54.             }
  55.             else
  56.             {
  57.                 cityTextBox.BackColor = Color.White;
  58.                 cityTextBox.ForeColor = Color.Black;
  59.             }
  60.  
  61.             if (stateTextBox.Text == "")
  62.             {
  63.                 MessageBox.Show("Please enter a state");
  64.                 stateTextBox.BackColor = Color.Red;
  65.                 stateTextBox.ForeColor = Color.White;
  66.             }
  67.             else
  68.             {
  69.                 stateTextBox.BackColor = Color.White;
  70.                 stateTextBox.ForeColor = Color.Black;
  71.             }
  72.  
  73.             if (zipTextBox.Text == "")
  74.             {
  75.                 MessageBox.Show("Please enter a zip");
  76.                 zipTextBox.BackColor = Color.Red;
  77.                 zipTextBox.ForeColor = Color.White;
  78.             }
  79.             else
  80.             {
  81.                 zipTextBox.BackColor = Color.White;
  82.                 zipTextBox.ForeColor = Color.Black;
  83.             }
  84.  
  85.             if (checkPassword == true)
  86.             {
  87.                 if (checkEmail == true)
  88.                 {
  89.                     try
  90.                     {                        
  91.                         CustomerInformation newCustomer = new CustomerInformation();
  92.  
  93.                         newCustomer.Username = usernameTextBox.Text;
  94.                         newCustomer.Password = PasswordOperations.AccountPasswordHashing(passwordTextBox.Text);
  95.                         newCustomer.Email = emailTextBox.Text;
  96.                         newCustomer.DOB = dOBTextBox.Text;
  97.                         newCustomer.Address = addressTextBox.Text;
  98.                         newCustomer.City = cityTextBox.Text;
  99.                         newCustomer.State = stateTextBox.Text;
  100.                         newCustomer.Zip = zipTextBox.Text;
  101.  
  102.                         DatabaseOperations.CreateUser(newCustomer);
  103.  
  104.                         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!");
  105.  
  106.                         EmailOperations.UserCreatedEmail(emailTextBox.Text, usernameTextBox.Text, dOBTextBox.Text, addressTextBox.Text, cityTextBox.Text, stateTextBox.Text, zipTextBox.Text);
  107.  
  108.                         //Hide this form so the user can no longer see it as it is no longer needed
  109.                         this.Hide();
  110.  
  111.                         //Go to the MainApplication since the user has successfully logged in and created there account
  112.                         MainApplication mainApplicationForm = new MainApplication();
  113.                         string username = usernameTextBox.Text;
  114.                         mainApplicationForm.mainApplicationUsername = username;
  115.                         mainApplicationForm.Show();
  116.  
  117.                     }
  118.                     catch (SqlException ex)
  119.                     {
  120.                         MessageBox.Show(ex.Message);
  121.                     }
  122.                 }
  123.             }
  124.         }
  125.  
  126.         private void exitButton_Click(object sender, EventArgs e)
  127.         {
  128.             //Close the application out when the user clicks Exit
  129.             this.Close();
  130.         }
  131.  
  132.         protected override void OnFormClosing(FormClosingEventArgs e)
  133.         {
  134.             //Close the application if the user decides to push the big red X
  135.             System.Windows.Forms.Application.Exit();
  136.         }
  137.  
  138.         private void AccountCreation_Load(object sender, EventArgs e)
  139.         {
  140.             try
  141.             {
  142.  
  143.             //Clear text fields of all information so user doesn't get information in first fields in CustomerInformation table in the GSEDatabase
  144.             usernameTextBox.Text = "";
  145.             passwordTextBox.Text = "";
  146.             emailTextBox.Text = "";
  147.             dOBTextBox.Text = "";
  148.             addressTextBox.Text = "";
  149.             cityTextBox.Text = "";
  150.             stateTextBox.Text = "";
  151.             zipTextBox.Text = "";
  152.             }
  153.             catch(Exception ex)
  154.             {
  155.                 MessageBox.Show(ex.ToString());
  156.             }
  157.            
  158.         }
  159.  
  160.         /**
  161.          * This code is to check and make sure that the user is inputting a email that is
  162.          * in the correct format IE sample@stuff.com
  163.          */        
  164.         private bool validateEmail(string email)
  165.         {
  166.             var input = email;      //Gets the string when the method is called and assigns it to input
  167.  
  168.             var validEmail = new Regex(@"[a-zA-Z0-9]{3,20}@[a-zA-Z0-9]{3,20}.[a-zA-Z0-9]{3}");
  169.            
  170.             if (!validEmail.IsMatch(input))
  171.             {
  172.                 //MessageBox.Show("Ensure that yoor email is in the correct format \n correctformat@this.com");
  173.  
  174.                 MessageBox.Show(this, "Correct format \n \n correctformat@this.com.",
  175.                                    "Wrong Email Format", MessageBoxButtons.OK,
  176.                                    MessageBoxIcon.Information,
  177.                                    MessageBoxDefaultButton.Button1);
  178.  
  179.                 emailTextBox.BackColor = Color.Red;
  180.                 emailTextBox.ForeColor = Color.White;
  181.  
  182.                 return false;
  183.             }
  184.             else
  185.             {
  186.                 emailTextBox.BackColor = Color.White;
  187.                 emailTextBox.ForeColor = Color.Black;
  188.  
  189.                 return true;
  190.             }
  191.         }
  192.  
  193.         //Method to allow the user to push enter instead of actually Confirm.
  194.         private void usernameTextBox_TextChanged(object sender, EventArgs e)
  195.         {
  196.             //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.
  197.             this.AcceptButton = confirmButton;
  198.         }
  199.  
  200.         //Method to allow the user to push enter instead of actually Confirm.
  201.         private void passwordTextBox_TextChanged(object sender, EventArgs e)
  202.         {
  203.             //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.
  204.             this.AcceptButton = confirmButton;
  205.         }
  206.  
  207.         //Method to allow the user to push enter instead of actually Confirm.
  208.         private void emailTextBox_TextChanged(object sender, EventArgs e)
  209.         {
  210.             //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.
  211.             this.AcceptButton = confirmButton;
  212.         }
  213.  
  214.         //Method to allow the user to push enter instead of actually Confirm.
  215.         private void dOBTextBox_TextChanged(object sender, EventArgs e)
  216.         {
  217.             //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.
  218.             this.AcceptButton = confirmButton;
  219.         }
  220.  
  221.         //Method to allow the user to push enter instead of actually Confirm.
  222.         private void addressTextBox_TextChanged(object sender, EventArgs e)
  223.         {
  224.             //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.
  225.             this.AcceptButton = confirmButton;
  226.         }
  227.  
  228.         //Method to allow the user to push enter instead of actually Confirm.
  229.         private void cityTextBox_TextChanged(object sender, EventArgs e)
  230.         {
  231.             //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.
  232.             this.AcceptButton = confirmButton;
  233.         }
  234.  
  235.         //Method to allow the user to push enter instead of actually Confirm.
  236.         private void stateTextBox_TextChanged(object sender, EventArgs e)
  237.         {
  238.             //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.
  239.             this.AcceptButton = confirmButton;
  240.         }
  241.  
  242.         //Method to allow the user to push enter instead of actually Confirm.
  243.         private void zipTextBox_TextChanged(object sender, EventArgs e)
  244.         {
  245.             //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.
  246.             this.AcceptButton = confirmButton;
  247.         }
  248.  
  249.         private void passwordTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  250.         {
  251.             bool checkPassword = Validation.PasswordValidation(passwordTextBox, errorProvider);
  252.         }
  253.  
  254.         private void emailTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  255.         {
  256.             bool checkEmail = validateEmail(emailTextBox.Text.ToString());
  257.         }
  258.     }
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement