void Rebind() { UpdateContextMenuView(); this.hideEvents = true; if (myMoney != null) { //--------------------------------------------------------- // First make a copy of the collection in order to // help LINQ do it's magic over the collection List <Account> inputList = new List <Account>(myMoney.Accounts.GetAccounts(!this.displayClosedAccounts)); var selected = this.SelectedAccount; this.items.Clear(); decimal netWorth = 0; var accountOfTypeBanking = from a in inputList where a.Type == AccountType.Checking || a.Type == AccountType.Savings || a.Type == AccountType.Cash select a; AccountSectionHeader sh = BundleAccount("Banking", this.items, accountOfTypeBanking); netWorth += sh.BalanceInNormalizedCurrencyValue; var accountOfTypeCredit = from a in inputList where a.Type == AccountType.Credit || a.Type == AccountType.CreditLine select a; sh = BundleAccount("Credit", this.items, accountOfTypeCredit); netWorth += sh.BalanceInNormalizedCurrencyValue; var accountOfTypeBrokerage = from a in inputList where a.Type == AccountType.Brokerage || a.Type == AccountType.MoneyMarket select a; sh = BundleAccount("Brokerage", this.items, accountOfTypeBrokerage); sh.Clicked += (s, e) => { AppCommands.CommandReportInvestment.Execute(null, this); }; netWorth += sh.BalanceInNormalizedCurrencyValue; var accountOfTypeRetirement = from a in inputList where a.Type == AccountType.Retirement select a; sh = BundleAccount("Retirement", this.items, accountOfTypeRetirement); sh.Clicked += (s, e) => { AppCommands.CommandReportInvestment.Execute(null, this); }; netWorth += sh.BalanceInNormalizedCurrencyValue; var accountOfTypeAsset = from a in inputList where a.Type == AccountType.Asset select a; sh = BundleAccount("Assets", this.items, accountOfTypeAsset); netWorth += sh.BalanceInNormalizedCurrencyValue; var accountOfTypeLoan = from a in inputList where a.Type == AccountType.Loan select a; sh = BundleAccount("Loans", this.items, accountOfTypeLoan); netWorth += sh.BalanceInNormalizedCurrencyValue; if (statusArea != null) { statusArea.Text = netWorth.ToString("C"); } if (selected != null) { this.SelectedAccount = selected; } } else { this.items.Clear(); } this.hideEvents = false; }
void listBox1_PreviewMouseDown(object sender, MouseButtonEventArgs e) { AccountSectionHeader item = GetElementFromPoint(listBox1, e.GetPosition(listBox1)) as AccountSectionHeader; if (item != null) { if (item.IsSelectable == false) { e.Handled = true; } } }
void OnListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { object selected = (e.AddedItems.Count > 0) ? e.AddedItems[0] : null; AccountSectionHeader ash = selected as AccountSectionHeader; if (ash != null) { ash.OnClick(); } if (this.selected != selected && SelectionChanged != null) { this.selected = selected; SelectionChanged(this, EventArgs.Empty); } }
void OnListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { object selected = (e.AddedItems.Count > 0) ? e.AddedItems[0] : null; AccountSectionHeader ash = selected as AccountSectionHeader; if (ash != null && ash.IsSelectable == false) { // Don't allow selection of an AcccountHeader when it does not want to return; } if (this.selected != selected && SelectionChanged != null) { this.selected = selected; SelectionChanged(this, EventArgs.Empty); } }
void RaiseSelectionEvent(AccountViewModel selected, bool force) { AccountSectionHeader ash = selected as AccountSectionHeader; if (ash != null) { ash.OnClick(); } if ((force || this.selected != selected) && SelectionChanged != null) { SetSelected(selected); // checked it really is a different account (could be different object // but the same account because of a rebind). if (!hideEvents) { SelectionChanged(this, EventArgs.Empty); } } }
private static AccountSectionHeader BundleAccount(string caption, List <object> output, IEnumerable <Account> accountOfTypeBanking) { AccountSectionHeader sectionHeader = new AccountSectionHeader(); if (accountOfTypeBanking.Count() > 0) { sectionHeader.Title = caption; List <Account> bundle = new List <Account>(); sectionHeader.Accounts = bundle; output.Add(sectionHeader); foreach (Account a in accountOfTypeBanking) { sectionHeader.BalanceInNormalizedCurrencyValue += a.BalanceNormalized; output.Add(a); bundle.Add(a); } } return(sectionHeader); }
private static AccountSectionHeader BundleAccount(string caption, ObservableCollection <AccountViewModel> output, IEnumerable <Account> accountOfTypeBanking) { AccountSectionHeader sectionHeader = new AccountSectionHeader(); if (accountOfTypeBanking.Count() > 0) { sectionHeader.Title = caption; List <Account> bundle = new List <Account>(); sectionHeader.Accounts = bundle; output.Add(sectionHeader); foreach (Account a in accountOfTypeBanking) { output.Add(new AccountItemViewModel(a)); bundle.Add(a); } sectionHeader.UpdateBalance(); } return(sectionHeader); }