//submits payment details public void btnOrder_Click(object sender, EventArgs e) { bool error = false; bool valid = false; lblExpirationDate.ForeColor = Color.Black; lblExpiratonDate.ForeColor = Color.Black; //checks expiration validity if (cmbExpirationMonth.SelectedIndex == -1 || cmbExpirationYear.SelectedIndex == -1) { error = true; } else { strExpirationDate = cmbExpirationMonth.SelectedItem.ToString() + " / " + cmbExpirationYear.SelectedItem.ToString(); } #region(SET VALUES) strFirstName = txtFirstName.Text; strLastName = txtLastName.Text; strCardNumber = txtCardNumber.Text; strCardSecurity = txtCardSecurity.Text; strBillingAddress1 = txtAddress1.Text; strBillingAddress2 = txtAddress2.Text; strCity = txtCity.Text; strPostCode = txtPostalCode.Text; strCountry = cmbCountry.SelectedItem.ToString(); strEmail = txtEmail.Text; #endregion #region(Set Default Colour) lblFirstName.ForeColor = Color.Black; lblLastName.ForeColor = Color.Black; lblCardType.ForeColor = Color.Black; lblCardNumber.ForeColor = Color.Black; lblSecurityNumber.ForeColor = Color.Black; lblBilling1.ForeColor = Color.Black; lblCity.ForeColor = Color.Black; lblCountry.ForeColor = Color.Black; lblPostCode.ForeColor = Color.Black; lblEmail.ForeColor = Color.Black; #endregion #region(Error Checking) //Checks email validity foreach (char c in strEmail) { if (c == '@') { valid = true; } } //Checks to see all needed fields are filled if (strFirstName == "" || strLastName == "" || strCardNumber == "" || strCardSecurity == "" || strCardType == "" || strExpirationDate == "" || strBillingAddress1 == "" || strCity == "" || strPostCode == "" || strCountry == "" || strEmail == "") { MessageBox.Show("ERROR"); error = true; } else { //Checks to see if card length is valid if (strCardNumber.Length != 16) { MessageBox.Show("Card Number Too Long"); txtCardNumber.Clear(); strCardNumber = ""; lblCardNumber.ForeColor = Color.Red; error = true; } else { //Checks to see if first name fiels is filled if (strFirstName == "") { MessageBox.Show("Please enter your first name"); txtFirstName.Clear(); lblFirstName.ForeColor = Color.Red; error = true; } else { //Checks to see if last name field is filled if (strLastName == "") { MessageBox.Show("Please enter your last name"); txtLastName.Clear(); lblLastName.ForeColor = Color.Red; error = true; } else { //Checks to see is a card type is selected if (radVisa.Checked == false && radMasterCard.Checked == false && radAmericanExpress.Checked == false && radDiscover.Checked == false && radDelta.Checked == false) { MessageBox.Show("Please chose a card type"); lblCardType.ForeColor = Color.Red; error = true; } else { //Checks to see if billing address is filled if (strBillingAddress1 == "") { MessageBox.Show("Please enter you address"); lblBilling1.ForeColor = Color.Red; error = true; } else { //Checks to see is city ils is filled if (strCity == "") { MessageBox.Show("Please enter your city"); lblCity.ForeColor = Color.Red; error = true; } else { //Checks to see if email fiels is filled if (strEmail == "") { MessageBox.Show("Please enter your email address"); lblEmail.ForeColor = Color.Red; error = true; } else { //Executed invalid email address is entered if (!valid) { MessageBox.Show("Please enter a valid email address"); lblEmail.ForeColor = Color.Red; txtEmail.Clear(); error = true; } else { //Checks to see if both expiration date fields are filled if (cmbExpirationMonth.SelectedIndex == -1 || cmbExpirationYear.SelectedIndex == -1) { MessageBox.Show("Please enter a valid expiration date"); lblExpirationDate.ForeColor = Color.Red; lblExpiratonDate.ForeColor = Color.Red; error = true; } } } } } } } } } } #endregion #region(Test Labels) //label1.Text = strFirstName; //label2.Text = strLastName; //label3.Text = strCardType; //label4.Text = strCardNumber; //label6.Text = strExpirationDate; //label7.Text = strCardSecurity; //label8.Text = strBillingAddress1; //label9.Text = strBillingAddress2; //label10.Text = strCity; //label11.Text = strPostCode; //label12.Text = strCountry; //label13.Text = strEmail; #endregion //Executed if all payment fields are filled correctly if (!error) { FrmTrackOrder track = new FrmTrackOrder(intOrderNumber); track.Show(); this.Close(); //this.Hide(); menu.closeForm(); //calls closeForm method from parent form } }
//submits payment details public void btnOrder_Click(object sender, EventArgs e) { bool error = false; bool valid = false; lblExpirationDate.ForeColor = Color.Black; lblExpiratonDate.ForeColor = Color.Black; //checks expiration validity if (cmbExpirationMonth.SelectedIndex == -1 || cmbExpirationYear.SelectedIndex == -1) { error = true; } else { strExpirationDate = cmbExpirationMonth.SelectedItem.ToString() + " / " + cmbExpirationYear.SelectedItem.ToString(); } #region (SET VALUES) strFirstName = txtFirstName.Text; strLastName = txtLastName.Text; strCardNumber = txtCardNumber.Text; strCardSecurity = txtCardSecurity.Text; strBillingAddress1 = txtAddress1.Text; strBillingAddress2 = txtAddress2.Text; strCity = txtCity.Text; strPostCode = txtPostalCode.Text; strCountry = cmbCountry.SelectedItem.ToString(); strEmail = txtEmail.Text; #endregion #region (Set Default Colour) lblFirstName.ForeColor = Color.Black; lblLastName.ForeColor = Color.Black; lblCardType.ForeColor = Color.Black; lblCardNumber.ForeColor = Color.Black; lblSecurityNumber.ForeColor = Color.Black; lblBilling1.ForeColor = Color.Black; lblCity.ForeColor = Color.Black; lblCountry.ForeColor = Color.Black; lblPostCode.ForeColor = Color.Black; lblEmail.ForeColor = Color.Black; #endregion #region (Error Checking) //Checks email validity foreach (char c in strEmail) { if (c == '@') { valid = true; } } //Checks to see all needed fields are filled if (strFirstName == "" || strLastName == "" || strCardNumber == "" || strCardSecurity == "" || strCardType == "" || strExpirationDate == "" || strBillingAddress1 == "" || strCity == "" || strPostCode == "" || strCountry == "" || strEmail == "") { MessageBox.Show("ERROR"); error = true; } else { //Checks to see if card length is valid if (strCardNumber.Length != 16) { MessageBox.Show("Card Number Too Long"); txtCardNumber.Clear(); strCardNumber = ""; lblCardNumber.ForeColor = Color.Red; error = true; } else { //Checks to see if first name fiels is filled if (strFirstName == "") { MessageBox.Show("Please enter your first name"); txtFirstName.Clear(); lblFirstName.ForeColor = Color.Red; error = true; } else { //Checks to see if last name field is filled if (strLastName == "") { MessageBox.Show("Please enter your last name"); txtLastName.Clear(); lblLastName.ForeColor = Color.Red; error = true; } else { //Checks to see is a card type is selected if (radVisa.Checked == false && radMasterCard.Checked == false && radAmericanExpress.Checked == false && radDiscover.Checked == false && radDelta.Checked == false) { MessageBox.Show("Please chose a card type"); lblCardType.ForeColor = Color.Red; error = true; } else { //Checks to see if billing address is filled if (strBillingAddress1 == "") { MessageBox.Show("Please enter you address"); lblBilling1.ForeColor = Color.Red; error = true; } else { //Checks to see is city ils is filled if (strCity == "") { MessageBox.Show("Please enter your city"); lblCity.ForeColor = Color.Red; error = true; } else { //Checks to see if email fiels is filled if (strEmail == "") { MessageBox.Show("Please enter your email address"); lblEmail.ForeColor = Color.Red; error = true; } else { //Executed invalid email address is entered if (!valid) { MessageBox.Show("Please enter a valid email address"); lblEmail.ForeColor = Color.Red; txtEmail.Clear(); error = true; } else { //Checks to see if both expiration date fields are filled if (cmbExpirationMonth.SelectedIndex == -1 || cmbExpirationYear.SelectedIndex == -1) { MessageBox.Show("Please enter a valid expiration date"); lblExpirationDate.ForeColor = Color.Red; lblExpiratonDate.ForeColor = Color.Red; error = true; } } } } } } } } } } #endregion #region (Test Labels) //label1.Text = strFirstName; //label2.Text = strLastName; //label3.Text = strCardType; //label4.Text = strCardNumber; //label6.Text = strExpirationDate; //label7.Text = strCardSecurity; //label8.Text = strBillingAddress1; //label9.Text = strBillingAddress2; //label10.Text = strCity; //label11.Text = strPostCode; //label12.Text = strCountry; //label13.Text = strEmail; #endregion //Executed if all payment fields are filled correctly if (!error) { FrmTrackOrder track = new FrmTrackOrder(intOrderNumber); track.Show(); this.Close(); //this.Hide(); menu.closeForm(); //calls closeForm method from parent form } }