Esempio n. 1
0
    private void PopulateControls()
    {
        FinancialAccounts accounts = FinancialAccounts.ForOwner(_currentUser);

        this.DropBudgets.Items.Clear();
        this.DropYears.Items.Clear();

        foreach (FinancialAccount account in accounts)
        {
            this.DropBudgets.Items.Add(new ListItem(account.Name + " / " + account.Organization.Name,
                                                    account.Identity.ToString()));
        }

        bool   selectedBudget         = false;
        string accountParameterString = Request.QueryString["AccountId"];

        if (!String.IsNullOrEmpty(accountParameterString))
        {
            int accountId = Int32.Parse(accountParameterString);

            if (FinancialAccount.FromIdentity(accountId).OwnerPersonId == _currentUser.Identity)
            {
                this.DropBudgets.SelectedValue = accountId.ToString();
            }
            else if (_currentUser.Identity == 1 && System.Diagnostics.Debugger.IsAttached) // DEBUG
            {
                FinancialAccount account = FinancialAccount.FromIdentity(accountId);
                this.DropBudgets.Items.Add(new ListItem(account.Name + " / " + account.Organization.Name,
                                                        account.Identity.ToString()));

                this.DropBudgets.SelectedValue = accountId.ToString();
            }
        }

        ViewState[this.ClientID + "_BudgetId"] = this.DropBudgets.SelectedValue;
        _account = FinancialAccount.FromIdentity(Int32.Parse(this.DropBudgets.SelectedValue));
        this.HiddenInitBudgetId.Value = _account.Identity.ToString();

        int yearStart = DateTime.Today.Year - 1;

        if (DateTime.Today.Month <= 6)
        {
            yearStart--;
        }

        for (int yearIndex = 0; yearIndex < 3; yearIndex++)
        {
            this.DropYears.Items.Add((yearStart + yearIndex).ToString());
        }

        this.DropYears.SelectedValue = DateTime.Today.Year.ToString();
        _year = DateTime.Today.Year;

        ViewState[this.ClientID + "_Year"] = this.DropYears.SelectedValue;
        this.HiddenInitYear.Value          = this.DropYears.SelectedValue;

        PopulateBudgetData();
    }