/// <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);
                }
            }
        }
예제 #2
0
        /// <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);
                            }
                        }
                    }
                }
            }
        }
        /// <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>
        /// <param name="oldTotalTakenVacationDays">oldTotalTakenVacationDays</param>
        /// <returns>requestId</returns>
        public int Save(double newTotalTakenVacationDays)
        {
            int requestId = 0;
            VacationsAddTDS vacationsAddChanges = (VacationsAddTDS)Data.GetChanges();

            if (vacationsAddChanges.RequestsInformation.Rows.Count > 0)
            {
                foreach (VacationsAddTDS.RequestsInformationRow row in (VacationsAddTDS.RequestsInformationDataTable)vacationsAddChanges.RequestsInformation)
                {
                    string comments = ""; if (!row.IsCommentsNull()) comments = row.Comments;

                    VacationRequests vacationRequests = new VacationRequests(null);
                    requestId = vacationRequests.InsertDirect(row.EmployeeID, row.StartDate, row.EndDate, row.TotalPaidVacationDays, row.State, comments, row.Details, "", "", row.Deleted, row.COMPANY_ID);

                    VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations();
                    vacationsEmployeeMaxPaidVacations.UpdateTotalTakenVacationDays(row.StartDate.Year, row.EmployeeID, newTotalTakenVacationDays);
                }
            }

            return requestId;
        }