/// <summary>
        /// Builds a list of columns whose values will be calculated depending on a specified aggregate function
        /// </summary>
        /// <param name="dsIndex"></param>
        /// <returns></returns>
        protected override BudgetColumnsCalculationsList GetCalculatedColumns(int dsIndex)
        {
            BudgetColumnsCalculationsList columnsList = new BudgetColumnsCalculationsList();

            switch (dsIndex)
            {
            //First dataset (on the first tab)
            case 0:
                columnsList.Add("CurrentHours", EBudgetCalculationMethod.eSUM);
                columnsList.Add("UpdateHours", EBudgetCalculationMethod.eSUM);
                columnsList.Add("NewHours", EBudgetCalculationMethod.eSUM);
                columnsList.Add("CurrentVal", EBudgetCalculationMethod.eSUM);
                columnsList.Add("UpdateVal", EBudgetCalculationMethod.eSUM);
                columnsList.Add("NewVal", EBudgetCalculationMethod.eSUM);
                break;

            //Second dataset (on the second tab)
            case 1:
                columnsList.Add("CurrentCost", EBudgetCalculationMethod.eSUM);
                columnsList.Add("UpdateCost", EBudgetCalculationMethod.eSUM);
                columnsList.Add("NewCost", EBudgetCalculationMethod.eSUM);
                columnsList.Add("CurrentSales", EBudgetCalculationMethod.eSUM);
                columnsList.Add("UpdateSales", EBudgetCalculationMethod.eSUM);
                columnsList.Add("NewSales", EBudgetCalculationMethod.eSUM);
                break;

            //Third dataset (on the third tab)
            case 2:
                break;

            default:
                throw new NotImplementedException("Undefinded dataset index: " + dsIndex);
            }
            return(columnsList);
        }
Exemple #2
0
        /// <summary>
        /// Sets null instead of acutal data for the first and second table
        /// </summary>
        /// <param name="sourceDS">the source dataset</param>
        protected override void RemoveNonCalculableValues(DataTable sourceTable, int dsIndex)
        {
            foreach (DataRow row in sourceTable.Rows)
            {
                BudgetColumnsCalculationsList columns = this.GetCalculatedColumns(dsIndex);
                foreach (KeyValuePair <string, EBudgetCalculationMethod> entry in columns)
                {
                    string columnName = entry.Key;

                    if (sourceTable.Columns[columnName].DataType == typeof(decimal))
                    {
                        row[columnName] = DBNull.Value;
                    }
                }
            }
        }
Exemple #3
0
        private void ApplyCurrencyForCostCenterTable(DataSet sourceDS, int associateCurrency, CurrencyConverter converter, int dsIndex)
        {
            DataTable sourceTable = sourceDS.Tables[2];

            //Cycle through each row of the cost center table
            foreach (DataRow row in sourceTable.Rows)
            {
                //Get the cost center currency for the current row
                int costCenterCurrency = (int)row["IdCurrency"];
                //If both currencies are the same, do nothing
                if (costCenterCurrency == associateCurrency)
                {
                    continue;
                }

                BudgetColumnsCalculationsList columns = this.GetCalculatedColumns(dsIndex);
                foreach (KeyValuePair <string, EBudgetCalculationMethod> entry in columns)
                {
                    //Get the current calculated column name
                    string columnName = entry.Key;
                    if (sourceTable.Columns[columnName].DataType == typeof(decimal))
                    {
                        //Gets the current value of the column
                        decimal val = (decimal)row[columnName];
                        //Get the parrent datarow
                        DataRow wpRow = GetParentWPRow(sourceTable.DataSet, row);
                        //Get the start year month and end year month for the currenct cost center
                        YearMonth startYearMonth = new YearMonth((int)wpRow["StartYearMonth"]);
                        YearMonth endYearMonth   = new YearMonth((int)wpRow["EndYearMonth"]);
                        //Calculate the existing value for each month in the date interval
                        int       numberOfMonths  = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1;
                        decimal[] yearMonthValues = Rounding.Divide(val, numberOfMonths);
                        decimal   newValue        = 0;
                        //Calculates the new value for each month and sum it
                        for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1))
                        {
                            int valueIterator = currentYearMonth.GetMonthsDiffrence(startYearMonth);
                            newValue += converter.GetConversionValue(yearMonthValues[valueIterator], costCenterCurrency, currentYearMonth, associateCurrency);
                        }
                        //Updates the value
                        row[columnName] = Rounding.Round(newValue);
                    }
                }
            }
        }
Exemple #4
0
        protected override BudgetColumnsCalculationsList GetCalculatedColumns(int dsIndex)
        {
            BudgetColumnsCalculationsList columnsList = new BudgetColumnsCalculationsList();

            switch (dsIndex)
            {
            case 0:
                columnsList.Add("TotalHours", EBudgetCalculationMethod.eSUM);
                columnsList.Add("Averate", EBudgetCalculationMethod.eAVG);
                columnsList.Add("ValuedHours", EBudgetCalculationMethod.eSUM);
                columnsList.Add("OtherCosts", EBudgetCalculationMethod.eSUM);
                columnsList.Add("Sales", EBudgetCalculationMethod.eSUM);
                columnsList.Add("NetCosts", EBudgetCalculationMethod.eSUM);
                break;

            default:
                throw new NotImplementedException("Undefinded dataset index: " + dsIndex);
            }
            return(columnsList);
        }
Exemple #5
0
        /// <summary>
        /// Updates a table using a child table and the associated agreagate functions
        /// </summary>
        /// <param name="parentTable">The parent table to be updated</param>
        /// <param name="childTable">The child table which contains the data needed for the calcultation</param>
        /// <param name="keyColumns">the columns that represents the logical key</param>
        /// <param name="dsIndex">The index of the dataset for which we are updating the parent table</param>
        protected void UpdateParentTableValues(DataTable parentTable, DataTable childTable, string[] keyColumns, int dsIndex)
        {
            foreach (string keyColumn in keyColumns)
            {
                if (!parentTable.Columns.Contains(keyColumn))
                {
                    throw new IndException(ApplicationMessages.EXCEPTION_COLUMN_MISSING);
                }
                if (!childTable.Columns.Contains(keyColumn))
                {
                    throw new IndException(ApplicationMessages.EXCEPTION_COLUMN_MISSING);
                }
            }
            BudgetColumnsCalculationsList calculatedColumns = GetCalculatedColumns(dsIndex);

            foreach (DataRow masterRow in parentTable.Rows)
            {
                foreach (KeyValuePair <string, EBudgetCalculationMethod> entry in calculatedColumns)
                {
                    masterRow[entry.Key] = 0;
                }
                int childRowCount = 0;
                foreach (DataRow childRow in childTable.Rows)
                {
                    bool isChildRow = true;
                    for (int i = 0; i < keyColumns.Length; i++)
                    {
                        if ((int)masterRow[keyColumns[i]] != (int)childRow[keyColumns[i]])
                        {
                            isChildRow = false;
                            break;
                        }
                    }

                    if (!isChildRow)
                    {
                        continue;
                    }
                    else
                    {
                        childRowCount++;
                    }

                    foreach (KeyValuePair <string, EBudgetCalculationMethod> entry in calculatedColumns)
                    {
                        if (parentTable.Columns[entry.Key].DataType == typeof(Decimal))
                        {
                            masterRow[entry.Key] = (decimal)masterRow[entry.Key] + (decimal)childRow[entry.Key];
                        }
                        else
                        {
                            masterRow[entry.Key] = (int)masterRow[entry.Key] + (int)childRow[entry.Key];
                        }
                    }
                }
                foreach (KeyValuePair <string, EBudgetCalculationMethod> entry in calculatedColumns)
                {
                    if (entry.Value == EBudgetCalculationMethod.eAVG && childRowCount != 0)
                    {
                        masterRow[entry.Key] = Rounding.Round((decimal)masterRow[entry.Key] / childRowCount);
                    }
                }
            }
        }