private bool ExistsDataModified() { foreach (GridViewRow row in grdVacationsSetup.Rows) { try { VacationsSetupTDS dataSet = new VacationsSetupTDS(); dataSet.VacationsSetup.Merge(vacationsSetup, true); VacationsSetupGateway model = new VacationsSetupGateway(dataSet); // Getting general information int year = Int32.Parse(grdVacationsSetup.DataKeys[row.RowIndex].Values["Year"].ToString()); int employeeId = Int32.Parse(grdVacationsSetup.DataKeys[row.RowIndex].Values["EmployeeID"].ToString()); // Verify vacation Days double newVacationDays = double.Parse(((TextBox)row.FindControl("tbxVacationDays")).Text); double originalVacationDays = model.GetVacationDaysOriginal(year, employeeId); if (newVacationDays != originalVacationDays) { return true; } else { // Verify carryOver days double newCarryOverDays = double.Parse(((TextBox)row.FindControl("tbxCarryOverDays")).Text); double originalCarryOverDays = model.GetCarryOverDaysOriginal(year, employeeId); if (newCarryOverDays != originalCarryOverDays) { return true; } } } catch { return true; } } return false; }
/// <summary> /// Save vacation setup to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { VacationsSetupTDS vacationSetupChanges = (VacationsSetupTDS)Data.GetChanges(); if (vacationSetupChanges != null) { if (vacationSetupChanges.VacationsSetup.Rows.Count > 0) { VacationsSetupGateway vacationsSetupGateway = new VacationsSetupGateway(vacationSetupChanges); foreach (VacationsSetupTDS.VacationsSetupRow row in (VacationsSetupTDS.VacationsSetupDataTable)vacationSetupChanges.VacationsSetup) { // Insert new vacation setup if (!row.InDatabase) { double totalTakenVacationDays = 0; VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations(null); vacationsEmployeeMaxPaidVacations.InsertDirect(row.Year, row.EmployeeID, row.VacationDays, totalTakenVacationDays, row.CarryOverDays, row.TotalVacationDays, false, companyId); } // Update vacation setup if (row.InDatabase) { int year = row.Year; int employeeId = row.EmployeeID; // ... original values double originalVacationDays = vacationsSetupGateway.GetVacationDaysOriginal(year, employeeId); double originalCarryOverDays = vacationsSetupGateway.GetCarryOverDaysOriginal(year, employeeId); double originalTotalVacationDays = vacationsSetupGateway.GetTotalVacationDaysOriginal(year, employeeId); // ... new values double newVacationDays = vacationsSetupGateway.GetVacationDays(year, employeeId); double newCarryOverDays = vacationsSetupGateway.GetCarryOverDays(year, employeeId); double newTotalVacationDays = vacationsSetupGateway.GetTotalVacationDays(year, employeeId); if ((originalVacationDays != newVacationDays) || (originalCarryOverDays != newCarryOverDays)) { VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations(null); vacationsEmployeeMaxPaidVacations.UpdateDirect(year, employeeId, originalVacationDays, row.TotalTakenVacationDays, originalCarryOverDays, originalTotalVacationDays, false, companyId, year, employeeId, newVacationDays, row.TotalTakenVacationDays, newCarryOverDays, newTotalVacationDays, false, companyId); } } } } } }