first step

This commit is contained in:
gaoyuan
2022-03-02 22:29:13 +08:00
parent 51f8e4f2e8
commit 9929eee056
17 changed files with 343 additions and 60 deletions

View File

@ -19,14 +19,14 @@ namespace Billing.Views
public decimal Liability => (decimal)GetValue(LiabilityProperty);
public List<AccountGrouping> Accounts => (List<AccountGrouping>)GetValue(AccountsProperty);
public Command AddAccount { get; }
public Command EditAccount { get; }
private readonly List<AccountGrouping> accounts = new();
private bool initialized;
public AccountPage()
{
AddAccount = new Command(OnAddAccount);
EditAccount = new Command(OnEditAccount);
SetValue(AccountsProperty, accounts);
InitializeComponent();
@ -40,9 +40,17 @@ namespace Billing.Views
accounts.Clear();
foreach (var account in App.Accounts)
{
account.Balance = account.Initial + App.Bills.Where(b => b.WalletId == account.Id).Sum(b => b.Amount);
AddToAccountGroup(account);
}
}
else
{
foreach (var account in App.Accounts)
{
account.Balance = account.Initial + App.Bills.Where(b => b.WalletId == account.Id).Sum(b => b.Amount);
}
}
groupLayout.Refresh(accounts);
}
@ -72,7 +80,7 @@ namespace Billing.Views
}
}
private async void OnAddAccount()
private async void OnEditAccount(object o)
{
if (Tap.IsBusy)
{
@ -80,7 +88,7 @@ namespace Billing.Views
}
using (Tap.Start())
{
var page = new AddAccountPage();
var page = new AddAccountPage(o as Account);
page.AccountChecked += AccountChecked;
await Navigation.PushAsync(page);
}
@ -88,8 +96,11 @@ namespace Billing.Views
private void AccountChecked(object sender, AccountEventArgs e)
{
App.Accounts.Add(e.Account);
AddToAccountGroup(e.Account);
if (e.Account.Id < 0)
{
App.Accounts.Add(e.Account);
AddToAccountGroup(e.Account);
}
groupLayout.Refresh(accounts);
Task.Run(App.WriteAccounts);