Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the datasource for the InitialBudget
        /// </summary>
        /// <param name="wpList">The list on WP that the method should retreive data for</param>
        /// <param name="idAssociate">The associate for which the data is retrieved</param>
        /// <param name="idAssociateViewer">The associate currently viewing the budget</param>
        /// <returns>The source DataSet (of type Master-Detail-Detail) </returns>
        public DataSet GetInitialBudgetDataSource(int idAssociate, int idAssociateViewer, object connectionManager, bool isAssociateCurrency, int idProject, int idCountry, int idCurrency)
        {
            //Create the DataSet
            DataSet resultDS = new DataSet();

            try
            {
                //First create the Master Table

                InitialBudget baseBudget = new InitialBudget(connectionManager);
                baseBudget.IdAssociate         = idAssociate;
                baseBudget.IdAssociateViewer   = idAssociateViewer;
                baseBudget.IsAssociateCurrency = isAssociateCurrency;
                baseBudget.IdProject           = idProject;
                baseBudget.IdCountry           = idCountry;
                baseBudget.IdCurrency          = idCurrency;

                resultDS = baseBudget.GetAll(true);

                //The data set should return exactly 3 tables
                if (resultDS.Tables.Count != 3)
                {
                    throw new IndException(ApplicationMessages.EXCEPTION_NUMBER_OF_DETAIL_TABLES);
                }

                //Calculate the DateIntervalColumn
                CalculateDateIntervalColumn(resultDS.Tables[1], "DateInterval", "StartYearMonth", "EndYearMonth");
                RoundTableValues(resultDS.Tables[0], new string[] { "Averate", "ValuedHours", "OtherCosts", "Sales", "NetCosts" });
                RoundTableValues(resultDS.Tables[1], new string[] { "Averate", "ValuedHours", "OtherCosts", "Sales", "NetCosts" });
                RoundTableValues(resultDS.Tables[2], new string[] { "Averate", "ValuedHours", "OtherCosts", "Sales", "NetCosts" });
                //UpdateParentTableValues(tblPhases,tblWP, new string[] { "IdPhase"}, 0);
            }
            catch (Exception exc)
            {
                throw new IndException(exc);
            }
            //Return the data source
            return(resultDS);
        }
Exemplo n.º 3
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);
            }
        }