private void btnPISubmit_Click(object sender, RoutedEventArgs e) { PIConfirmation PIConfirmWindow = new PIConfirmation(); PIConfirmWindow.Show(); this.Close(); }
private bool AddPayment(string firstName, string lastName, object ccType, string ccNumber, string phone, string email) { //define variables; Payment newPayment; //Validate on required fields if (firstName == "") { MessageBox.Show("First Name is a required field."); return(false); } if (lastName == "") { MessageBox.Show("Last Name is a required field."); return(false); } if (ccType == null) { MessageBox.Show("Credit Card Type is a required field."); return(false); } if (ccNumber == "") { MessageBox.Show("Credit Card Number is a required field."); return(false); } if (phone == "") { MessageBox.Show("Phone is a required field."); return(false); } //validate Credit Card Number //validate phone number Regex phoneValidate = new Regex(@"^(\([0-9]{3}\)|[0-9]{3}-)[0-9]{3}-[0-9]{4}|(\([0-9]{3}\)|[0-9]{3})[0-9]{3}[0-9]{4}$"); if (!phoneValidate.IsMatch(txtPhone.Text)) { MessageBox.Show("Please input a valid phone number."); return(false); } //validate email address Regex emailValidate = new Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"); if (!emailValidate.IsMatch(txtEmail.Text)) { MessageBox.Show("Please input a valid email."); return(false); } newPayment = new Payment(firstName, lastName, ccType.ToString(), ccNumber, phone, email); //make sure customer want to save record MessageBoxResult messageBoxResult = MessageBox.Show("Do you want to save the payment information?" + Environment.NewLine , "Add New Payment", MessageBoxButton.YesNo); // add customer to list if (messageBoxResult == MessageBoxResult.No) { return(false); } else { paymentList.Add(newPayment); PIConfirmation PIConfirmation = new PIConfirmation(); PIConfirmation.Show(); this.Close(); return(true); } }