/// <summary> /// Validates if Comboboxes have been clicked /// </summary> /// <returns>bool</returns> private bool IsCourseControlsChecked() { if (!(CBxCredits.SelectedIndex > -1) || !(CBxGrades.SelectedIndex > -1)) { if (!(CBxCredits.SelectedIndex > -1)) { EpForm.SetError(CBxCredits, "Credits not Selected"); } else { EpForm.SetError(CBxGrades, "Grade not Selected"); } return false; } return true; }
/// <summary> /// Submits a Course /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnSubmitCourse_Click(object sender, EventArgs e) { string grade, date = "", school, courseId, courseName, credits, empId; Control[] txtControls = { TxtCourseEmpId, TxtCollegeName, TxtCourseId, TxtCourseName}; //Control[] OtherControls = { CBxCredits, CBxGrades }; List<Control> txtControlErrors = valid.validateCourseData(txtControls); try { if (txtControlErrors.Count > 0 || !IsCourseControlsChecked()) { if (txtControlErrors.Count > 0) { foreach (var item in txtControlErrors) { if (item == TxtCollegeName) { EpForm.SetError(item, "Utah Valley University Only"); } else if (item == TxtCourseEmpId) { EpForm.SetError(item, "Invalid or non-existant ID"); } else if (item == TxtCourseId) { EpForm.SetError(item, "Invalid Course ID"); } else { if (item == TxtCourseName) { EpForm.SetError(item, "Invalid Course Name"); } } } } BlinkLabel("Course Was Not Added!", Color.Red, LblSucessCourse); } else { if (ChBxApproved.Checked) { date = DTPrApprovedData.Text; } else { date = "Course Not Approved"; } empId = TxtCourseEmpId.Text; school = TxtCollegeName.Text; courseId = TxtCourseId.Text; courseName = TxtCourseName.Text; credits = CBxCredits.SelectedItem.ToString(); grade = CBxGrades.SelectedItem.ToString(); businessRules.AddCourse(empId, school, courseId, courseName, credits, grade, date); ClearAddCourseInfo(); BlinkLabel("Course Sucessfully Added!", Color.Blue, LblSucessCourse); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
/// <summary> /// Starts Search for employee /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnSearch_Click(object sender, EventArgs e) { RTBxEmpInfo.Clear(); EpForm.Clear(); string output; if (RBtnSearchID.Checked || RBtnSearchLastName.Checked) { if (RBtnSearchID.Checked) { if (valid.ValidIDFormat(TxtSearchEmployee.Text)) { uint key = uint.Parse(TxtSearchEmployee.Text); Employee emp = businessRules[key]; output = businessRules.QueryEmpID(TxtSearchEmployee.Text); if (ChBxBenefits.Checked && ChBxCourses.Checked) { output = businessRules.QueryEmpID(TxtSearchEmployee.Text) + emp.DisplayBenefits() + emp.DisplayCourses(); } else if (ChBxBenefits.Checked) { output = businessRules.QueryEmpID(TxtSearchEmployee.Text) + emp.DisplayBenefits(); } else { if (ChBxCourses.Checked) { output = businessRules.QueryEmpID(TxtSearchEmployee.Text) + emp.DisplayCourses(); } } RTBxEmpInfo.AppendText(output); } else { EpForm.SetError(TxtSearchEmployee, "Invalid ID"); } } else { if (valid.ValidLastNameFormat(TxtSearchEmployee.Text)) { output = businessRules.QueryEmpLastName(TxtSearchEmployee.Text); if (ChBxBenefits.Checked && ChBxCourses.Checked) { output = businessRules.QueryLastNameBenefitsCourses(TxtSearchEmployee.Text); } else if (ChBxBenefits.Checked) { output = businessRules.QueryLastNamesWithBenefits(TxtSearchEmployee.Text); } else { output = businessRules.QueryLastNameWithCourses(TxtSearchEmployee.Text); } RTBxEmpInfo.AppendText(output); } else { EpForm.SetError(TxtSearchEmployee, "Invalid Last Name"); } } } else { if (!(RBtnSearchID.Checked || RBtnSearchLastName.Checked)) { EpForm.SetError(RBtnSearchID, "Choose One"); EpForm.SetError(RBtnSearchLastName, "Choose One"); } } }
/// <summary> /// validate user input controls /// </summary> /// <returns>true or false</returns> private bool IsValidTextBoxes() { string[] textBoxes = { TxtID.Text, TxtFirstName.Text, TxtLastName.Text, TxtAddress.Text, TxtCity.Text, TxtZip.Text, TxtHireDate.Text, TxtJobTitle.Text, TxtDept.Text}; string[] regExStrings = { "\\b\\d{6}\\b", "\\b[A-Z][a-z]+\\b", "\\b[A-Z][a-z]+\\b", "\\w+", "\\b[A-Z][a-z]+\\b", "\\b\\d{5}\\b", "\\b\\d{2}[/]\\d{2}[/]\\d{4}\\b", "\\w+", "\\w+" }; TextBox[] controls = { TxtID, TxtFirstName, TxtLastName, TxtAddress, TxtCity, TxtZip, TxtHireDate, TxtJobTitle, TxtDept }; Match match; int i = 0; bool isValid = true; //checks all textboxes not including type testboxes foreach (var item in textBoxes) { match = Regex.Match(item, regExStrings[i]); if (!match.Success || item == "") { if (item == "") { EpForm.SetError(controls[i], requiredMsg); } else { EpForm.SetError(controls[i], invalidField); } isValid = false; } i++; } if (CBxMarriageStatus.SelectedIndex == -1) { isValid = false; EpForm.SetError(CBxMarriageStatus, requiredMsg); } if (CBxEmpType.SelectedIndex == -1 || CBxState.SelectedIndex == -1) { isValid = false; if (CBxEmpType.SelectedIndex == -1) { EpForm.SetError(CBxEmpType, requiredMsg); } if(CBxState.SelectedIndex == -1) { EpForm.SetError(CBxState, requiredMsg); } } else //type combobox has been selected so now validate the textboxes { match = Regex.Match(TxtPayAmount.Text, @"(?:\d*\.)?\d+"); if (!match.Success) { isValid = false; EpForm.SetError(TxtPayAmount, invalidField); } if (CBxEmpType.SelectedIndex != (int)EType.SALARY || CBxEmpType.SelectedIndex != (int)EType.CONTRACT) { if (!match.Success) { isValid = false; EpForm.SetError(TxtSecondInput, invalidField); } } } return isValid; }