private EmployeeOutput GenerateEmployeeOutput(EmployeeInput employeeInput) { EmployeeOutput employeeOutput = new EmployeeOutput(); employeeOutput.Name = employeeInput.FirstName + " " + employeeInput.LastName; employeeOutput.PayPeriod = employeeInput.PaymentStartDate.ToString("dd/MMM/yyyy", CultureInfo.CreateSpecificCulture("en-US")) + " - " + (new DateTime(employeeInput.PaymentStartDate.Year, employeeInput.PaymentStartDate.Month, 1).AddMonths(1).AddDays(-1)).ToString("dd/MMM/yyyy", CultureInfo.CreateSpecificCulture("en-ES")); employeeOutput.GrossIncome = Math.Round(employeeInput.AnnualSalary / 12); employeeOutput.IncomeTax = Math.Round(SalaryCalculation.CalculateTax(employeeInput.AnnualSalary)); employeeOutput.NetIncome = Math.Round(employeeOutput.GrossIncome - employeeOutput.IncomeTax); employeeOutput.Super = Math.Round(employeeOutput.GrossIncome * (employeeInput.SuperRate / 100)); return(employeeOutput); }
private async void WriteOutputFileAsync() { try { saveFileDlg.Filter = "csv files (*.csv)|*.csv"; DialogResult dlgResult = saveFileDlg.ShowDialog(); if (saveFileDlg.FileName != null) { using (StreamWriter outfile = new StreamWriter(saveFileDlg.FileName)) { foreach (EmployeeInput ei in inputList) { EmployeeOutput eo = GenerateEmployeeOutput(ei); await outfile.WriteLineAsync(eo.Name + "," + eo.PayPeriod + "," + eo.GrossIncome + "," + eo.IncomeTax + "," + eo.NetIncome + "," + eo.Super); } } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace); } }