コード例 #1
0
        /// <summary>
        /// Save all costs to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            EmployeeInformationTDS costInformationChanges = (EmployeeInformationTDS)Data.GetChanges();

            if (costInformationChanges.CostInformation.Rows.Count > 0)
            {
                EmployeeInformationCostInformationGateway employeeInformationCostInformationGateway = new EmployeeInformationCostInformationGateway(costInformationChanges);

                foreach (EmployeeInformationTDS.CostInformationRow row in (EmployeeInformationTDS.CostInformationDataTable)costInformationChanges.CostInformation)
                {
                    // Insert new costs
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        EmployeeCostHistory employeeCost = new EmployeeCostHistory(null);
                        employeeCost.InsertDirect(row.CostID, row.EmployeeID, row.Date, row.UnitOfMeasurement, row.PayRateCad, row.BurdenRateCad, row.TotalCostCad, row.PayRateUsd, row.BurdenRateUsd, row.TotalCostUsd, row.Deleted, row.COMPANY_ID, row.BenefitFactorCad, row.BenefitFactorUsd, row.HealthBenefitUsd);
                    }

                    // Update costs
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int costId = row.CostID;
                        int employeeId = row.EmployeeID;
                        bool originalDeleted = row.Deleted;
                        int originalCompanyId = companyId;

                        // original values
                        DateTime originalDate = employeeInformationCostInformationGateway.GetDateOriginal(costId, employeeId);
                        string originalUnitOfMeasurement = employeeInformationCostInformationGateway.GetUnitOfMeasurementOriginal(costId, employeeId);
                        decimal originalPayRateCad = employeeInformationCostInformationGateway.GetPayRateCadOriginal(costId, employeeId);
                        decimal originalBurdenRateCad = employeeInformationCostInformationGateway.GetBurdenRateCadOriginal(costId, employeeId);
                        decimal originalTotalCostCad = employeeInformationCostInformationGateway.GetTotalCostCadOriginal(costId, employeeId);
                        decimal originalPayRateUsd = employeeInformationCostInformationGateway.GetPayRateUsdOriginal(costId, employeeId);
                        decimal originalBurdenRateUsd = employeeInformationCostInformationGateway.GetBurdenRateUsdOriginal(costId, employeeId);
                        decimal originalTotalCostUsd = employeeInformationCostInformationGateway.GetTotalCostUsdOriginal(costId, employeeId);
                        decimal originalBenefitFactorCad = employeeInformationCostInformationGateway.GetBenefitFactorCadOriginal(costId, employeeId);
                        decimal originalBenefitFactorUsd = employeeInformationCostInformationGateway.GetBenefitFactorUsdOriginal(costId, employeeId);
                        decimal originalHealthBenefitUsd = employeeInformationCostInformationGateway.GetHealthBenefitUsdOriginal(costId, employeeId);

                        // new values
                        DateTime newDate = employeeInformationCostInformationGateway.GetDate(costId, employeeId);
                        string newUnitOfMeasurement = employeeInformationCostInformationGateway.GetUnitOfMeasurement(costId, employeeId);
                        decimal newPayRateCad = employeeInformationCostInformationGateway.GetPayRateCad(costId, employeeId);
                        decimal newBurdenRateCad = employeeInformationCostInformationGateway.GetBurdenRateCad(costId, employeeId);
                        decimal newTotalCostCad = employeeInformationCostInformationGateway.GetTotalCostCad(costId, employeeId);
                        decimal newPayRateUsd = employeeInformationCostInformationGateway.GetPayRateUsd(costId, employeeId);
                        decimal newBurdenRateUsd = employeeInformationCostInformationGateway.GetBurdenRateUsd(costId, employeeId);
                        decimal newTotalCostUsd = employeeInformationCostInformationGateway.GetTotalCostUsd(costId, employeeId);
                        decimal newBenefitFactorCad = employeeInformationCostInformationGateway.GetBenefitFactorCad(costId, employeeId);
                        decimal newBenefitFactorUsd = employeeInformationCostInformationGateway.GetBenefitFactorUsd(costId, employeeId);
                        decimal newHealthBenefitUsd = employeeInformationCostInformationGateway.GetHealthBenefitUsd(costId, employeeId);

                        EmployeeCostHistory employeeCost = new EmployeeCostHistory(null);
                        employeeCost.UpdateDirect(costId, employeeId, originalDate, originalUnitOfMeasurement, originalPayRateCad, originalBurdenRateCad, originalTotalCostCad, originalPayRateUsd, originalBurdenRateUsd, originalTotalCostUsd, originalDeleted, originalCompanyId, originalBenefitFactorCad, originalBenefitFactorUsd, originalHealthBenefitUsd, costId, employeeId, newDate, newUnitOfMeasurement, newPayRateCad, newBurdenRateCad, newTotalCostCad, newPayRateUsd, newBurdenRateUsd, newTotalCostUsd, originalDeleted, originalCompanyId, newBenefitFactorCad, newBenefitFactorUsd, newHealthBenefitUsd);
                    }

                    // Deleted costs
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        EmployeeCostHistory employeeCost = new EmployeeCostHistory(null);
                        employeeCost.DeleteDirect(row.CostID, row.EmployeeID, row.COMPANY_ID);
                    }
                }
            }
        }