/// <summary> /// Apply a given amount scale option to the current object value /// </summary> /// <param name="scaleOption">The amount scale to be applied</param> public override void ApplyAmountScaleOption(AmountScaleOption scaleOption) { try { //Calculate the multiplier int multiplier = 1; for (int i = 1; i <= (int)scaleOption; i++) { multiplier *= 1000; } //Update the values if (_ValuedHours != ApplicationConstants.DECIMAL_NULL_VALUE) { _ValuedHours *= multiplier; } if (_Sales != ApplicationConstants.DECIMAL_NULL_VALUE) { _Sales *= multiplier; } } catch (Exception exc) { throw new IndException(exc); } }
/// <summary> /// Converts the edited cc list from an old amount scale option to Unit amount scale by passing through a new one /// The old scale must be greater than the new one /// </summary> /// <param name="oldOption"></param> /// <param name="newOption"></param> /// <param name="htValues"></param> public override void ApplyAmountScaleOptionToHT(AmountScaleOption oldOption, AmountScaleOption newOption, List <InitialBudget> htValues) { try { //Gets the diffrence between scales int scaleDif = oldOption - newOption; decimal multiplier = 1; if (scaleDif == 0) { return; } for (int i = 1; i <= scaleDif; i++) { multiplier *= 1000; } foreach (InitialBudget iBudget in htValues) { iBudget.ValuedHours = (iBudget.ValuedHours == ApplicationConstants.DECIMAL_NULL_VALUE) ? ApplicationConstants.DECIMAL_NULL_VALUE : Rounding.Round(Decimal.Multiply((decimal)iBudget.ValuedHours, multiplier)); iBudget.Sales = (iBudget.Sales == ApplicationConstants.DECIMAL_NULL_VALUE) ? ApplicationConstants.DECIMAL_NULL_VALUE : Rounding.Round(Decimal.Multiply((decimal)iBudget.Sales, multiplier)); } } catch (Exception exc) { throw new IndException(exc); } }
/// <summary> /// load amount combo /// </summary> private void LoadAmountScaleOption(AmountScaleOption amountScaleOption) { cmbAmountScaleOption.Items.Clear(); cmbAmountScaleOption.Items.Add(new RadComboBoxItem("Unit", ((int)AmountScaleOption.Unit).ToString())); cmbAmountScaleOption.Items.Add(new RadComboBoxItem("Thousands", ((int)AmountScaleOption.Thousands).ToString())); cmbAmountScaleOption.Items.Add(new RadComboBoxItem("Millions", ((int)AmountScaleOption.Millions).ToString())); }
public UserSettings(int associateId, object connectionManager) : base(connectionManager) { this._AssociateId = associateId; this._NumberOfRecordsPerPage = ApplicationConstants.DEFAULT_DATAGRID_PAGESIZE; this._AmountScaleOption = AmountScaleOption.Unit; this._CurrencyRepresentation = CurrencyRepresentationMode.CostCenter; }
/// <summary> /// /// </summary> /// <param name="associateId"></param> /// <param name="amountScaleOption"></param> /// <param name="numberOfRecordsPerPage"></param> /// <param name="currencyRepresentation"></param> public UserSettings(int associateId, AmountScaleOption amountScaleOption, int numberOfRecordsPerPage, CurrencyRepresentationMode currencyRepresentation, object connectionManager) : base(connectionManager) { this._AssociateId = associateId; this._AmountScaleOption = amountScaleOption; this._CurrencyRepresentation = currencyRepresentation; this._NumberOfRecordsPerPage = numberOfRecordsPerPage; }
private int GetMultiplier() { if (String.IsNullOrEmpty(this.Request.QueryString["AmountScaleOption"])) { throw new IndException(ApplicationMessages.MessageWithParameters(ApplicationMessages.EXCEPTION_COULD_NOT_GET_PARAMETER, "AmountScaleOption")); } AmountScaleOption amountScaleOption = BudgetUtils.GetAmountScaleOptionFromText(this.Request.QueryString["AmountScaleOption"]); int multiplier = 1; for (int i = 1; i <= (int)amountScaleOption; i++) { multiplier *= 1000; } return(multiplier); }
protected void btnApply_Click(object sender, ImageClickEventArgs e) { try { #region Build Object //Gets the amount scale AmountScaleOption scaleOption = BudgetUtils.GetAmountScaleOptionFromText(this.Request.QueryString["AmountScaleOption"]); int multiplier = 1; //Find out the number that will be used to multiply the values with for (int i = 1; i <= (int)scaleOption; i++) { multiplier *= 1000; } //Build the object from the screen values InitialBudgetOtherCosts otherCosts = SessionManager.GetSessionValueNoRedirect(this, SessionStrings.INITIAL_OTHER_COSTS) as InitialBudgetOtherCosts; otherCosts.TE = (txtTE.Text == String.Empty) ? ApplicationConstants.DECIMAL_NULL_VALUE : decimal.Parse(txtTE.Text) * multiplier; otherCosts.ProtoParts = (txtProtoParts.Text == String.Empty) ? ApplicationConstants.DECIMAL_NULL_VALUE : decimal.Parse(txtProtoParts.Text) * multiplier; otherCosts.ProtoTooling = (txtProtoTooling.Text == String.Empty) ? ApplicationConstants.DECIMAL_NULL_VALUE : decimal.Parse(txtProtoTooling.Text) * multiplier; otherCosts.Trials = (txtTrials.Text == String.Empty) ? ApplicationConstants.DECIMAL_NULL_VALUE : decimal.Parse(txtTrials.Text) * multiplier; otherCosts.OtherExpenses = (txtOtherExpenses.Text == String.Empty) ? ApplicationConstants.DECIMAL_NULL_VALUE : decimal.Parse(txtOtherExpenses.Text) * multiplier; //Add object to session SessionManager.AddOtherCosts(this, otherCosts); #endregion Buidl Object //Close the page if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "ButtonClickScript")) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ButtonClickScript", "window.returnValue = 1; window.close();", true); } } catch (IndException exc) { ShowError(exc); return; } catch (Exception exc) { ShowError(new IndException(exc)); return; } }
/// <summary> /// Applay the scale option to an existing datasource(to all decimal columns). /// If the newOption is greater than the oldOption, than the datasource need /// to be expressed in Unit scale /// </summary> /// <param name="oldOption">The old scale option</param> /// <param name="newOption">The new scale optin</param> /// <param name="initialTable">The table that will be transformed</param> public void ApplyAmountScaleOptionToDataSource(AmountScaleOption oldOption, AmountScaleOption newOption, DataTable initialTable) { try { //Gets the diffrence between scales int scaleDif = oldOption - newOption; if ((scaleDif > 0) && (oldOption != AmountScaleOption.Unit)) { throw new IndException(ApplicationMessages.EXCEPTION_PRECISION_LOST_ON_CONVERT); } //The number that will be used to multiplay the values from the data source decimal transformInd = 1; //Represents the sign that will be used for multiplay decimal multiplier = (scaleDif > 0) ? 1000 : (decimal)1 / 1000; //Calculates the transform indice for (int i = 0; i < Math.Abs(scaleDif); i++) { transformInd *= multiplier; } //Gets the decimal columns in the table foreach (DataColumn column in initialTable.Columns) { if (column.DataType == typeof(decimal)) { //Update the value for all rows foreach (DataRow row in initialTable.Rows) { if (row[column] != DBNull.Value) { row[column] = Rounding.Round(Decimal.Multiply((decimal)row[column], transformInd)); } } } } } catch (Exception ex) { throw new IndException(ex); } }
/// <summary> /// Apply a given amount scale option to the current object value /// </summary> /// <param name="scaleOption">The amount scale to be applied</param> public override void ApplyAmountScaleOption(AmountScaleOption scaleOption) { try { //If the value of New is DECIMAL_NULL_VALUE, do not perform any conversion if (_New == ApplicationConstants.DECIMAL_NULL_VALUE) { return; } //Calculate the multiplier int multiplier = 1; for (int i = 1; i <= (int)scaleOption; i++) { multiplier *= 1000; } _New *= multiplier; } catch (Exception ex) { throw new IndException(ex); } }
/// <summary> /// Saves the budgets from budgetList to the database, applying an exchange rate conversion /// </summary> /// <param name="budgetList">list of ReforecastBudget objects to be saved to the database</param> /// <param name="displayedDataType">the type of data to be saved (one of the values in the Constants region)</param> /// <param name="amountScaleOption">the amount scale in which the data is represented</param> /// <param name="associateCurrency">the currency of the associate saving the budget</param> /// <param name="converter">converter object used to exchange values from one currency to another</param> public void SaveAll(List <ReforecastBudget> budgetList, int displayedDataType, AmountScaleOption amountScaleOption, int associateCurrency, CurrencyConverter converter) { //Begin the transaction BeginTransaction(); try { foreach (ReforecastBudget budget in budgetList) { budget.UpdateMasterRecord(); budget.ApplyAmountScaleOption(amountScaleOption); if (displayedDataType > DATA_VALUE_HOURS) { budget.ApplyCostCenterCurrency(associateCurrency, converter); } budget.UpdateDetail(displayedDataType); } //Commit the transaction CommitTransaction(); } catch (Exception ex) { //If, for any reason, an exception was thrown, rollback the transaction RollbackTransaction(); throw new IndException(ex); } }
/// <summary> /// Saves the budgets from budgetList to the database /// </summary> /// <param name="budgetList">list of ReforecastBudget objects to be saved to the database</param> /// <param name="displayedDataType">the type of data to be saved (one of the values in the Constants region)</param> /// <param name="amountScaleOption">the amount scale in which the data is represented</param> public void SaveAll(List <ReforecastBudget> budgetList, int displayedDataType, AmountScaleOption amountScaleOption) { //Begin the transaction BeginTransaction(); try { foreach (ReforecastBudget budget in budgetList) { budget.UpdateMasterRecord(); budget.ApplyAmountScaleOption(amountScaleOption); budget.UpdateDetail(displayedDataType); } //Commit the transaction CommitTransaction(); } catch (Exception ex) { //If, for any reason, an exception was thrown, rollback the transaction RollbackTransaction(); throw new IndException(ex); } }
/// <summary> /// Save the Revised Budget object by splitting it into several object according to /// startYearMonth and endYearMonth values. /// </summary> /// <param name="startYearMonth">The startYearMonth value</param> /// <param name="endYearMonth">The endYearMonth value</param> /// <param name="otherCosts">other costs object that will be saved if it is not null</param> /// <param name="isAssociateCurrency">specifies if a conversion must be made from the associate currency to the cost center currency before saving</param> /// <param name="associateCurrency">the id of the associate currency</param> /// <param name="converter">the currency converter object to be used for the currency conversion</param> /// <param name="scaleOption">the amount scale from the budget interface (if it is not unit, a multiplication must be made before saving)</param> private void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, RevisedBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption) { //TODO: Implement transactions //Get the months difference int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; int[] newHours = Rounding.Divide(this.NewHours, monthsNo); decimal[] newSales = Rounding.Divide(this.NewSales, 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 revised budget object RevisedBudget newBudget = new RevisedBudget(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.NewHours = newHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.NewSales = newSales[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.SaveHours = this.SaveHours; 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 int idNewBudget = newBudget.Save(); } //Insert Other cost object if (otherCosts != null) { otherCosts.SaveSplitted(startYearMonth, endYearMonth, isAssociateCurrency, this.IdCostCenter, associateCurrency, converter); } }
/// <summary> /// Updates the budget (transactions enabled) /// </summary> /// <param name="startYearMonth"></param> /// <param name="endYearMonth"></param> /// <param name="otherCosts"></param> /// <param name="isAssociateCurrency"></param> /// <param name="associateCurrency"></param> /// <param name="converter"></param> /// <param name="scaleOption"></param> public void UpdateBudget(YearMonth startYearMonth, YearMonth endYearMonth, InitialBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption, bool insertMasterRecord) { BeginTransaction(); try { if (insertMasterRecord) { InsertMasterRecord(); } SaveSplitted(startYearMonth, endYearMonth, otherCosts, isAssociateCurrency, associateCurrency, converter, scaleOption); CommitTransaction(); } catch (Exception exc) { RollbackTransaction(); throw new IndException(exc); } }
/// <summary> /// Applyes the given amount scale to the object values /// </summary> /// <param name="scaleOption">The Amount Scale Option to be applyed</param> public virtual void ApplyAmountScaleOption(AmountScaleOption scaleOption) { }
/// <summary> /// Applay the scale option to an existing hash table(to all decimal columns). /// If the newOption is greater than the oldOption, than the datasource need /// to be expressed in Unit scale /// </summary> /// <param name="oldOption">The old scale option</param> /// <param name="newOption">The new scale optin</param> /// <param name="initialTable">The table that will be transformed</param> public virtual void ApplyAmountScaleOptionToHT(AmountScaleOption oldOption, AmountScaleOption newOption, List <InitialBudget> htValues) { }
/// <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); } }
/// <summary> /// Saves the revised budget to the database /// </summary> /// <param name="startYearMonth">start yearmonth of the work package associated to this budget entry (cost center)</param> /// <param name="endYearMonth">end yearmonth of the work package associated to this budget entry (cost center)</param> /// <param name="otherCosts">other costs object which is saved to the database</param> /// <param name="isAssociateCurrency">specifies whether the data is in the currency of the associate /// (if this is the case, the values must be converted to the cost center currency before saving)</param> /// <param name="associateCurrency">the currency of the associate</param> /// <param name="converter">the converter object used to convert values between currencies</param> /// <param name="scaleOption">the scale option in which the values are represented (if it is different than unit, it will be /// converted before saving)</param> /// <param name="insertMasterRecord">specifies whether a master record will be inserted in the BUDGET_REVISED table</param> public void SaveBudget(YearMonth startYearMonth, YearMonth endYearMonth, RevisedBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption, bool insertMasterRecord) { //Begin the transaction BeginTransaction(); try { //Insert the master record only if it is necessary if (insertMasterRecord) { InsertMasterRecord(); } //Save the budget SaveSplitted(startYearMonth, endYearMonth, otherCosts, isAssociateCurrency, associateCurrency, converter, scaleOption); //Commit the transaction CommitTransaction(); } catch (Exception exc) { //If, for any reason, an exception was thrown, rollback the transaction RollbackTransaction(); throw new IndException(exc); } }