private void btnConfirmMemb_Click(object sender, EventArgs e) { //Validate Email Boolean t = Databases.ValidateEmail(txtEmail.Text); if (!t) { MessageBox.Show("Enter valid email", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.ResetText(); return; } //Validate DOB String dob = txtDOB.Text; DateTime dt; string[] formats = { "yyyy-MM-dd" }; if (!DateTime.TryParseExact(dob, formats, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { MessageBox.Show("Please enter DOB in yyyy-MM-dd format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Validate Age int age = Databases.GetAge(dt); Boolean valid = Databases.ValidateAge(age); if (!valid) { MessageBox.Show("You must be over 18 to become a member", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Validate Phone if (txtPhone.Text.Length < 10) { MessageBox.Show("Please enter a valid mobile number!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //All fields must be entered before you can add a member if (txtName.Text.Trim() == string.Empty || txtSurname.Text.Trim() == string.Empty || txtDOB.Text.Trim() == string.Empty || txtEmail.Text.Trim() == string.Empty || txtPhone.Text.Trim() == string.Empty || cmbMembership.SelectedIndex < 0 || cmbPayment.SelectedIndex < 0) { MessageBox.Show("All fields must be entered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Validate Member Email String emailMember = txtEmail.Text.ToString(); DataSet emails; emails = Databases.CheckEmail(emailMember); int i = emails.Tables["emails"].Rows.Count; if (i > 0) { MessageBox.Show("Email already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.ResetText(); return; } Databases newMember = new Databases(); int id = Convert.ToInt32(txtMemID.Text); String name = txtName.Text.ToString(); String surname = txtSurname.Text.ToString(); int phone = Convert.ToInt32(txtPhone.Text); String email = txtSurname.Text.ToString(); char status = 'A'; newMember.AddMember(id, name, surname, dob, email, phone, status); DateTime start = dateStartBox.Value; int membershipID = Int32.Parse(cmbMembership.SelectedItem.ToString().Substring(0, 3)); newMember.MakeActiveMembership(membershipID, id, start); MessageBox.Show("Membership complete!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); parent.Visible = true; }