public EditApplicantDetails(Applicant applicant) { InitializeComponent(); ApplicantToUpdate = applicant; /* * I decide to make applicant first name, surname and pps number not opened to editing. * My reasoning is for security, i.e to prevent the averag staff member to be able * to change critical details without permission. I acknowledge that it is possible * to change one's own name. */ txtFirstName.Text = applicant.FirstName; txtSurname.Text = applicant.Surname; txtEmail.Text = applicant.Email; txtPhone.Text = applicant.Phone; txtAddressLine1.Text = applicant.AddressLine1; txtAddressLine2.Text = applicant.AddressLine2; txtCity.Text = applicant.City; cboCounties.Text = applicant.County; txtEircode.Text = applicant.Eircode; txtWeeklyNetPay.Text = applicant.WeeklyNetPay.ToString(); txtWeeklyOutgoings.Text = applicant.WeeklyOutgoings.ToString(); txtPPSNumber.Text = applicant.PPSNumber; }
public NewLoanDetails(Applicant applicant) { InitializeComponent(); txtCRN.Text = applicant.CRN.ToString(); txtFirstName.Text = applicant.FirstName; txtSurname.Text = applicant.Surname; txtPhone.Text = applicant.Phone; txtEmploymentStatus.Text = applicant.EmploymentStatus.ToString(); txtWeeklyNetPay.Text = applicant.WeeklyNetPay.ToString(); txtWeeklyOugoings.Text = applicant.WeeklyOutgoings.ToString(); txtCreditRating.Text = applicant.CreditRating; // new applicant has no outstanding loans with company rBtnNo.Checked = true; // getters and setters for crn, weekly net pay and credit rating CRN = applicant.CRN; WNP = applicant.WeeklyNetPay; CR = applicant.CreditRating; cboLoanType.DataSource = Enum.GetValues(typeof(LoanType)); }
// public method to pass over applicant details public bool PassApplicantDetails(Applicant applicant) { bool result = false; try { result = ApplicantDetails(applicant); } catch (Exception ex) { throw; } return result; }
//algorithim for determining credit rating private string CreditRating(Applicant loanapp) { string creditRating = String.Empty; EmploymentStatus employmentStatus = loanapp.EmploymentStatus; decimal weeklyNetPay = loanapp.WeeklyNetPay; if ((employmentStatus == EmploymentStatus.FullTime || employmentStatus == EmploymentStatus.PartTime) && (weeklyNetPay >= 500)) { creditRating = "A1"; } else if ((employmentStatus == EmploymentStatus.FullTime || employmentStatus == EmploymentStatus.PartTime) && (weeklyNetPay >= 400 && weeklyNetPay < 500)) { creditRating = "A2"; } else if ((employmentStatus == EmploymentStatus.FullTime || employmentStatus == EmploymentStatus.PartTime) && (weeklyNetPay >= 300 && weeklyNetPay < 400)) { creditRating = "B1"; } else if ((employmentStatus == EmploymentStatus.FullTime || employmentStatus == EmploymentStatus.PartTime) && (weeklyNetPay >= 275 && weeklyNetPay < 300)) { creditRating = "B2"; } else if ((employmentStatus == EmploymentStatus.FullTime || employmentStatus == EmploymentStatus.PartTime) && (weeklyNetPay < 275)) { creditRating = "C1"; } else if ((employmentStatus == EmploymentStatus.FTC) && (weeklyNetPay >= 375)) { creditRating = "B1"; } else if ((employmentStatus == EmploymentStatus.FTC) && (weeklyNetPay >= 315 && weeklyNetPay < 375)) { creditRating = "B2"; } else if ((employmentStatus == EmploymentStatus.FTC) && (weeklyNetPay < 315)) { creditRating = "C1"; } else if ((employmentStatus == EmploymentStatus.Unemployed) && (weeklyNetPay >= 400)) { creditRating = "B1"; } else if ((loanapp.EmploymentStatus == EmploymentStatus.Unemployed) && (weeklyNetPay < 400)) { creditRating = "C1"; } return creditRating; }
// method which sends applicant details to DAL private bool ApplicantDetails(Applicant la) { bool result = false; try { DALApplicantManager DALMngr = new DALApplicantManager(); la.CreditRating = CreditRating(la); result = DALMngr.PassApplicantDetailsToDB(la); } catch (Exception ex) { throw; } return result; }
public EditLoanDetails(Applicant applicant, Loan loan) { InitializeComponent(); LoanToUpdate = loan; AppSeekingLoanUpdate = applicant; txtFirstName.Text = applicant.FirstName; txtSurname.Text = applicant.Surname; txtEmail.Text = applicant.Email; txtPhone.Text = applicant.Phone; txtCRN.Text = applicant.CRN.ToString(); txtEmploymentStatus.Text = applicant.EmploymentStatus.ToString(); txtWeeklyNetPay.Text = applicant.WeeklyNetPay.ToString(); txtWeeklyOutgoings.Text = applicant.WeeklyOutgoings.ToString(); txtCreditRating.Text = applicant.CreditRating.ToString(); txtLRN.Text = loan.LRN.ToString(); dtpLoanApplicationDate.Value = loan.LoanApplicationDate; dtpLoanCommencementDate.Value = loan.LoanCommencementDate; txtATB.Text = loan.ATB.ToString(); //txtRepaymentPeriod.Text = loan.RepaymentPeriod.ToString(); cboRepaymentPeriod.Text = loan.RepaymentPeriod.ToString(); txtPaymentsMade.Text = loan.PaymentsMade.ToString(); txtMonthlyRepayment.Text = loan.MonthlyRepayment.ToString(); txtLoanBalance.Text = loan.LoanBalance.ToString(); txtLoanType.Text = loan.LoanType.ToString(); txtComments.Text = loan.Comments; if (loan.OutstandingLoans == true) { rBtnYes.Checked = true; } else { rBtnNo.Checked = true; } txtOutstandingLoansValue.Text = loan.OutstandingLoans.ToString(); }
// send updated applicant details to data access layer private bool UpdatedApplicantDetails(Applicant applicant) { bool result = false; try { applicant.CreditRating = CreditRating(applicant); DALApplicantManager DALMngr = new DALApplicantManager(); result = DALMngr.PassUpdatedApplicantDetailsToDB(applicant); } catch (Exception ex) { throw; } return result; }
// method which inserts applicant details into database private bool ApplicantDetailsToDB(Applicant applicant) { bool result = false; try { using (SqlConnection Cxn = new SqlConnection(CxnString)) { using (SqlCommand Cmd = new SqlCommand("spInsertApplicantDetails", Cxn)) { Cmd.CommandType = CommandType.StoredProcedure; SqlParameter InsertFirstNameParam = new SqlParameter("@firstname", SqlDbType.NVarChar, 20); SqlParameter InsertSurnameParam = new SqlParameter("@surname", SqlDbType.NVarChar, 20); SqlParameter InsertEmailParam = new SqlParameter("@email", SqlDbType.NVarChar, 20); SqlParameter InsertPhoneParam = new SqlParameter("@phone", SqlDbType.NVarChar, 20); SqlParameter InsertLine1Param = new SqlParameter("@line1", SqlDbType.NVarChar, 20); SqlParameter InsertLine2Param = new SqlParameter("@line2", SqlDbType.NVarChar, 20); SqlParameter InsertCityParam = new SqlParameter("@city", SqlDbType.NVarChar, 20); SqlParameter InsertCountyParam = new SqlParameter("@county", SqlDbType.NVarChar, 10); SqlParameter InsertEircodeParam = new SqlParameter("@eircode", SqlDbType.NVarChar, 10); SqlParameter InsertPPSParam = new SqlParameter("@pps", SqlDbType.NVarChar, 10); SqlParameter InsertStatusParam = new SqlParameter("@status", SqlDbType.Int, 4); SqlParameter InsertPayParam = new SqlParameter("@pay", SqlDbType.Decimal); SqlParameter InsertOutgoingsParam = new SqlParameter("@outgoings", SqlDbType.Decimal); SqlParameter InsertCRParam = new SqlParameter("@cr", SqlDbType.NVarChar, 2); SqlParameter InsertCRNParam = new SqlParameter("@crn", SqlDbType.Int, 4); InsertFirstNameParam.Value = applicant.FirstName; InsertSurnameParam.Value = applicant.Surname; InsertEmailParam.Value = applicant.Email; InsertPhoneParam.Value = applicant.Phone; InsertLine1Param.Value = applicant.AddressLine1; InsertLine2Param.Value = applicant.AddressLine2; InsertCityParam.Value = applicant.City; InsertCountyParam.Value = applicant.County; InsertEircodeParam.Value = applicant.Eircode; InsertPPSParam.Value = applicant.PPSNumber; InsertStatusParam.Value = applicant.EmploymentStatus; InsertPayParam.Value = applicant.WeeklyNetPay; InsertOutgoingsParam.Value = applicant.WeeklyOutgoings; InsertCRParam.Value = applicant.CreditRating; InsertCRNParam.Direction = ParameterDirection.Output; Cmd.Parameters.Add(InsertFirstNameParam); Cmd.Parameters.Add(InsertSurnameParam); Cmd.Parameters.Add(InsertEmailParam); Cmd.Parameters.Add(InsertPhoneParam); Cmd.Parameters.Add(InsertLine1Param); Cmd.Parameters.Add(InsertLine2Param); Cmd.Parameters.Add(InsertCityParam); Cmd.Parameters.Add(InsertCountyParam); Cmd.Parameters.Add(InsertEircodeParam); Cmd.Parameters.Add(InsertPPSParam); Cmd.Parameters.Add(InsertStatusParam); Cmd.Parameters.Add(InsertPayParam); Cmd.Parameters.Add(InsertOutgoingsParam); Cmd.Parameters.Add(InsertCRParam); Cmd.Parameters.Add(InsertCRNParam); Cxn.Open(); int i = Cmd.ExecuteNonQuery(); if (i > 0) { applicant.CRN = Convert.ToInt32(InsertCRNParam.Value); result = true; } else { result = false; } Cxn.Close(); } } return result; } catch (SqlException ex) { throw; } }
// sends updated applicant details to database private bool UpdatedApplicantDetailsToDB(Applicant applicant) { bool result = false; try { using (SqlConnection Cxn = new SqlConnection(CxnString)) { using (SqlCommand Cmd = new SqlCommand("spUpdateApplicantDetails", Cxn)) { Cmd.CommandType = CommandType.StoredProcedure; SqlParameter UpdateCRNParam = new SqlParameter("@crn", SqlDbType.Int, 4); SqlParameter UpdateEmailParam = new SqlParameter("@email", SqlDbType.NVarChar, 20); SqlParameter UpdatePhoneParam = new SqlParameter("@phone", SqlDbType.NVarChar, 20); SqlParameter UpdateLine1Param = new SqlParameter("@line1", SqlDbType.NVarChar, 20); SqlParameter UpdateLine2Param = new SqlParameter("@line2", SqlDbType.NVarChar, 20); SqlParameter UpdateCityParam = new SqlParameter("@city", SqlDbType.NVarChar, 20); SqlParameter UpdateCountyParam = new SqlParameter("@county", SqlDbType.NVarChar, 10); SqlParameter UpdateEircodeParam = new SqlParameter("@eircode", SqlDbType.NVarChar, 10); SqlParameter UpdateStatusParam = new SqlParameter("@status", SqlDbType.Int, 4); SqlParameter UpdatePayParam = new SqlParameter("@pay", SqlDbType.Decimal); SqlParameter UpdateOutgoingsParam = new SqlParameter("@outgoings", SqlDbType.Decimal); SqlParameter UpdateCRParam = new SqlParameter("@cr", SqlDbType.NVarChar, 2); UpdateCRNParam.Value = applicant.CRN; UpdateEmailParam.Value = applicant.Email; UpdatePhoneParam.Value = applicant.Phone; UpdateLine1Param.Value = applicant.AddressLine1; UpdateLine2Param.Value = applicant.AddressLine2; UpdateCityParam.Value = applicant.City; UpdateCountyParam.Value = applicant.County; UpdateEircodeParam.Value = applicant.Eircode; UpdateStatusParam.Value = applicant.EmploymentStatus; UpdatePayParam.Value = applicant.WeeklyNetPay; UpdateOutgoingsParam.Value = applicant.WeeklyOutgoings; UpdateCRParam.Value = applicant.CreditRating; Cmd.Parameters.Add(UpdateCRNParam); Cmd.Parameters.Add(UpdateEmailParam); Cmd.Parameters.Add(UpdatePhoneParam); Cmd.Parameters.Add(UpdateLine1Param); Cmd.Parameters.Add(UpdateLine2Param); Cmd.Parameters.Add(UpdateCityParam); Cmd.Parameters.Add(UpdateCountyParam); Cmd.Parameters.Add(UpdateEircodeParam); Cmd.Parameters.Add(UpdateStatusParam); Cmd.Parameters.Add(UpdatePayParam); Cmd.Parameters.Add(UpdateOutgoingsParam); Cmd.Parameters.Add(UpdateCRParam); Cxn.Open(); int i = Cmd.ExecuteNonQuery(); if (i > 0) { result = true; } else { result = false; } Cxn.Close(); } } } catch (SqlException ex) { throw; } return result; }
// public method calls private public bool PassUpdatedApplicantDetailsToDB(Applicant applicant) { bool result = false; try { result = UpdatedApplicantDetailsToDB(applicant); } catch (SqlException ex) { throw; } return result; }
// method which returns list of applicants from datbase private List<Applicant> GetAppList() { try { List<Applicant> AppList = new List<Applicant>(15); using (SqlConnection Cxn = new SqlConnection(CxnString)) { using (SqlCommand Cmd = new SqlCommand("spGetAllApplicants", Cxn)) { Cmd.CommandType = CommandType.StoredProcedure; Cxn.Open(); using (SqlDataReader dr = Cmd.ExecuteReader()) { while(dr.Read()) { string firstName = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_FirstName)).ToString(); string surname = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_Surname)).ToString(); string email= dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_Email)).ToString(); string phone = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_Phone)).ToString(); string addressLine1 = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_AddressLine1)).ToString(); string addressLine2 = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_AddressLine2)).ToString(); string city = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_City)).ToString(); string county = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_County)).ToString(); string eircode = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_Eircode)).ToString(); string ppsNumber = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_PPSNumber)).ToString(); EmploymentStatus empStatus = (EmploymentStatus)(Convert.ToInt32(dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_EmploymentStatus)))); decimal weeklyNetPay = Convert.ToDecimal(Convert.ToInt32(dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_WeeklyNetPay)))); decimal weeklyOutgoings = Convert.ToDecimal(Convert.ToInt32(dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_WeeklyOutings)))); int crn = Convert.ToInt32(dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_CRN))); string creditRating = dr.GetValue(Convert.ToInt32(LA_SPGetLoanApplicants.SPGetLoanApp_CreditRating)).ToString(); Applicant la = new Applicant(firstName, surname, email, phone, addressLine1, addressLine2, city, county, eircode, ppsNumber, empStatus, weeklyNetPay, weeklyOutgoings); la.CRN = crn; la.CreditRating = creditRating; AppList.Add(la); } dr.Close(); } } Cxn.Close(); } return AppList; } catch (SqlException ex) { 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; } } }