add account page detail
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Billing.Models;
|
||||
using Billing.UI;
|
||||
using Xamarin.Forms;
|
||||
@ -10,21 +12,21 @@ namespace Billing.Views
|
||||
private static readonly BindableProperty BalanceProperty = BindableProperty.Create(nameof(Balance), typeof(decimal), typeof(AccountPage));
|
||||
private static readonly BindableProperty AssetProperty = BindableProperty.Create(nameof(Asset), typeof(decimal), typeof(AccountPage));
|
||||
private static readonly BindableProperty LiabilityProperty = BindableProperty.Create(nameof(Liability), typeof(decimal), typeof(AccountPage));
|
||||
private static readonly BindableProperty AccountsProperty = BindableProperty.Create(nameof(Accounts), typeof(ObservableCollection<Account>), typeof(AccountPage));
|
||||
private static readonly BindableProperty AccountsProperty = BindableProperty.Create(nameof(Accounts), typeof(List<AccountGrouping>), typeof(AccountPage));
|
||||
|
||||
public decimal Balance => (decimal)GetValue(BalanceProperty);
|
||||
public decimal Asset => (decimal)GetValue(AssetProperty);
|
||||
public decimal Liability => (decimal)GetValue(LiabilityProperty);
|
||||
public ObservableCollection<Account> Accounts => (ObservableCollection<Account>)GetValue(AccountsProperty);
|
||||
public List<AccountGrouping> Accounts => (List<AccountGrouping>)GetValue(AccountsProperty);
|
||||
|
||||
public Command AddAccount { get; }
|
||||
|
||||
private readonly ObservableCollection<Account> accounts;
|
||||
private readonly List<AccountGrouping> accounts;
|
||||
|
||||
public AccountPage()
|
||||
{
|
||||
AddAccount = new Command(OnAddAccount);
|
||||
accounts = new ObservableCollection<Account>();
|
||||
accounts = new List<AccountGrouping>();
|
||||
SetValue(AccountsProperty, accounts);
|
||||
|
||||
InitializeComponent();
|
||||
@ -47,7 +49,27 @@ namespace Billing.Views
|
||||
private void AccountChecked(object sender, AccountEventArgs e)
|
||||
{
|
||||
Helper.Debug(e.Account.ToString());
|
||||
accounts.Add(e.Account);
|
||||
var group = accounts.FirstOrDefault(g => g.Key == e.Account.Category);
|
||||
if (group == null)
|
||||
{
|
||||
group = new AccountGrouping(e.Account.Category)
|
||||
{
|
||||
e.Account
|
||||
};
|
||||
accounts.Add(group);
|
||||
}
|
||||
else
|
||||
{
|
||||
group.Add(e.Account);
|
||||
}
|
||||
groupLayout.Refresh(accounts);
|
||||
}
|
||||
}
|
||||
|
||||
public class AccountGrouping : List<Account>, IGrouping<AccountCategory, Account>
|
||||
{
|
||||
public AccountGrouping(AccountCategory key) : base() => Key = key;
|
||||
public AccountCategory Key { get; }
|
||||
public decimal Balance { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user