/// <summary>
        /// Removes otherCosts BudgetRevisedOtherCosts object from the list of BudgetRevisedOtherCosts objects
        /// </summary>
        /// <param name="page">calling page</param>
        /// <param name="otherCosts">object to be removed from the list</param>
        public static void RemoveInitialBudgetOtherCosts(Page page, InitialBudgetOtherCosts otherCosts)
        {
            if (!(page is IndBasePage))
            {
                throw new IndException(ApplicationMessages.EXCEPTION_PAGE_NOT_INDBASEPAGE);
            }

            List <InitialBudgetOtherCosts> otherCostsList = (List <InitialBudgetOtherCosts>)GetSessionValue(page as IndBasePage, SessionStrings.INITIAL_OTHER_COSTS_LIST, false);

            try
            {
                if (otherCostsList == null)
                {
                    return;
                }
                //BudgetRevisedOtherCosts foundOtherCost = null;
                foreach (InitialBudgetOtherCosts currentOC in otherCostsList)
                {
                    if ((currentOC.IdProject == otherCosts.IdProject) &&
                        (currentOC.IdPhase == otherCosts.IdPhase) &&
                        (currentOC.IdWP == otherCosts.IdWP) &&
                        (currentOC.IdCostCenter == otherCosts.IdCostCenter))
                    {
                        otherCostsList.Remove(currentOC);
                        SetSessionValue(page, SessionStrings.INITIAL_OTHER_COSTS, otherCostsList);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new IndException(ex);
            }
        }
        /// <summary>
        /// Get the other costs object from session if it exist in the list
        /// </summary>
        /// <param name="page">The page that has access to the session</param>
        /// <param name="otherCosts">The object that contains the key</param>
        /// <returns></returns>
        public static InitialBudgetOtherCosts GetOtherCost(Page page, InitialBudgetOtherCosts otherCosts)
        {
            if (!(page is IndBasePage))
            {
                throw new IndException(ApplicationMessages.EXCEPTION_PAGE_NOT_INDBASEPAGE);
            }

            List <InitialBudgetOtherCosts> otherCostsList = GetSessionValue(page as IndBasePage, SessionStrings.INITIAL_OTHER_COSTS_LIST, false) as List <InitialBudgetOtherCosts>;

            try
            {
                if (otherCostsList == null)
                {
                    return(null);
                }
                foreach (InitialBudgetOtherCosts currentOC in otherCostsList)
                {
                    if ((currentOC.IdProject == otherCosts.IdProject) && (currentOC.IdPhase == otherCosts.IdPhase) && (currentOC.IdWP == otherCosts.IdWP) && (currentOC.IdCostCenter == otherCosts.IdCostCenter))
                    {
                        return(currentOC);
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new IndException(ex);
            }
        }
    private void LoadValues(InitialBudgetOtherCosts otherCosts)
    {
        int multiplier = GetMultiplier();

        txtTE.Text            = (otherCosts.TE == ApplicationConstants.DECIMAL_NULL_VALUE) ? String.Empty : Rounding.Round(decimal.Divide(otherCosts.TE, multiplier)).ToString();
        txtProtoParts.Text    = (otherCosts.ProtoParts == ApplicationConstants.DECIMAL_NULL_VALUE) ? String.Empty : Rounding.Round(decimal.Divide(otherCosts.ProtoParts, multiplier)).ToString();
        txtProtoTooling.Text  = (otherCosts.ProtoTooling == ApplicationConstants.DECIMAL_NULL_VALUE) ? String.Empty : Rounding.Round(decimal.Divide(otherCosts.ProtoTooling, multiplier)).ToString();
        txtTrials.Text        = (otherCosts.Trials == ApplicationConstants.DECIMAL_NULL_VALUE) ? String.Empty : Rounding.Round(decimal.Divide(otherCosts.Trials, multiplier)).ToString();
        txtOtherExpenses.Text = (otherCosts.OtherExpenses == ApplicationConstants.DECIMAL_NULL_VALUE) ? String.Empty : Rounding.Round(decimal.Divide(otherCosts.OtherExpenses, multiplier)).ToString();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                if (String.IsNullOrEmpty(this.Request.QueryString["IsAssociateCurrency"]))
                {
                    throw new IndException(ApplicationMessages.MessageWithParameters(ApplicationMessages.EXCEPTION_COULD_NOT_GET_PARAMETER, "IsAssociateCurrency"));
                }
                if (this.Request.QueryString["IsAssociateCurrency"] != "0" && this.Request.QueryString["IsAssociateCurrency"] != "1")
                {
                    throw new IndException(ApplicationMessages.EXCEPTION_WRONG_ASSOCIATE_CURRENCY_PARAMETER);
                }
                if (String.IsNullOrEmpty(this.Request.QueryString["AmountScaleOption"]))
                {
                    throw new IndException(ApplicationMessages.MessageWithParameters(ApplicationMessages.EXCEPTION_COULD_NOT_GET_PARAMETER, "AmountScaleOption"));
                }

                InitialBudgetOtherCosts otherCosts = SessionManager.GetSessionValueRedirect(this, SessionStrings.INITIAL_OTHER_COSTS) as InitialBudgetOtherCosts;
                //If other costs is null, the redirect does not take place immediately
                if (otherCosts != null)
                {
                    //initialize controls to empty string before loading from database
                    InitializePopupControls();
                    InitialBudgetOtherCosts existingOtherCosts = SessionManager.GetOtherCost(this, otherCosts);
                    if (existingOtherCosts == null)
                    {
                        otherCosts.IsAssociateCurrency = this.Request.QueryString["IsAssociateCurrency"] == "1" ? true : false;
                        DataSet ds = otherCosts.GetAll(true);
                        LoadValues(ds);
                    }
                    else
                    {
                        LoadValues(existingOtherCosts);
                    }
                }
            }
        }
        catch (IndException exc)
        {
            ShowError(exc);
            return;
        }
        catch (Exception exc)
        {
            ShowError(new IndException(exc));
            return;
        }
    }
        public static void AddOtherCosts(Page page, InitialBudgetOtherCosts otherCosts)
        {
            if (!(page is IndBasePage))
            {
                throw new IndException(ApplicationMessages.EXCEPTION_PAGE_NOT_INDBASEPAGE);
            }

            List <InitialBudgetOtherCosts> otherCostsList = GetSessionValue(page as IndBasePage, SessionStrings.INITIAL_OTHER_COSTS_LIST, false) as List <InitialBudgetOtherCosts>;

            try
            {
                if (otherCostsList == null)
                {
                    otherCostsList = new List <InitialBudgetOtherCosts>();
                    otherCostsList.Add(otherCosts);
                }
                else
                {
                    InitialBudgetOtherCosts foundOtherCost = null;
                    foreach (InitialBudgetOtherCosts currentOC in otherCostsList)
                    {
                        if ((currentOC.IdProject == otherCosts.IdProject) && (currentOC.IdPhase == otherCosts.IdPhase) && (currentOC.IdWP == otherCosts.IdWP) && (currentOC.IdCostCenter == otherCosts.IdCostCenter))
                        {
                            foundOtherCost = currentOC;
                            break;
                        }
                    }
                    if (foundOtherCost == null)
                    {
                        otherCostsList.Add(otherCosts);
                    }
                    else
                    {
                        otherCostsList.Remove(foundOtherCost);
                        otherCostsList.Add(otherCosts);
                    }
                }
                SetSessionValue(page, SessionStrings.INITIAL_OTHER_COSTS_LIST, otherCostsList);
            }
            catch (Exception ex)
            {
                throw new IndException(ex);
            }
        }
    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;
        }
    }