示例#1
0
        /// <summary>
        /// Save the Initial Budget object by splitting it into several object accordin to
        /// startYearMonth and endYearMonth values.
        /// </summary>
        /// <param name="startYearMonth">The startYearMonth value</param>
        /// <param name="endYearMonth">The endYearMonth value</param>
        private void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, InitialBudgetOtherCosts otherCosts)
        {
            try
            {
                //Get the months difference
                int       monthsNo   = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1;
                int[]     totalHours = Rounding.Divide(this.TotalHours, monthsNo);
                decimal[] sales      = Rounding.Divide(this.Sales, monthsNo);
                decimal[] valHours   = Rounding.Divide(this.ValuedHours, monthsNo);
                int[]     detailsIds = new int[monthsNo];
                //Iterate through each month and construct the InitialBudget object
                for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1))
                {
                    //construct a new initial budget object
                    InitialBudget newBudget = new InitialBudget(this.CurrentConnectionManager);
                    newBudget.IdProject    = this.IdProject;
                    newBudget.IdPhase      = this.IdPhase;
                    newBudget.IdWP         = this.IdWP;
                    newBudget.IdCostCenter = this.IdCostCenter;
                    newBudget.IdAssociate  = this.IdAssociate;
                    newBudget.YearMonth    = currentYearMonth.Value;
                    newBudget.TotalHours   = totalHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)];
                    newBudget.ValuedHours  = valHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)];
                    newBudget.Sales        = sales[currentYearMonth.GetMonthsDiffrence(startYearMonth)];
                    if (this.State == EntityState.New)
                    {
                        newBudget.SetNew();
                    }
                    if (this.State == EntityState.Modified)
                    {
                        newBudget.SetModified();
                    }
                    if (this.State == EntityState.Deleted)
                    {
                        newBudget.SetDeleted();
                    }

                    //Saves the new budget
                    if (this.State == EntityState.New)
                    {
                        IdDetail = newBudget.Save();
                    }
                    else
                    {
                        newBudget.Save();
                    }
                }

                //Insert Other cost object
                if (otherCosts != null)
                {
                    otherCosts.SaveSplitted(startYearMonth, endYearMonth);
                }
            }
            catch (Exception exc)
            {
                throw new IndException(exc);
            }
        }
示例#2
0
        /// <summary>
        /// Save the Initial Budget object by splitting it into several object accordin to
        /// startYearMonth and endYearMonth values.
        /// </summary>
        /// <param name="startYearMonth">The startYearMonth value</param>
        /// <param name="endYearMonth">The endYearMonth value</param>
        private void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, InitialBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption)
        {
            try
            {
                //Get the months difference
                int       monthsNo   = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1;
                int[]     totalHours = Rounding.Divide(this.TotalHours, monthsNo);
                decimal[] sales      = Rounding.Divide(this.Sales, monthsNo);
                decimal[] valHours   = new decimal[monthsNo];
                if (this.ValuedHours != ApplicationConstants.DECIMAL_NULL_VALUE)
                {
                    valHours = Rounding.Divide(this.ValuedHours, monthsNo);
                }
                else
                {
                    for (int i = 0; i < monthsNo; i++)
                    {
                        valHours[i] = ApplicationConstants.DECIMAL_NULL_VALUE;
                    }
                }
                int[] detailsIds = new int[monthsNo];
                //Iterate through each month and construct the InitialBudget object
                for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1))
                {
                    //construct a new initial budget object
                    InitialBudget newBudget = new InitialBudget(this.CurrentConnectionManager);
                    newBudget.IdProject    = this.IdProject;
                    newBudget.IdPhase      = this.IdPhase;
                    newBudget.IdWP         = this.IdWP;
                    newBudget.IdCostCenter = this.IdCostCenter;
                    newBudget.IdAssociate  = this.IdAssociate;
                    newBudget.YearMonth    = currentYearMonth.Value;
                    newBudget.TotalHours   = totalHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)];
                    newBudget.ValuedHours  = valHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)];
                    newBudget.Sales        = sales[currentYearMonth.GetMonthsDiffrence(startYearMonth)];
                    if (this.State == EntityState.New)
                    {
                        newBudget.SetNew();
                    }
                    if (this.State == EntityState.Modified)
                    {
                        newBudget.SetModified();
                    }
                    if (this.State == EntityState.Deleted)
                    {
                        newBudget.SetDeleted();
                    }

                    //Apply the cost center currency if this is the case
                    if (isAssociateCurrency)
                    {
                        newBudget.ApplyCostCenterCurrency(associateCurrency, converter);
                    }
                    //Apply the amount scale
                    newBudget.ApplyAmountScaleOption(scaleOption);

                    //Saves the new budget
                    if (this.State == EntityState.New)
                    {
                        IdDetail = newBudget.Save();
                    }
                    else
                    {
                        newBudget.Save();
                    }
                }

                //Insert Other cost object
                if (otherCosts != null)
                {
                    otherCosts.SaveSplitted(startYearMonth, endYearMonth, isAssociateCurrency, this.IdCostCenter, associateCurrency, converter);
                }
            }
            catch (Exception exc)
            {
                throw new IndException(exc);
            }
        }