private void Date_Validated(object sender, EventArgs e) { if (!Validator.ValidateDate(Date.Value)) { FieldError.SetError(Date, "Cannot Select Future Date"); } else { FieldError.SetError(Date, ""); } }
private void City_Validated(object sender, EventArgs e) { if (!Validator.ValidateTextField(City.Text)) { FieldError.SetError(City, "Required Field"); } else { FieldError.SetError(City, ""); } }
private void Proof_Validated(object sender, EventArgs e) { if (!Validator.ValidateComboBox(Proof.SelectedItem)) { FieldError.SetError(Proof, "Required Field"); } else { FieldError.SetError(Proof, ""); } }
private void Address1_Validated(object sender, EventArgs e) { if (!Validator.ValidateTextField(Address1.Text)) { FieldError.SetError(Address1, "Required Field"); } else { FieldError.SetError(Address1, ""); } }
private void lastName_validate(object sender, EventArgs e) { if (!Validator.ValidateTextField(lastName.Text)) { FieldError.SetError(lastName, "Required Field"); } else { FieldError.SetError(lastName, ""); } }
private void middleInitial_validated(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(Minitial.Text) && !Validator.ValidateInitial(Minitial.Text)) { Minitial.ForeColor = Color.Red; FieldError.SetError(Minitial, "Invalid Character"); } else { Minitial.ForeColor = Color.Black; FieldError.SetError(Minitial, ""); } }
private void Email_Validated(object sender, EventArgs e) { if (!Validator.ValidateEmailAddress(Email.Text)) { if (string.IsNullOrWhiteSpace(Email.Text)) { FieldError.SetError(Email, "Required Field"); } else { Email.ForeColor = Color.Red; FieldError.SetError(Email, "Invalid Email Address"); } } else { Email.ForeColor = Color.Black; FieldError.SetError(Email, ""); } }
private void Zip_Validated(object sender, EventArgs e) { if (!Validator.ValidateZipCode(Zip.Text)) { if (string.IsNullOrWhiteSpace(Zip.Text.Remove(5, 1).Trim())) { FieldError.SetError(Zip, "Required Field"); } else { Zip.ForeColor = Color.Red; FieldError.SetError(Zip, "Invalid Zip Code"); } } else { Zip.ForeColor = Color.Black; FieldError.SetError(Zip, ""); } }
private void Phone_Validated(object sender, EventArgs e) { if (!Validator.ValidatePhoneNumber(Phone.Text)) { if (string.IsNullOrWhiteSpace(Phone.Text.Replace("(", "") .Replace(")", "").Replace("-", "").Trim())) { FieldError.SetError(Phone, "Required Field"); } else { Phone.ForeColor = Color.Red; FieldError.SetError(Phone, "Invalid Phone Number"); } } else { Email.ForeColor = Color.Black; FieldError.SetError(Email, ""); } }
private void ClearForm() { // clear all fields firstName.Clear(); Minitial.Clear(); lastName.Clear(); Address1.Clear(); Address2.Clear(); City.Clear(); State.SelectedItem = null; Zip.Clear(); Gender.SelectedItem = null;; Phone.Clear(); Email.Clear(); Proof.SelectedItem = null; Date.Value = DateTime.Today; // clear errors FieldError.SetError(firstName, ""); FieldError.SetError(Minitial, ""); FieldError.SetError(lastName, ""); FieldError.SetError(Address1, ""); FieldError.SetError(Address2, ""); FieldError.SetError(City, ""); FieldError.SetError(State, ""); FieldError.SetError(Zip, ""); FieldError.SetError(Gender, ""); FieldError.SetError(Phone, ""); FieldError.SetError(Email, ""); FieldError.SetError(Proof, ""); FieldError.SetError(Date, ""); firstName.Select(); SetAddMode(); }
// Enables save function if all fields are valid and required fields have been entered and no duplicates. private void CanSave() { // check if all required fields have been filled bool valid_Entry = Validator.ValidateTextField(firstName.Text) && Validator.ValidateInitial(Minitial.Text) && Validator.ValidateTextField(lastName.Text) && Validator.ValidateTextField(Address1.Text) && Validator.ValidateTextField(City.Text) && Validator.ValidateComboBox(State.SelectedItem) && Validator.ValidateZipCode(Zip.Text) && Validator.ValidateComboBox(Gender.SelectedItem) && Validator.ValidatePhoneNumber(Phone.Text) && Validator.ValidateEmailAddress(Email.Text) && Validator.ValidateComboBox(Proof.SelectedItem) && Validator.ValidateDate(Date.Value); RebateRecord entered_Record = new RebateRecord(); if (curr_Mode == MODIFY && RebateList.SelectedItems.Count != 0) { entered_Record = new RebateRecord((RebateRecord)RebateList.SelectedItems[0].Tag); } entered_Record.firstName = firstName.Text; entered_Record.middleInitial = Minitial.Text; entered_Record.lastName = lastName.Text; entered_Record.Address1 = Address1.Text; entered_Record.Address2 = Address2.Text; entered_Record.City = City.Text; entered_Record.State = State.Text; entered_Record.Zip = new string(Zip.Text.Where(char.IsDigit).ToArray()); //zipcode should only be numbers entered_Record.Gender = Gender.Text; entered_Record.Phone = new string(Phone.Text.Where(char.IsDigit).ToArray()); // phone number should only have numbers entered_Record.Email = Email.Text; entered_Record.Proof = Proof.Text; entered_Record.Date = Date.Value; switch (curr_Mode) { case ADD: if (start_time.CompareTo(DateTime.MinValue) == 0) { start_time = DateTime.Now; } if (valid_Entry && !SearchListViewItem(RebateList, entered_Record)) //Duplicate records checked { Save.Enabled = true; FieldError.SetError(firstName, ""); FieldError.SetError(lastName, ""); FieldError.SetError(Phone, ""); } else { Save.Enabled = false; if (SearchListViewItem(RebateList, entered_Record)) { FieldError.SetError(firstName, "Found existing rebate with same name and phone number!"); FieldError.SetError(lastName, "Found existing rebate with same name and phone number!"); FieldError.SetError(Phone, "Found existing rebate with same name and phone number!"); } } break; case MODIFY: if (valid_Entry && !SearchListViewItem(RebateList, entered_Record)) { Save.Enabled = true; FieldError.SetError(firstName, ""); FieldError.SetError(lastName, ""); FieldError.SetError(Phone, ""); } else { Save.Enabled = false; if (SearchListViewItem(RebateList, entered_Record)) { FieldError.SetError(firstName, "Found existing rebate with same name and phone number!"); FieldError.SetError(lastName, "Found existing rebate with same name and phone number!"); FieldError.SetError(Phone, "Found existing rebate with same name and phone number!"); } } break; } }