示例#1
0
        // method to get loan details from the form
        private Loan GetLoanDetailsFromForm()
        {
            int crn = int.Parse(txtCRN.Text.ToString());
            //DateTime loanAppDate = DateTime.Today; 
            DateTime loanComDate = DateTime.MaxValue;
            decimal atb = 0;
            int repayPeriod = 0;
            LoanType loanType = 0;
            string comments = String.Empty;
            validations = true;
            Validations validator = new Validations();

            Loan loan = null;
            try
            {
                // loan application date and loan application commencement date
                if (dtpLoanCommencementDate.Value > DateTime.Today)
                {
                    loanComDate = dtpLoanCommencementDate.Value;
                }
                else
                {
                    MessageBox.Show("Error: check loan application date and loan application commencement values");
                }

                // amount to be paid back
                if (txtATB.Text != null)
                {
                    //atb = decimal.Parse(txtATB.Text);
                    validations = decimal.TryParse(txtATB.Text, out atb);
                    if (!validations)
                    {
                        txtATB.Text = "Invalid Entry";
                        validations = false;
                    }
                }
                else
                {
                    MessageBox.Show("Error: must specify amount to be borrowed");
                }

                // repayment period
                if (cboRepaymentPeriod.SelectedItem != null)
                {
                    repayPeriod = int.Parse(cboRepaymentPeriod.SelectedItem.ToString());
                    
                }
                else
                {
                    MessageBox.Show("Error: must specify repayment period");
                }

                // loan type
                if (cboLoanType.SelectedItem != null)
                {
                    string loanT = cboLoanType.SelectedItem.ToString();
                    loanType = (LoanType)Enum.Parse(typeof(LoanType), loanT);
                }
                else
                {
                    MessageBox.Show("Error: must specify loan type");
                }

                // comments
                comments = txtComments.Text.ToString();

                loan = new Loan(crn, loanComDate, atb, repayPeriod, loanType, comments);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }

            return loan;

            
        }
        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;
            }
        }
        // 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;
                }
            }


        }