switch to sqlite

This commit is contained in:
2022-03-11 16:10:11 +08:00
parent f5f16d43f4
commit 5ec4119025
25 changed files with 286 additions and 435 deletions

View File

@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Billing.Languages;
using Billing.Models;
using Billing.Store;
using Billing.UI;
using Xamarin.Forms;
@ -120,25 +120,27 @@ namespace Billing.Views
if (group == null)
{
Helper.Error("account.delete", "unexpected deleting account, cannot find the current category");
return;
}
group.Remove(account);
if (group.Count == 0)
}
else
{
accounts.Remove(group);
group.Remove(account);
if (group.Count == 0)
{
accounts.Remove(group);
}
}
RefreshBalance();
groupLayout.Refresh(accounts);
RankPage.Instance?.SetNeedRefresh();
_ = Task.Run(App.WriteAccounts);
await StoreHelper.DeleteAccountItemAsync(account);
}
}
}
}
private void AccountChecked(object sender, AccountEventArgs e)
private async void AccountChecked(object sender, AccountEventArgs e)
{
var add = e.Account.Id < 0;
if (add)
@ -151,7 +153,7 @@ namespace Billing.Views
RankPage.Instance?.SetNeedRefresh();
Task.Run(App.WriteAccounts);
await StoreHelper.SaveAccountItemAsync(e.Account);
}
}

View File

@ -59,7 +59,7 @@ namespace Billing.Views
this.account = account;
if (account == null)
{
AccountIcon = BaseModel.ICON_DEFAULT;
AccountIcon = Definition.DefaultIcon;
Category = AccountCategory.Cash;
}
else

View File

@ -56,14 +56,13 @@ namespace Billing.Views
{
CategoryName = category.Name;
CategoryIcon = category.Icon;
if (category.TintColor == Color.Transparent ||
category.TintColor == default)
if (category.TintColor.IsTransparent())
{
TintColor = BaseTheme.CurrentPrimaryColor;
}
else
{
TintColor = category.TintColor;
TintColor = category.TintColor.ToColor();
}
}
else
@ -103,6 +102,7 @@ namespace Billing.Views
{
var currentColor = BaseTheme.CurrentPrimaryColor;
var tintColor = TintColor;
var color = (tintColor == currentColor ? Color.Transparent : tintColor).ToLong();
var category = App.Categories.FirstOrDefault(c => c.Id == categoryId);
if (category == null)
{
@ -111,7 +111,7 @@ namespace Billing.Views
Id = -1,
Name = CategoryName,
Icon = CategoryIcon,
TintColor = tintColor == currentColor ? Color.Transparent : tintColor,
TintColor = color,
ParentId = parent?.Id,
Type = parent?.Type ?? CategoryType.Spending
});
@ -120,7 +120,7 @@ namespace Billing.Views
{
category.Name = CategoryName;
category.Icon = CategoryIcon;
category.TintColor = tintColor == currentColor ? Color.Transparent : tintColor;
category.TintColor = color;
CategoryChecked?.Invoke(this, category);
}
await Navigation.PopAsync();

View File

@ -1,4 +1,5 @@
using Billing.Models;
using Billing.Store;
using Billing.UI;
using System;
using System.Collections.Generic;
@ -84,7 +85,7 @@ namespace Billing.Views
private void UpdateBill(UIBill bill)
{
bill.Icon = App.Categories.FirstOrDefault(c => c.Id == bill.Bill.CategoryId)?.Icon ?? BaseModel.ICON_DEFAULT;
bill.Icon = App.Categories.FirstOrDefault(c => c.Id == bill.Bill.CategoryId)?.Icon ?? Definition.DefaultIcon;
bill.Name = bill.Bill.Name;
bill.DateCreation = bill.Bill.CreateTime;
bill.Amount = bill.Bill.Amount;
@ -158,13 +159,13 @@ namespace Billing.Views
RankPage.Instance?.SetNeedRefresh();
_ = Task.Run(App.WriteBills);
await StoreHelper.DeleteBillItemAsync(bill.Bill);
}
}
}
}
private void OnBillChecked(object sender, Bill e)
private async void OnBillChecked(object sender, Bill e)
{
if (e.Id < 0)
{
@ -195,7 +196,7 @@ namespace Billing.Views
RankPage.Instance?.SetNeedRefresh();
Task.Run(App.WriteBills);
await StoreHelper.SaveBillItemAsync(e);
}
}

View File

@ -1,11 +1,11 @@
using Billing.Languages;
using Billing.Models;
using Billing.Store;
using Billing.Themes;
using Billing.UI;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Billing.Views
@ -68,9 +68,9 @@ namespace Billing.Views
Icon = category.Icon,
Name = category.Name,
IsTopCategory = IsTopCategory,
TintColor = category.TintColor == Color.Transparent || category.TintColor == default ?
TintColor = category.TintColor.IsTransparent() ?
BaseTheme.CurrentPrimaryColor :
category.TintColor
category.TintColor.ToColor()
};
}
@ -112,7 +112,7 @@ namespace Billing.Views
Categories.Remove(c);
groupLayout.Refresh(Categories);
App.Categories.Remove(c.Category);
_ = Task.Run(App.WriteCategories);
await StoreHelper.DeleteCategoryItemAsync(c.Category);
}
}
}
@ -144,7 +144,7 @@ namespace Billing.Views
}
}
private void OnCategoryChecked(object sender, Category category)
private async void OnCategoryChecked(object sender, Category category)
{
if (category.Id < 0)
{
@ -183,16 +183,16 @@ namespace Billing.Views
}
groupLayout.Refresh(Categories);
Task.Run(App.WriteCategories);
await StoreHelper.SaveCategoryItemAsync(category);
}
private void UpdateCategory(UICategory c)
{
c.Name = c.Category.Name;
c.Icon = c.Category.Icon;
c.TintColor = c.Category.TintColor == Color.Transparent || c.Category.TintColor == default ?
c.TintColor = c.Category.TintColor.IsTransparent() ?
BaseTheme.CurrentPrimaryColor :
c.Category.TintColor;
c.Category.TintColor.ToColor();
}
}

View File

@ -72,7 +72,7 @@ namespace Billing.Views
IsChecked = c.Id == categoryId,
Icon = c.Icon,
Name = c.Name,
TintColor = c.TintColor == Color.Transparent || c.TintColor == default ? defaultColor : c.TintColor
TintColor = c.TintColor.IsTransparent() ? defaultColor : c.TintColor.ToColor()
};
}

View File

@ -1,5 +1,4 @@
using Billing.Models;
using Billing.UI;
using Billing.UI;
using System;
using System.Collections.Generic;
using System.Linq;
@ -37,7 +36,7 @@ namespace Billing.Views
{
var source = new List<BillingIcon>
{
new() { Icon = BaseModel.ICON_DEFAULT },
new() { Icon = Definition.DefaultIcon },
new() { Icon = "wallet" },
new() { Icon = "dollar" },
new() { Icon = "creditcard" },

View File

@ -1,4 +1,5 @@
using Billing.Models;
using Billing.Store;
using Billing.Themes;
using Billing.UI;
using Microcharts;
@ -473,7 +474,7 @@ namespace Billing.Views
private async void OnBillChecked(object sender, Bill e)
{
await Task.Run(App.WriteBills);
await StoreHelper.SaveBillItemAsync(e);
LoadData();
}