/// <summary> /// Clears all fields on form /// </summary> private void ClearAllFields() { FirstNameText.Text = ""; LastNameText.Text = ""; AddressText.Text = ""; GenderComboBox.SelectedIndex = -1; ConsultingDoctorText.Text = ""; WardText.Text = ""; RoomNoText.Text = ""; BedNoText.Text = ""; YesCheckBox.Checked = false; PatientFormValidator.Clear(); HealthCardLabel.Text = "-"; FirstNameText.Focus(); }
/// <summary> /// Clears windows form /// </summary> private void ClearAllFields() { foreach (int i in PositionsCheckedListBox.CheckedIndices) { PositionsCheckedListBox.SetItemCheckState(i, CheckState.Unchecked); } FirstNameText.Text = String.Empty; LastNameText.Text = String.Empty; AddressText.Text = String.Empty; EmailText.Text = String.Empty; CellNoText.Text = String.Empty; PositionText.Text = String.Empty; PositionsCheckedListBox.SelectedIndex = -1; EmployeeFormValidator.Clear(); FirstNameText.Focus(); }
private bool isControlsDataValidation() { Regex objEmployeeID = new Regex("^[0-9]{3,4}$"); Regex objFirstName = new Regex("^[A-Z][a-zA-Z]*$"); Regex objLastName = new Regex("^[A-Z][a-zA-Z]*$"); Regex ObjNI = new Regex(@"^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-D\s]$"); Regex objEmail = new Regex("^[a-zA-Z0-9]{1,30}@[a-zA-Z0-9]{1,30}.[a-zA-Z]{2,3}$"); //ID validation if (Convert.ToInt32(idText.Text.Length) < 1) { MessageBox.Show("Please enter EmployeeID", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); idText.Focus(); idText.BackColor = Color.Silver; return(false); } else if (!objEmployeeID.IsMatch(idText.Text)) { MessageBox.Show("Please enter a valid EmployeeID", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); idText.Focus(); idText.BackColor = Color.Silver; return(false); } else { idText.BackColor = Color.White; } //First Name Validation if (string.IsNullOrEmpty(FirstNameText.Text)) { MessageBox.Show("Please enter First Name", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FirstNameText.Focus(); FirstNameText.BackColor = Color.Silver; return(false); } else if (!objFirstName.IsMatch(FirstNameText.Text)) { MessageBox.Show("Please enter a valid First Name", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FirstNameText.Focus(); FirstNameText.BackColor = Color.Silver; return(false); } else { FirstNameText.BackColor = Color.White; } //last Name Validation if (string.IsNullOrEmpty(lastNameText.Text)) { MessageBox.Show("Please enter Last Name", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); lastNameText.Focus(); lastNameText.BackColor = Color.Silver; return(false); } else if (!objLastName.IsMatch(lastNameText.Text)) { MessageBox.Show("Please enter a valid Last Name", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); lastNameText.Focus(); lastNameText.BackColor = Color.Silver; return(false); } else { lastNameText.BackColor = Color.White; } //gender validation if (maleRadioBtn.Checked == false && femaleRadioBtn.Checked == false) { MessageBox.Show("Please enter Your Gender", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); genderGrp.Focus(); maleRadioBtn.BackColor = Color.Silver; femaleRadioBtn.BackColor = Color.Silver; return(false); } else { maleRadioBtn.BackColor = Color.CornflowerBlue; femaleRadioBtn.BackColor = Color.CornflowerBlue; } //national insuarance validation if (insuaranceText.Text == "") { MessageBox.Show("Please enter National Insuarance Number", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); insuaranceText.Focus(); insuaranceText.BackColor = Color.Silver; return(false); } else if (!ObjNI.IsMatch(insuaranceText.Text)) { MessageBox.Show("Please enter a valid Insuarance No", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); insuaranceText.Focus(); insuaranceText.BackColor = Color.Silver; return(false); } else { insuaranceText.BackColor = Color.White; } //marital status validation if (marriedRadioBtn.Checked == false && singleRadioBtn.Checked == false) { MessageBox.Show("Please enter Your Marital Status", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); maritalStatusGrp.Focus(); marriedRadioBtn.BackColor = Color.Silver; singleRadioBtn.BackColor = Color.Silver; return(false); } else { marriedRadioBtn.BackColor = Color.CornflowerBlue; singleRadioBtn.BackColor = Color.CornflowerBlue; } //adress Validation if (addressText.Text == "") { MessageBox.Show("Please enter Your Address", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); addressText.Focus(); addressText.BackColor = Color.Silver; return(false); } else { addressText.BackColor = Color.White; } //city validation if (cityText.Text == "") { MessageBox.Show("Please enter CIty", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cityText.Focus(); cityText.BackColor = Color.Silver; return(false); } else { cityText.BackColor = Color.White; } //postCode validation if (postTeext.Text == "") { MessageBox.Show("Please enter your postal code", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); postTeext.Focus(); postTeext.BackColor = Color.Silver; return(false); } else { postTeext.BackColor = Color.White; } //country Validation if (countryCombo.SelectedIndex == 0 || countryCombo.SelectedIndex == -1) { MessageBox.Show("Please Select Your Country", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); countryCombo.Focus(); countryCombo.BackColor = Color.Silver; return(false); } else { countryCombo.BackColor = Color.White; } //phoneNO validation if (phoneText.Text == "") { MessageBox.Show("Please enter your phone number", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); phoneText.Focus(); phoneText.BackColor = Color.Silver; return(false); } else { phoneText.BackColor = Color.White; } //email validation if (emailText.Text == "") { MessageBox.Show("Please enter your email", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); emailText.Focus(); emailText.BackColor = Color.Silver; return(false); } else if (emailText.Text.Length >= 1) { try { MailAddress objMail = new MailAddress(emailText.Text); } catch (Exception ex) { MessageBox.Show("Error :" + ex.Message, "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); emailText.Focus(); emailText.BackColor = Color.Silver; return(false); } } //else if (!objEmail.IsMatch(emailText.Text)) //{ // MessageBox.Show("Please enter a valid Email", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // emailText.Focus(); // emailText.BackColor = Color.Silver; // return false; //} else { emailText.BackColor = Color.White; } //Notes validation if (noteText.Text.Length > 30) { MessageBox.Show("Too Much Text! Please reduce your length..", "Data entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); noteText.Focus(); noteText.BackColor = Color.Silver; return(false); } else { noteText.BackColor = Color.White; } return(true); }