/// <summary> /// The primary button control that generates the salary breakdown in a display grid. /// 1) It checks whether the salary input is not empty, populates a model called employeedetails with the values associated with the employee. /// 2) Collects the addition and the deduction components that the user has added from the UI(form) in userAdditionComponents and userDeductionComponents lists respectively. /// 3) The method ComputeRules() computes the static components from the web.config and dynamic components from the form input on the salary input and stores them. /// 4) The method PopulateGrid() is responsible for filling the display grid with the calculated components (salary Breakdown) that is displayed to the user. /// 5) The method CollectTemplateData() is responsible for preparing the html template that will be sent to the employee. Values which are /// to be added to the template are represented by placeholders which are replaced with the actual values in the method flow. /// 6)The method SendTemplateData() is responsible for creating a pdf from the html template and setting up the smtp mail parameters to /// deliver the salary slip in pdf format to the employee. /// 7) The method DeleteSalarySlips() is responsible for deleting the salary slips from the local store as soon as the mail is delivered /// to the employee. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void generateButton_Click(object sender, EventArgs e) { ICollection <Rules> userAdditionComponents = null; ICollection <Rules> userDeductionComponents = null; if (salary.Text.ToString() != string.Empty) { decimal salaryAmount = Convert.ToDecimal(salary.Text); ISalaryService salaryService = new SalaryService(); EmployeeDetails employeeDetails = new EmployeeDetails(); employeeDetails.EmployeeName = requiredName.Text.ToString(); employeeDetails.DateOfJoining = dateOfJoining.Text.ToString(); employeeDetails.PanNumber = pan.Text.ToString(); employeeDetails.AccountNumber = accountNumber.Text.ToString(); employeeDetails.Designation = designation.Text.ToString(); employeeDetails.Salary = salary.Text.ToString(); employeeDetails.EmailId = email.Text.ToString(); employeeDetails.Month = month.SelectedItem.ToString(); employeeDetails.Year = year.SelectedItem.ToString(); if (addComponentNumber.Text != string.Empty) { List <Rules> userRules = new List <Rules>(); userRules = SegregateComponents(addComponentNumber, ComputationVariety.ADDITION, userRules); userAdditionComponents = FetchUserComponents(addOuterPanel.Controls, ComputationVariety.ADDITION, userRules); } if (deductComponentNumber.Text != string.Empty) { List <Rules> userRules = new List <Rules>(); userRules = SegregateComponents(deductComponentNumber, ComputationVariety.SUBTRACTION, userRules); userDeductionComponents = FetchUserComponents(deductOuterPanel.Controls, ComputationVariety.SUBTRACTION, userRules); } ICollection <Rules> computedRules = salaryService.ComputeRules(salaryAmount, userAdditionComponents, userDeductionComponents); ICollection <Rules> finalResults = PopulateGrid(computedRules, userAdditionComponents, userDeductionComponents); string templateContent = salaryService.CollectTemplateData(employeeDetails, finalResults); string pdfPath = salaryService.SendTemplate(employeeDetails, templateContent); salaryService.DeleteSalarySlips(pdfPath); //Mail Content; } }