//Generate for all. private void Button_Click(object sender, RoutedEventArgs e) { //for this we have to take data from all the employees and then we have to if (cmbselectMonth.SelectedIndex > 0 && cmbselectyear.SelectedIndex > 0) { //First get all the employees. try { Datalayer dl = new Datalayer(); Response res = dl.GetAllEmployeesID(); if (res.success) { List <Employee> employees = (List <Employee>)res.body; for (int i = 0; i < employees.Count; i++) { //How we have the employee ID of all the employees so now let's start the game ! //we can fetch the salary components according to the employeeid Datalayer dla = new Datalayer(); Response response = dla.getEmployeeSalaryDetailsbyID(employees[i].employeeID); if (response.success) { SalaryComponents salaryComponents = new SalaryComponents(); salaryComponents = (SalaryComponents)response.body; //salaryComponents = (SalaryComponents)res.body; ////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/\/\/\/\/\/\/\/\/\/\/\/\/\//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ var Workbook = new XLWorkbook("SALARYCOMPONENTS.xlsx"); IXLWorksheet worksheet = Workbook.Worksheet("Sal Temp"); worksheet.Cell("B1").Value = salaryComponents.basic_plus_DA1; worksheet.Cell("B3").Value = salaryComponents.hra; worksheet.Cell("B4").Value = salaryComponents.conveyance1; worksheet.Cell("B5").Value = salaryComponents.productionIncentive1; worksheet.Cell("B6").Value = salaryComponents.food; worksheet.Cell("B7").Value = salaryComponents.allowance1; worksheet.Cell("B8").Value = salaryComponents.allowance2; worksheet.Cell("B14").Value = salaryComponents.allowance3_dailyrepory; worksheet.Cell("B15").Value = salaryComponents.allowance4; worksheet.Cell("B16").Value = salaryComponents.allowance5_telephone; worksheet.Cell("B17").Value = salaryComponents.allowance6; worksheet.Cell("B9").Value = salaryComponents.cea; worksheet.Cell("F15").Value = salaryComponents.overtimeRate; worksheet.Cell("F14").Value = salaryComponents.salary_package_attendance_bonus; worksheet.Cell("F7").Value = salaryComponents.ot_hours; worksheet.Cell("D4").Value = salaryComponents.tds_debits; worksheet.Cell("D5").Value = salaryComponents.otherdebits; worksheet.Cell("I13").Value = salaryComponents.late_attendance_debitrate; worksheet.Cell("D9").Value = salaryComponents.mobile_phone_credit; worksheet.Cell("D10").Value = salaryComponents.canteen_credit; worksheet.Cell("D13").Value = salaryComponents.medical_insurance; worksheet.Cell("D14").Value = salaryComponents.accidentql_insurance; worksheet.Cell("I17").Value = salaryComponents.early_attendance_bonus; worksheet.Cell("D18").Value = salaryComponents.severance_pakage; if (salaryComponents.optforEsi == 1) { worksheet.Cell("F1").Value = 1; } else { worksheet.Cell("F1").Value = 0; } if (salaryComponents.optforpf == 1) { worksheet.Cell("F2").Value = 1; } else { worksheet.Cell("F2").Value = 0; } ////Display the data now //txtBonus.Text = (worksheet.Cell("B2").Value).ToString(); //txtCommitmentAllowance.Text = (worksheet.Cell("B11").Value).ToString(); //txtGrossSalary.Text = (worksheet.Cell("B13").Value).ToString(); //txtPtaxDebits.Text = (worksheet.Cell("D3").Value).ToString(); //txtTotalDebits.Text = (worksheet.Cell("D6").Value).ToString(); //txtESIEmployerCredit.Text = (worksheet.Cell("D7").Value).ToString(); //txtPFEmployerCredit.Text = (worksheet.Cell("D8").Value).ToString(); //txtEarnedLeavecredit.Text = (worksheet.Cell("D11").Value).ToString(); //txtGratuity.Text = (worksheet.Cell("D12").Value).ToString(); //txttotalOtherCredits.Text = (worksheet.Cell("D15").Value).ToString(); //txtTakeHome.Text = (worksheet.Cell("D19").Value).ToString(); //txtsavingsalary.Text = (worksheet.Cell("D20").Value).ToString(); //txtnetsalary.Text = (worksheet.Cell("D21").Value).ToString(); //txtctc.Text = (worksheet.Cell("D22").Value).ToString(); //Now creating the particular Fields for the system //Create the folder for the employee string monthname = getCurrentMonth(); string year = getcurrentYear(); string nameofEMP = salaryComponents.employeeName; string pathfileabs = @"C:\PayrollManagerofCTPL\SalaryData\"; string path = pathfileabs + nameofEMP + @"\" + year + @"\" + monthname; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); //Thread.Sleep(100); } string filename = monthname + "" + year; string filepath = path + @"\" + filename + ".xlsx"; Workbook.SaveAs(filepath); GenerateSalaryOfEmployee generateSalaryOfEmployee = new ClassLibrary.MainClasses.GenerateSalaryOfEmployee(); generateSalaryOfEmployee.employeeID = salaryComponents.employeeID; generateSalaryOfEmployee.nameofEmployee = salaryComponents.employeeName; generateSalaryOfEmployee.monthName = monthname; generateSalaryOfEmployee.year = year; generateSalaryOfEmployee.pathFile = filepath; Datalayer datalayer = new Datalayer(); Response response1 = dl.savegeneratesalaryinDB(generateSalaryOfEmployee); if (response1.success) { } else if (res.isException) { MessageBox.Show("Error occured" + response1.exception); } //Workbook.SaveAs(@"C:\Users\Vikas\Desktop\Merci\file.xlsx"); } } } } catch (Exception ex) { MessageBox.Show("Exception on the front Page" + ex); } MessageBox.Show("Generated For all"); } else { MessageBox.Show("Choose Proper Month And Year In order to genearate the salary"); } }