/// <summary> /// Save /// </summary> public void SaveForEdit(double newTakenDays) { VacationsInformationTDS vacationsInformationChanges = (VacationsInformationTDS)Data.GetChanges(); if (vacationsInformationChanges.RequestsInformation.Rows.Count > 0) { VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationChanges); foreach (VacationsInformationTDS.RequestsInformationRow row in (VacationsInformationTDS.RequestsInformationDataTable)vacationsInformationChanges.RequestsInformation) { int requestId = row.RequestID; int employeeId = row.EmployeeID; bool deleted = row.Deleted; int companyId = row.COMPANY_ID; // original values DateTime originalStartDate = vacationsInformationRequestsInformationGateway.GetStartDateOriginal(requestId); DateTime originalEndDate = vacationsInformationRequestsInformationGateway.GetEndDateOriginal(requestId); double originalTotalPaidVacationDays = vacationsInformationRequestsInformationGateway.GetTotalPaidVacationDaysOriginal(requestId); string originalState = vacationsInformationRequestsInformationGateway.GetStateOriginal(requestId); string originalComments = vacationsInformationRequestsInformationGateway.GetCommentsOriginal(requestId); string originalDetails = vacationsInformationRequestsInformationGateway.GetDetailsOriginal(requestId); string originalRejectReason = vacationsInformationRequestsInformationGateway.GetRejectReasonOriginal(requestId); string originalCancelReason = vacationsInformationRequestsInformationGateway.GetCancelReasonOriginal(requestId); bool originalDeleted = vacationsInformationRequestsInformationGateway.GetDeletedOriginal(requestId); // new values DateTime newStartDate = vacationsInformationRequestsInformationGateway.GetStartDate(requestId); DateTime newEndDate = vacationsInformationRequestsInformationGateway.GetEndDate(requestId); double newTotalPaidVacationDays = vacationsInformationRequestsInformationGateway.GetTotalPaidVacationDays(requestId); string newState = vacationsInformationRequestsInformationGateway.GetState(requestId); string newComments = vacationsInformationRequestsInformationGateway.GetComments(requestId); string newDetails = vacationsInformationRequestsInformationGateway.GetDetails(requestId); string newRejectReason = vacationsInformationRequestsInformationGateway.GetRejectReason(requestId); string newCancelReason = vacationsInformationRequestsInformationGateway.GetCancelReason(requestId); bool newDeleted = vacationsInformationRequestsInformationGateway.GetDeleted(requestId); VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations(); vacationsEmployeeMaxPaidVacations.UpdateTotalTakenVacationDays(row.StartDate.Year, row.EmployeeID, newTakenDays); VacationRequests vacationRequests = new VacationRequests(null); vacationRequests.UpdateDirect(requestId, employeeId, originalStartDate, originalEndDate, originalTotalPaidVacationDays, originalState, originalComments, originalDetails, originalRejectReason, originalCancelReason, originalDeleted, companyId, requestId, employeeId, newStartDate, newEndDate, newTotalPaidVacationDays, newState, newComments, newDetails, newRejectReason, newCancelReason, newDeleted, companyId); } } }
/// <summary> /// Save /// </summary> public void Save() { VacationsInformationTDS vacationsInformationChanges = (VacationsInformationTDS)Data.GetChanges(); if (vacationsInformationChanges.RequestsInformation.Rows.Count > 0) { VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationChanges); foreach (VacationsInformationTDS.RequestsInformationRow row in (VacationsInformationTDS.RequestsInformationDataTable)vacationsInformationChanges.RequestsInformation) { int requestId = row.RequestID; int employeeId = row.EmployeeID; bool deleted = row.Deleted; int companyId = row.COMPANY_ID; // original values DateTime originalStartDate = vacationsInformationRequestsInformationGateway.GetStartDateOriginal(requestId); DateTime originalEndDate = vacationsInformationRequestsInformationGateway.GetEndDateOriginal(requestId); double originalTotalPaidVacationDays = vacationsInformationRequestsInformationGateway.GetTotalPaidVacationDaysOriginal(requestId); string originalState = vacationsInformationRequestsInformationGateway.GetStateOriginal(requestId); string originalComments = vacationsInformationRequestsInformationGateway.GetCommentsOriginal(requestId); string originalDetails = vacationsInformationRequestsInformationGateway.GetDetailsOriginal(requestId); string originalRejectReason = vacationsInformationRequestsInformationGateway.GetRejectReasonOriginal(requestId); string originalCancelReason = vacationsInformationRequestsInformationGateway.GetCancelReasonOriginal(requestId); // new values DateTime newStartDate = vacationsInformationRequestsInformationGateway.GetStartDate(requestId); DateTime newEndDate = vacationsInformationRequestsInformationGateway.GetEndDate(requestId); double newTotalPaidVacationDays = vacationsInformationRequestsInformationGateway.GetTotalPaidVacationDays(requestId); string newState = vacationsInformationRequestsInformationGateway.GetState(requestId); string newComments = vacationsInformationRequestsInformationGateway.GetComments(requestId); string newDetails = vacationsInformationRequestsInformationGateway.GetDetails(requestId); string newRejectReason = vacationsInformationRequestsInformationGateway.GetRejectReason(requestId); string newCancelReason = vacationsInformationRequestsInformationGateway.GetCancelReason(requestId); if (newState == "Rejected" || newState == "Cancelled") { VacationsInformationBasicInformationGateway vacationsInformationBasicInformationGateway = new VacationsInformationBasicInformationGateway(); vacationsInformationBasicInformationGateway.LoadByEmployeeIdYear(employeeId, originalStartDate.Year, companyId); double oldTotalTakenVacationDays = vacationsInformationBasicInformationGateway.GetTotalVacationDays(employeeId, originalStartDate.Year) - vacationsInformationBasicInformationGateway.GetRemainingPayVacationDays(employeeId, originalStartDate.Year); VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations(); double newTotalTakenVacationDays = oldTotalTakenVacationDays - originalTotalPaidVacationDays; vacationsEmployeeMaxPaidVacations.UpdateTotalTakenVacationDays(row.StartDate.Year, row.EmployeeID, newTotalTakenVacationDays); } else { if (originalState == newState) { VacationsInformationBasicInformationGateway vacationsInformationBasicInformationGateway = new VacationsInformationBasicInformationGateway(); vacationsInformationBasicInformationGateway.LoadByEmployeeIdYear(employeeId, originalStartDate.Year, companyId); double oldTotalTakenVacationDays = vacationsInformationBasicInformationGateway.GetTotalVacationDays(employeeId, originalStartDate.Year) - vacationsInformationBasicInformationGateway.GetRemainingPayVacationDays(employeeId, originalStartDate.Year); VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations(); double newTotalTakenVacationDays = oldTotalTakenVacationDays + newTotalPaidVacationDays; vacationsEmployeeMaxPaidVacations.UpdateTotalTakenVacationDays(row.StartDate.Year, row.EmployeeID, newTotalTakenVacationDays); } } VacationRequests vacationRequests = new VacationRequests(null); vacationRequests.UpdateDirect(requestId, employeeId, originalStartDate, originalEndDate, originalTotalPaidVacationDays, originalState, originalComments, originalDetails, originalRejectReason, originalCancelReason, deleted, companyId, requestId, employeeId, newStartDate, newEndDate, newTotalPaidVacationDays, newState, newComments, newDetails, newRejectReason, newCancelReason, deleted, companyId); } } }
// //////////////////////////////////////////////////////////////////////// // PRIVATE METHODS // private void LoadData(int employeeId, int year, int requestId) { VacationsInformationBasicInformationGateway vacationsInformationBasicInformationGateway = new VacationsInformationBasicInformationGateway(vacationsInformationTDS); VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationTDS); tbxEmployee.Text = vacationsInformationBasicInformationGateway.GetEmployeeName(employeeId, year); tbxMax.Text = vacationsInformationBasicInformationGateway.GetTotalVacationDays(employeeId, year).ToString(); tbxRemaining.Text = vacationsInformationBasicInformationGateway.GetRemainingPayVacationDays(employeeId, year).ToString(); tbxComments.Text = vacationsInformationRequestsInformationGateway.GetComments(requestId); }