/// <summary> /// Method used to validate the input and then add a contact object to the list if it is okay. /// </summary> /// <returns>true if the contact was successfully validated, otherwise false</returns> private bool ReadInput() { bool ok = false; Contact contact = CreateContact(); if (contact != null) { ok = contact.validate(); } if (ok) { contactmanager.AddContact(contact); } else { MessageBox.Show("Check your input then try again!"); } return(ok); }
/// <summary> /// adding in the listBox /// </summary> private void btnAdd_Click(object sender, EventArgs e) { if (_fName.Text == "") { MessageBox.Show("Please give a valid First Name!", "Please . . ."); return; } if (_fName.Text == " ") { MessageBox.Show("Please give a valid First Name!", "Please . . ."); return; } if (_lName.Text == "") { MessageBox.Show("Please give a valid Last Name!", "Please . . ."); return; } if (_lName.Text == " ") { MessageBox.Show("Please give a valid Last Name!", "Please . . ."); return; } if (_street.Text == "") { MessageBox.Show("Please give a valid Street Number!", "Please . . ."); return; } if (_street.Text == " ") { MessageBox.Show("Please give a valid Street Number!", "Please . . ."); return; } if (_city.Text == "") { MessageBox.Show("Please give a valid City Name!", "Please . . ."); return; } if (_city.Text == " ") { MessageBox.Show("Please give a valid City Name!", "Please . . ."); return; } if (_zipCode.Text == "") { MessageBox.Show("Please give valid Zip Code!", "Please . . ."); return; } if (_zipCode.Text == " ") { MessageBox.Show("Please give valid Zip Code!", "Please . . ."); return; } m_contactMngr.AddContact(ReadInput()); UpdateGUi(); }