first test-flight version
This commit is contained in:
@ -13,6 +13,10 @@ namespace Billing.Views
|
||||
{
|
||||
private static readonly BindableProperty SelectedDateProperty = BindableProperty.Create(nameof(SelectedDate), typeof(DateTime), typeof(BillPage));
|
||||
private static readonly BindableProperty BillsProperty = BindableProperty.Create(nameof(Bills), typeof(List<UIBill>), typeof(BillPage));
|
||||
private static readonly BindableProperty NoBillsProperty = BindableProperty.Create(nameof(NoBills), typeof(bool), typeof(BillPage));
|
||||
private static readonly BindableProperty IncomeProperty = BindableProperty.Create(nameof(Income), typeof(decimal), typeof(BillPage));
|
||||
private static readonly BindableProperty SpendingProperty = BindableProperty.Create(nameof(Spending), typeof(decimal), typeof(BillPage));
|
||||
private static readonly BindableProperty BalanceProperty = BindableProperty.Create(nameof(Balance), typeof(decimal), typeof(BillPage));
|
||||
|
||||
public DateTime SelectedDate
|
||||
{
|
||||
@ -24,12 +28,18 @@ namespace Billing.Views
|
||||
get => (List<UIBill>)GetValue(BillsProperty);
|
||||
set => SetValue(BillsProperty, value);
|
||||
}
|
||||
public bool NoBills => (bool)GetValue(NoBillsProperty);
|
||||
public decimal Income => (decimal)GetValue(IncomeProperty);
|
||||
public decimal Spending => (decimal)GetValue(SpendingProperty);
|
||||
public decimal Balance => (decimal)GetValue(BalanceProperty);
|
||||
|
||||
public Command EditBilling { get; }
|
||||
public Command DeleteBilling { get; }
|
||||
|
||||
public BillPage()
|
||||
{
|
||||
EditBilling = new Command(OnEditBilling);
|
||||
DeleteBilling = new Command(OnDeleteBilling);
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
@ -45,6 +55,17 @@ namespace Billing.Views
|
||||
b.CreateTime.Month == e.Date.Month &&
|
||||
b.CreateTime.Day == e.Date.Day);
|
||||
Bills = new List<UIBill>(bills.Select(b => WrapBill(b)));
|
||||
RefreshBalance(Bills);
|
||||
}
|
||||
|
||||
private void RefreshBalance(List<UIBill> bills)
|
||||
{
|
||||
SetValue(NoBillsProperty, bills.Count == 0);
|
||||
var income = bills.Where(b => b.Amount > 0).Sum(b => b.Amount);
|
||||
var spending = -bills.Where(b => b.Amount < 0).Sum(b => b.Amount);
|
||||
SetValue(IncomeProperty, income);
|
||||
SetValue(SpendingProperty, spending);
|
||||
SetValue(BalanceProperty, income - spending);
|
||||
}
|
||||
|
||||
private UIBill WrapBill(Bill b)
|
||||
@ -101,6 +122,31 @@ namespace Billing.Views
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnDeleteBilling(object o)
|
||||
{
|
||||
if (Tap.IsBusy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
using (Tap.Start())
|
||||
{
|
||||
if (o is UIBill bill)
|
||||
{
|
||||
var result = await this.ShowConfirm(Resource.ConfirmDeleteBill);
|
||||
if (result)
|
||||
{
|
||||
var bills = Bills;
|
||||
bills.Remove(bill);
|
||||
App.Bills.Remove(bill.Bill);
|
||||
billsLayout.Refresh(bills);
|
||||
RefreshBalance(bills);
|
||||
|
||||
_ = Task.Run(App.WriteBills);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBillChecked(object sender, Bill e)
|
||||
{
|
||||
if (e.Id < 0)
|
||||
@ -127,6 +173,7 @@ namespace Billing.Views
|
||||
UpdateBill(bill);
|
||||
}
|
||||
}
|
||||
RefreshBalance(Bills);
|
||||
|
||||
Task.Run(App.WriteBills);
|
||||
}
|
||||
|
Reference in New Issue
Block a user