private void UpdateApplicantDetails() { Validations validations = new Validations(); bool result = false; bool isValid = true; bool payValid = true; try { // email of applicant if (txtEmail.Text != null) { if (validations.EmailValidation(txtEmail.Text.ToString())) { ApplicantToUpdate.Email = txtEmail.Text.ToString(); } else { isValid = false; txtEmail.Text = "Invalid Entry"; } } else { MessageBox.Show("Error: must specify email"); } // phone number of applicant if (txtPhone.Text != null) { if (validations.PhoneValidation(txtPhone.Text.ToString())) { ApplicantToUpdate.Phone = txtPhone.Text.ToString(); } else { isValid = false; txtPhone.Text = "Invalid Entry"; } } else { MessageBox.Show("Error: must specify phone number"); } // address line 1 of applicant if (txtAddressLine1.Text != null) { ApplicantToUpdate.AddressLine1 = txtAddressLine1.Text.ToString(); } else { MessageBox.Show("Error: must specify address line 1"); } // address line 2 of applicant if (txtAddressLine2.Text != null) { ApplicantToUpdate.AddressLine2 = txtAddressLine2.Text.ToString(); } else { MessageBox.Show("Error: must specify address line 2"); } // city of applicant if (txtCity.Text != null) { ApplicantToUpdate.City = txtCity.Text.ToString(); } else { MessageBox.Show("Error: must specify city"); } // county of applicant if (cboCounties.SelectedItem != null) { ApplicantToUpdate.County = cboCounties.SelectedItem.ToString(); } else { MessageBox.Show("Error: must specify county"); } // eircode of applicant if (txtEircode.Text != null) { ApplicantToUpdate.Eircode = txtEircode.Text.ToString(); } else { MessageBox.Show("Error: must specify eircode"); } // employment status of applicant if (rBtnFullTime.Checked) { ApplicantToUpdate.EmploymentStatus = EmploymentStatus.FullTime; } else if (rBtnPartTime.Checked) { ApplicantToUpdate.EmploymentStatus = EmploymentStatus.PartTime; } else if (rBtnFTC.Checked) { ApplicantToUpdate.EmploymentStatus = EmploymentStatus.FTC; } else if (rBtnUnemployed.Checked) { ApplicantToUpdate.EmploymentStatus = EmploymentStatus.Unemployed; } // weekly net pay of applicant if (txtWeeklyNetPay.Text != null) { decimal weeklyNetPay = 0; payValid = decimal.TryParse(txtWeeklyNetPay.Text, out weeklyNetPay); if (payValid) { ApplicantToUpdate.WeeklyNetPay = weeklyNetPay; } else { isValid = false; txtWeeklyNetPay.Text= "Invalid Entry"; } } else { MessageBox.Show("Error: must specify weekly net pay"); } // weekly outgoings of applicant if (txtWeeklyOutgoings != null) { decimal weeklyOutgoings = 0; payValid = decimal.TryParse(txtWeeklyOutgoings.Text, out weeklyOutgoings); if (payValid) { ApplicantToUpdate.WeeklyOutgoings = weeklyOutgoings; } else { isValid = false; txtWeeklyOutgoings.Text = "Invalid Entry"; } } else { MessageBox.Show("Error: must specify weekly outgoings"); } if (isValid) { BLLApplicantManager BLLMngr = new BLLApplicantManager(); result = BLLMngr.PassUpdatedApplicantDetails(ApplicantToUpdate); if (result == true) { MessageBox.Show("Applicant Details succesfully recorded"); OnApplicantAdded(true); this.Close(); } else { MessageBox.Show("Error: applicant details not recorded"); OnApplicantAdded(false); } } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
// button click to edit selected loan on datagridview private void editLoanToolStripMenuItem_Click(object sender, EventArgs e) { Loan loan = GetSelectedLoan(); int crn; Applicant app = null; if (dgvMainFormLoans.Visible == true && loan != null) { try { crn = loan.CRN; BLLApplicantManager BLLMngr = new BLLApplicantManager(); List<Applicant> ApplicantList = BLLMngr.CallGetListOfApplicants(); foreach (Applicant a in ApplicantList) { if(a.CRN == crn) { app = a; } } using (EditLoanDetails frmEditLoanDetails = new EditLoanDetails(app, loan)) { frmEditLoanDetails.OnLoanAdded += LoanAdded; frmEditLoanDetails.ShowDialog(); } } catch(Exception ex) { MessageBox.Show(ex.Message); throw; } } }
// method to sort applicants by county descending private void SortApplicantsByCountyDesc() { try { BLLApplicantManager BLLMngr = new BLLApplicantManager(); List<Applicant> ApplicantList = BLLMngr.CallGetListOfApplicants(); ApplicantList = ApplicantList.OrderByDescending((applicant) => applicant.County).ToList(); dgvMainFormLoans.Visible = false; dgvMainFormApplicant.Visible = true; dgvMainFormApplicant.DataSource = ApplicantList; ApplicantsInDGV = ApplicantList; } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
// method to find applicant by lrn private void SearchLRNNumber(int lrn) { try { BLLApplicantManager BLLMngrApp = new BLLApplicantManager(); List<Applicant> ApplicantList = BLLMngrApp.CallGetListOfApplicants(); BLLLoanManager BLLMngrLoan = new BLLLoanManager(); List<Loan> LoanList = BLLMngrLoan.CallGetListOfLoans(); Loan getLoan = null; foreach (Loan loan in LoanList) { if (loan.LRN == lrn) { getLoan = loan; } } int crn = getLoan.CRN; ApplicantList = ApplicantList.Where((applicant) => applicant.CRN == crn).ToList(); dgvMainFormLoans.Visible = false; dgvMainFormApplicant.Visible = true; dgvMainFormApplicant.DataSource = ApplicantList; ApplicantsInDGV = ApplicantList; } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
// method to find applicant by phone number private void SearchPhone(string phone) { try { BLLApplicantManager BLLMngr = new BLLApplicantManager(); List<Applicant> ApplicantList = BLLMngr.CallGetListOfApplicants(); ApplicantList = ApplicantList.Where((applicant) => applicant.Phone == phone).ToList(); dgvMainFormLoans.Visible = false; dgvMainFormApplicant.Visible = true; dgvMainFormApplicant.DataSource = ApplicantList; ApplicantsInDGV = ApplicantList; } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
// returns selected applicant object on datagridview private Applicant GetSelectedApplicant() { Applicant SelectApplicant = null; int crn = 0; int ColumnIndex = 0; int RowIndex = 0; try { if (dgvMainFormApplicant.SelectedRows.Count > 0) { BLLApplicantManager BLLMngr = new BLLApplicantManager(); List<Applicant> ApplicantList = BLLMngr.CallGetListOfApplicants(); RowIndex = dgvMainFormApplicant.SelectedRows[0].Index; crn = (int)dgvMainFormApplicant.Rows[RowIndex].Cells[ColumnIndex].Value; for (int i = 0; i < ApplicantList.Count; i++) { if (ApplicantList[i].CRN == crn) { SelectApplicant = ApplicantList[i]; break; } } } } catch(Exception ex) { MessageBox.Show(ex.Message); throw; } return SelectApplicant; }
//int crn, string firstName, string surname, string phone, EmploymentStatus empStatus, decimal weeklyNetPay, decimal weeklyOutgoings, string cr private void newLoanToolStripMenuItem1_Click(object sender, EventArgs e) { Applicant applicant = null; List<Applicant> appList = null; BLLApplicantManager BLLMngr = new BLLApplicantManager(); if (dgvMainFormApplicant.Visible == true) { applicant = GetSelectedApplicant(); } else if (dgvMainFormLoans.Visible == true) { Loan newLoan = GetSelectedLoan(); appList = BLLMngr.CallGetListOfApplicants(); foreach (Applicant a in appList) { if (a.CRN == newLoan.CRN) { applicant = a; } } } if (applicant != null) { using (NewLoanDetails frmNewLoan = new NewLoanDetails(applicant)) { frmNewLoan.OnLoanAdded += LoanAdded; frmNewLoan.ShowDialog(); } } }
// method which gets list of applicants from database and populates a datagridview with them private void PrimeApplicantListDGV() { try { BLLApplicantManager BLLMngr = new BLLApplicantManager(); List<Applicant> ApplicantList = BLLMngr.CallGetListOfApplicants(); dgvMainFormLoans.Visible = false; dgvMainFormApplicant.Visible = true; dgvMainFormApplicant.DataSource = ApplicantList; ApplicantsInDGV = ApplicantList; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// method to filter applicants by employment status private void FilterApplicantsByEmploymentStatus(EmploymentStatus status) { try { BLLApplicantManager BLLMngr = new BLLApplicantManager(); List<Applicant> ApplicantList = BLLMngr.CallGetListOfApplicants(); ApplicantList = ApplicantList.Where((applicant) => applicant.EmploymentStatus == status).ToList(); dgvMainFormLoans.Visible = false; dgvMainFormApplicant.Visible = true; dgvMainFormApplicant.DataSource = ApplicantList; ApplicantsInDGV = ApplicantList; } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
// method for creating new applicant object private void CreateNewApplicant() { // applicant constructor with parameters used to create object // these variable shall be assigned values and passed into said constructor string firstName = String.Empty; string surname = String.Empty; string email = String.Empty; string phone = String.Empty; string addressLine1 = String.Empty; string addressLine2 = String.Empty; string city = String.Empty; string county = String.Empty; string eircode = String.Empty; string ppsNumber = String.Empty; EmploymentStatus employmentStatus = 0; decimal weeklyNetPay = 0; decimal weeklyOutgoings = 0; //bool isValid = false; bool validations = true; bool isValid = true; // bool variable which will be returned from the DAL layer // bool result = false; Validations validator = new Validations(); // first name of applicant if (txtFirstName.Text != null) { firstName = txtFirstName.Text.ToString(); validations = validator.NameValidation(firstName); if (!validations) { txtFirstName.Text = "Invalid Entry"; isValid = false; } } else { MessageBox.Show("Error: must specify first name"); } // surname of applicant if (txtSurname.Text != null) { surname = txtSurname.Text.ToString(); validations = validator.NameValidation(surname); if (!validations) { txtSurname.Text = "Invalid Email Address"; isValid = false; } } else { MessageBox.Show("Error: must specify surname"); } // email of applicant if (txtEmail.Text != null) { email = txtEmail.Text.ToString(); validations = validator.EmailValidation(email); if (!validations) { txtEmail.Text = "Invalid Entry: Only Digits Allowed/ No Sapces"; isValid = false; } } else { MessageBox.Show("Error: must specify email"); } // phone number of applicant if (txtPhone.Text != null) { phone = txtPhone.Text.ToString(); validations = validator.PhoneValidation(phone); if (!validations) { txtPhone.Text = "Invalid Entry"; isValid = false; } } else { MessageBox.Show("Error: must specify phone number"); } // address line 1 of applicant if(txtAddressLine1.Text != null) { addressLine1 = txtAddressLine1.Text.ToString(); } else { MessageBox.Show("Error: must specify address line 1"); } // address line 2 of applicant if (txtAddressLine2.Text != null) { addressLine2 = txtAddressLine2.Text.ToString(); } else { MessageBox.Show("Error: must specify address line 2"); } // city of applicant if (txtCity.Text != null) { city = txtCity.Text.ToString(); } else { MessageBox.Show("Error: must specify city"); } // county of applicant if (cboCounties.SelectedItem != null) { county = cboCounties.SelectedItem.ToString(); } else { MessageBox.Show("Error: must specify county"); } // eircode of applicant if (txtEircode.Text != null) { eircode = txtEircode.Text.ToString(); } else { MessageBox.Show("Error: must specify eircode"); } // PPS Number of applicant if (txtPPSNumber.Text != null) { ppsNumber = txtPPSNumber.Text.ToString(); } else { MessageBox.Show("Error: must specify PPS Number"); } // employment status of applicant if (rBtnFullTime.Checked) { employmentStatus = EmploymentStatus.FullTime; } else if (rBtnPartTime.Checked) { employmentStatus = EmploymentStatus.PartTime; } else if (rBtnFTC.Checked) { employmentStatus = EmploymentStatus.FTC; } else if (rBtnUnemployed.Checked) { employmentStatus = EmploymentStatus.Unemployed; } // weekly net pay of applicant if (txtWeeklyNetPay.Text != null) { //weeklyNetPay = decimal.Parse(txtWeeklyNetPay.Text); validations = decimal.TryParse(txtWeeklyNetPay.Text, out weeklyNetPay); if (!validations) { txtWeeklyNetPay.Text = "Invalid Entry"; isValid = false; } } else { MessageBox.Show("Error: must specify weekly net pay"); } // weekly outgoings of applicant if (txtWeeklyOutgoings != null) { //weeklyOutgoings = decimal.Parse(txtWeeklyOutgoings.Text); validations = decimal.TryParse(txtWeeklyOutgoings.Text, out weeklyNetPay); if (!validations) { txtWeeklyOutgoings.Text = "Invalid Entry"; isValid = false; } } else { MessageBox.Show("Error: must specify weekly outgoings"); } if (isValid == true) { // applicant object Applicant applicant = new Applicant(firstName, surname, email, phone, addressLine1, addressLine2, city, county, eircode, ppsNumber, employmentStatus, weeklyNetPay, weeklyOutgoings); try { BLLApplicantManager BLLMngr = new BLLApplicantManager(); result = BLLMngr.PassApplicantDetails(applicant); if (result == true) { MessageBox.Show("Applicant Details succesfully recorded"); // assign applicant details to NewApplicant to pass info over to next form NewApplicant = applicant; // eventhandler OnApplicantAdded(true); btnSubmit.Enabled = false; btnClear.Enabled = false; btnNext.Enabled = true; } else { MessageBox.Show("Error: applicant details not recorded"); OnApplicantAdded(false); } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } } }