Пример #1
0
        /// <summary>
        /// DeleteAllDirect
        /// </summary>
        /// <param name="unitId">unitId</param>
        /// <param name="companyId">companyId</param>
        public void DeleteAllDirect(int unitId, int companyId)
        {
            // Delete exceptions
            UnitsCostHistoryExceptions unitsCostHistoryExceptions = new UnitsCostHistoryExceptions(null);
            unitsCostHistoryExceptions.DeleteAllDirect(unitId, companyId);

            // Delete costs
            UnitsCostHistoryGateway unitsCostHistoryGateway = new UnitsCostHistoryGateway(null);
            unitsCostHistoryGateway.DeleteAll(unitId, companyId);
        }
        /// <summary>
        /// Save all unit to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId, int unitId)
        {
            UnitInformationTDS costExceptionsInformationChanges = (UnitInformationTDS)Data.GetChanges();

            if (costExceptionsInformationChanges.CostExceptionsInformation.Rows.Count > 0)
            {
                UnitInformationCostExceptionsInformationGateway unitInformationCostExceptionsInformationGateway = new UnitInformationCostExceptionsInformationGateway(costExceptionsInformationChanges);

                foreach (UnitInformationTDS.CostExceptionsInformationRow row in (UnitInformationTDS.CostExceptionsInformationDataTable)costExceptionsInformationChanges.CostExceptionsInformation)
                {
                    // Insert new costs exceptions
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        UnitsCostHistoryExceptions unitsCostHistoryExceptions = new UnitsCostHistoryExceptions(null);
                        unitsCostHistoryExceptions.InsertDirect(row.CostID, row.RefID, unitId, row.Work_, row.UnitOfMeasurement, row.CostCad, row.CostUsd, row.Deleted, row.COMPANY_ID);
                    }

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

                        // original values
                        string originalWork = unitInformationCostExceptionsInformationGateway.GetWork_Original(costId, refId);
                        string originalUnitOfMeasurement = unitInformationCostExceptionsInformationGateway.GetUnitOfMeasurementOriginal(costId, refId);
                        decimal originalCostCad = unitInformationCostExceptionsInformationGateway.GetCostCadOriginal(costId, refId);
                        decimal originalCostUsd = unitInformationCostExceptionsInformationGateway.GetCostUsdOriginal(costId, refId);

                        // new values
                        string newWork = unitInformationCostExceptionsInformationGateway.GetWork_Original(costId, refId);
                        string newUnitOfMeasurement = unitInformationCostExceptionsInformationGateway.GetUnitOfMeasurement(costId, refId);
                        decimal newCostCad = unitInformationCostExceptionsInformationGateway.GetCostCad(costId, refId);
                        decimal newCostUsd = unitInformationCostExceptionsInformationGateway.GetCostUsd(costId, refId);

                        UnitsCostHistoryExceptions unitsCostHistoryExceptions = new UnitsCostHistoryExceptions(null);
                        unitsCostHistoryExceptions.UpdateDirect(costId, refId, unitId, originalWork, originalUnitOfMeasurement, originalCostCad, originalCostUsd, originalDeleted, originalCompanyId, costId, refId, unitId, newWork, newUnitOfMeasurement, newCostCad, newCostUsd, originalDeleted, originalCompanyId);
                    }

                    // Deleted costs exceptions
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        UnitsCostHistoryExceptions unitsCostHistoryExceptions = new UnitsCostHistoryExceptions(null);
                        unitsCostHistoryExceptions.DeleteDirect(row.CostID, row.RefID, row.COMPANY_ID);
                    }
                }
            }
        }