issue fix
This commit is contained in:
parent
5ec4119025
commit
28897c96ea
@ -1,4 +1,5 @@
|
|||||||
using Billing.Models;
|
using Billing.Models;
|
||||||
|
using Billing.Themes;
|
||||||
using Billing.UI;
|
using Billing.UI;
|
||||||
using Billing.Views;
|
using Billing.Views;
|
||||||
using System;
|
using System;
|
||||||
@ -83,9 +84,13 @@ namespace Billing
|
|||||||
|
|
||||||
public static UIBill WrapBill(Bill b)
|
public static UIBill WrapBill(Bill b)
|
||||||
{
|
{
|
||||||
|
var category = App.Categories.FirstOrDefault(c => c.Id == b.CategoryId);
|
||||||
return new UIBill(b)
|
return new UIBill(b)
|
||||||
{
|
{
|
||||||
Icon = App.Categories.FirstOrDefault(c => c.Id == b.CategoryId)?.Icon ?? Definition.DefaultIcon,
|
Icon = category?.Icon ?? Definition.DefaultIcon,
|
||||||
|
TintColor = category?.TintColor.IsTransparent() == false ?
|
||||||
|
category.TintColor.ToColor() :
|
||||||
|
BaseTheme.CurrentPrimaryColor,
|
||||||
Name = b.Name,
|
Name = b.Name,
|
||||||
DateCreation = b.CreateTime,
|
DateCreation = b.CreateTime,
|
||||||
Amount = b.Amount,
|
Amount = b.Amount,
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
{
|
{
|
||||||
public interface IIdItem
|
public interface IIdItem
|
||||||
{
|
{
|
||||||
public int Id { get; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Billing.Models;
|
using Billing.Models;
|
||||||
using SQLite;
|
using SQLite;
|
||||||
@ -31,35 +30,35 @@ namespace Billing.Store
|
|||||||
await database.InsertAllAsync(new List<Category>
|
await database.InsertAllAsync(new List<Category>
|
||||||
{
|
{
|
||||||
// sample categories
|
// sample categories
|
||||||
new() { Id = 1, Name = Resource.Clothing, Icon = "clothes" },
|
new() { Name = Resource.Clothing, Icon = "clothes" },
|
||||||
new() { Id = 2, Name = Resource.Food, Icon = "food" },
|
new() { Name = Resource.Food, Icon = "food" },
|
||||||
new() { Id = 4, Name = Resource.Daily, Icon = "daily" },
|
new() { Name = Resource.Daily, Icon = "daily" },
|
||||||
new() { Id = 5, Name = Resource.Trans, Icon = "trans" },
|
new() { Name = Resource.Trans, Icon = "trans" },
|
||||||
new() { Id = 6, Name = Resource.Entertainment, Icon = "face" },
|
new() { Name = Resource.Entertainment, Icon = "face" },
|
||||||
new() { Id = 7, Name = Resource.Learn, Icon = "learn" },
|
new() { Name = Resource.Learn, Icon = "learn" },
|
||||||
new() { Id = 8, Name = Resource.Medical, Icon = "medical" },
|
new() { Name = Resource.Medical, Icon = "medical" },
|
||||||
new() { Id = 9, Name = Resource.OtherSpending, Icon = "plus" },
|
new() { Name = Resource.OtherSpending, Icon = "plus" },
|
||||||
|
|
||||||
new() { Id = 10, Type = CategoryType.Income, Name = Resource.Earnings, Icon = "#brand#btc" },
|
new() { Type = CategoryType.Income, Name = Resource.Earnings, Icon = "#brand#btc" },
|
||||||
new() { Id = 20, Type = CategoryType.Income, Name = Resource.OtherIncome, Icon = "plus" },
|
new() { Type = CategoryType.Income, Name = Resource.OtherIncome, Icon = "plus" },
|
||||||
|
|
||||||
// sub-categories
|
// sub-categories
|
||||||
new() { Id = 100, ParentId = 1, Name = Resource.Jewellery, Icon = "gem" },
|
new() { ParentId = 1, Name = Resource.Jewellery, Icon = "gem" },
|
||||||
new() { Id = 101, ParentId = 1, Name = Resource.Cosmetics, Icon = "makeup" },
|
new() { ParentId = 1, Name = Resource.Cosmetics, Icon = "makeup" },
|
||||||
new() { Id = 102, ParentId = 2, Name = Resource.Brunch, Icon = "brunch" },
|
new() { ParentId = 2, Name = Resource.Brunch, Icon = "brunch" },
|
||||||
new() { Id = 103, ParentId = 2, Name = Resource.Dinner, Icon = "dinner" },
|
new() { ParentId = 2, Name = Resource.Dinner, Icon = "dinner" },
|
||||||
new() { Id = 104, ParentId = 2, Name = Resource.Drinks, Icon = "drink" },
|
new() { ParentId = 2, Name = Resource.Drinks, Icon = "drink" },
|
||||||
new() { Id = 105, ParentId = 2, Name = Resource.Fruit, Icon = "fruit" },
|
new() { ParentId = 2, Name = Resource.Fruit, Icon = "fruit" },
|
||||||
new() { Id = 106, ParentId = 4, Name = Resource.UtilityBill, Icon = "bill" },
|
new() { ParentId = 3, Name = Resource.UtilityBill, Icon = "bill" },
|
||||||
new() { Id = 107, ParentId = 4, Name = Resource.PropertyFee, Icon = "fee" },
|
new() { ParentId = 3, Name = Resource.PropertyFee, Icon = "fee" },
|
||||||
new() { Id = 108, ParentId = 4, Name = Resource.Rent, Icon = "rent" },
|
new() { ParentId = 3, Name = Resource.Rent, Icon = "rent" },
|
||||||
new() { Id = 109, ParentId = 4, Name = Resource.Maintenance, Icon = "maintenance" },
|
new() { ParentId = 3, Name = Resource.Maintenance, Icon = "maintenance" },
|
||||||
new() { Id = 110, ParentId = 5, Name = Resource.LightRail, Icon = "rail" },
|
new() { ParentId = 4, Name = Resource.LightRail, Icon = "rail" },
|
||||||
new() { Id = 111, ParentId = 5, Name = Resource.Taxi, Icon = "taxi" },
|
new() { ParentId = 4, Name = Resource.Taxi, Icon = "taxi" },
|
||||||
new() { Id = 112, ParentId = 6, Name = Resource.Fitness, Icon = "fitness" },
|
new() { ParentId = 5, Name = Resource.Fitness, Icon = "fitness" },
|
||||||
new() { Id = 113, ParentId = 6, Name = Resource.Party, Icon = "party" },
|
new() { ParentId = 5, Name = Resource.Party, Icon = "party" },
|
||||||
new() { Id = 200, ParentId = 10, Type = CategoryType.Income, Name = Resource.Salary, Icon = "#brand#buffer" },
|
new() { ParentId = 9, Type = CategoryType.Income, Name = Resource.Salary, Icon = "#brand#buffer" },
|
||||||
new() { Id = 201, ParentId = 10, Type = CategoryType.Income, Name = Resource.Bonus, Icon = "dollar" },
|
new() { ParentId = 9, Type = CategoryType.Income, Name = Resource.Bonus, Icon = "dollar" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
@ -141,8 +140,8 @@ namespace Billing.Store
|
|||||||
var source = new TaskCompletionSource<T>();
|
var source = new TaskCompletionSource<T>();
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var list = await database.QueryAsync<T>($"SELECT * FROM [{typeof(T).Name}] WHERE [Id] = ?", id);
|
var item = await database.FindWithQueryAsync<T>($"SELECT * FROM [{typeof(T).Name}] WHERE [Id] = ? LIMIT 1", id);
|
||||||
source.SetResult(list.FirstOrDefault());
|
source.SetResult(item);
|
||||||
});
|
});
|
||||||
return source.Task;
|
return source.Task;
|
||||||
}
|
}
|
||||||
@ -172,20 +171,20 @@ namespace Billing.Store
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (item.Id < 0)
|
if (item.Id > 0)
|
||||||
{
|
{
|
||||||
return database.InsertAsync(item);
|
return database.UpdateAsync(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return database.UpdateAsync(item);
|
return database.InsertAsync(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Helper.Error("db.write", $"failed to insert/update item, table: {typeof(T)}, id: {item.Id}, item: {item}, error: {ex.Message}");
|
Helper.Error("db.write", $"failed to insert/update item, table: {typeof(T)}, id: {item.Id}, item: {item}, error: {ex.Message}");
|
||||||
}
|
}
|
||||||
return Task.FromResult(-1);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<int> DeleteItemAsync<T>(T item) where T : IIdItem
|
private Task<int> DeleteItemAsync<T>(T item) where T : IIdItem
|
||||||
@ -198,7 +197,7 @@ namespace Billing.Store
|
|||||||
{
|
{
|
||||||
Helper.Error("db.delete", $"failed to delete item, table: {typeof(T)}, id: {item.Id}, item: {item}, error: {ex.Message}");
|
Helper.Error("db.delete", $"failed to delete item, table: {typeof(T)}, id: {item.Id}, item: {item}, error: {ex.Message}");
|
||||||
}
|
}
|
||||||
return Task.FromResult(-1);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -64,17 +64,6 @@ namespace Billing.Views
|
|||||||
|
|
||||||
private void AddToAccountGroup(Account account)
|
private void AddToAccountGroup(Account account)
|
||||||
{
|
{
|
||||||
int maxId;
|
|
||||||
if (accounts.Count > 0)
|
|
||||||
{
|
|
||||||
maxId = accounts.Max(g => g.Max(a => a.Id));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maxId = -1;
|
|
||||||
}
|
|
||||||
account.Id = maxId + 1;
|
|
||||||
|
|
||||||
var group = accounts.FirstOrDefault(g => g.Key == account.Category);
|
var group = accounts.FirstOrDefault(g => g.Key == account.Category);
|
||||||
if (group == null)
|
if (group == null)
|
||||||
{
|
{
|
||||||
@ -142,7 +131,7 @@ namespace Billing.Views
|
|||||||
|
|
||||||
private async void AccountChecked(object sender, AccountEventArgs e)
|
private async void AccountChecked(object sender, AccountEventArgs e)
|
||||||
{
|
{
|
||||||
var add = e.Account.Id < 0;
|
var add = e.Account.Id <= 0;
|
||||||
if (add)
|
if (add)
|
||||||
{
|
{
|
||||||
App.Accounts.Add(e.Account);
|
App.Accounts.Add(e.Account);
|
||||||
|
@ -105,7 +105,6 @@ namespace Billing.Views
|
|||||||
{
|
{
|
||||||
Account = account ?? new Account
|
Account = account ?? new Account
|
||||||
{
|
{
|
||||||
Id = -1,
|
|
||||||
Name = AccountName,
|
Name = AccountName,
|
||||||
Icon = AccountIcon,
|
Icon = AccountIcon,
|
||||||
Category = Category,
|
Category = Category,
|
||||||
|
@ -162,7 +162,6 @@ namespace Billing.Views
|
|||||||
}
|
}
|
||||||
BillChecked?.Invoke(this, bill ?? new Bill
|
BillChecked?.Invoke(this, bill ?? new Bill
|
||||||
{
|
{
|
||||||
Id = -1,
|
|
||||||
Amount = amount,
|
Amount = amount,
|
||||||
Name = name,
|
Name = name,
|
||||||
CategoryId = categoryId,
|
CategoryId = categoryId,
|
||||||
|
@ -108,7 +108,6 @@ namespace Billing.Views
|
|||||||
{
|
{
|
||||||
CategoryChecked?.Invoke(this, new Category
|
CategoryChecked?.Invoke(this, new Category
|
||||||
{
|
{
|
||||||
Id = -1,
|
|
||||||
Name = CategoryName,
|
Name = CategoryName,
|
||||||
Icon = CategoryIcon,
|
Icon = CategoryIcon,
|
||||||
TintColor = color,
|
TintColor = color,
|
||||||
|
@ -101,6 +101,7 @@
|
|||||||
CommandParameter="{Binding .}"/>
|
CommandParameter="{Binding .}"/>
|
||||||
</Grid.GestureRecognizers>
|
</Grid.GestureRecognizers>
|
||||||
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
||||||
|
ui:TintHelper.TintColor="{Binding TintColor}"
|
||||||
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
||||||
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
|
@ -167,18 +167,8 @@ namespace Billing.Views
|
|||||||
|
|
||||||
private async void OnBillChecked(object sender, Bill e)
|
private async void OnBillChecked(object sender, Bill e)
|
||||||
{
|
{
|
||||||
if (e.Id < 0)
|
if (e.Id <= 0)
|
||||||
{
|
{
|
||||||
int maxId;
|
|
||||||
if (App.Bills.Count > 0)
|
|
||||||
{
|
|
||||||
maxId = App.Bills.Max(b => b.Id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maxId = -1;
|
|
||||||
}
|
|
||||||
e.Id = maxId + 1;
|
|
||||||
App.Bills.Add(e);
|
App.Bills.Add(e);
|
||||||
var bills = Bills;
|
var bills = Bills;
|
||||||
bills.Add(Helper.WrapBill(e));
|
bills.Add(Helper.WrapBill(e));
|
||||||
@ -189,7 +179,21 @@ namespace Billing.Views
|
|||||||
var bill = Bills.FirstOrDefault(b => b.Bill == e);
|
var bill = Bills.FirstOrDefault(b => b.Bill == e);
|
||||||
if (bill != null)
|
if (bill != null)
|
||||||
{
|
{
|
||||||
UpdateBill(bill);
|
if (bill.DateCreation != e.CreateTime)
|
||||||
|
{
|
||||||
|
var bills = App.Bills.Where(b => Helper.IsSameDay(b.CreateTime, SelectedDate));
|
||||||
|
Bills = new List<UIBill>(bills.OrderBy(b => b.CreateTime).Select(b => Helper.WrapBill(b)));
|
||||||
|
RefreshBalance(Bills);
|
||||||
|
|
||||||
|
RankPage.Instance?.SetNeedRefresh();
|
||||||
|
|
||||||
|
await StoreHelper.SaveBillItemAsync(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateBill(bill);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RefreshBalance(Bills);
|
RefreshBalance(Bills);
|
||||||
@ -203,6 +207,7 @@ namespace Billing.Views
|
|||||||
public class UIBill : BindableObject
|
public class UIBill : BindableObject
|
||||||
{
|
{
|
||||||
public static readonly BindableProperty IconProperty = Helper.Create<string, UIBill>(nameof(Icon));
|
public static readonly BindableProperty IconProperty = Helper.Create<string, UIBill>(nameof(Icon));
|
||||||
|
public static readonly BindableProperty TintColorProperty = Helper.Create<Color, UIBill>(nameof(TintColor));
|
||||||
public static readonly BindableProperty NameProperty = Helper.Create<string, UIBill>(nameof(Name));
|
public static readonly BindableProperty NameProperty = Helper.Create<string, UIBill>(nameof(Name));
|
||||||
public static readonly BindableProperty DateCreationProperty = Helper.Create<DateTime, UIBill>(nameof(DateCreation));
|
public static readonly BindableProperty DateCreationProperty = Helper.Create<DateTime, UIBill>(nameof(DateCreation));
|
||||||
public static readonly BindableProperty AmountProperty = Helper.Create<decimal, UIBill>(nameof(Amount));
|
public static readonly BindableProperty AmountProperty = Helper.Create<decimal, UIBill>(nameof(Amount));
|
||||||
@ -213,6 +218,11 @@ namespace Billing.Views
|
|||||||
get => (string)GetValue(IconProperty);
|
get => (string)GetValue(IconProperty);
|
||||||
set => SetValue(IconProperty, value);
|
set => SetValue(IconProperty, value);
|
||||||
}
|
}
|
||||||
|
public Color TintColor
|
||||||
|
{
|
||||||
|
get => (Color)GetValue(TintColorProperty);
|
||||||
|
set => SetValue(TintColorProperty, value);
|
||||||
|
}
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get => (string)GetValue(NameProperty);
|
get => (string)GetValue(NameProperty);
|
||||||
|
@ -146,19 +146,9 @@ namespace Billing.Views
|
|||||||
|
|
||||||
private async void OnCategoryChecked(object sender, Category category)
|
private async void OnCategoryChecked(object sender, Category category)
|
||||||
{
|
{
|
||||||
if (category.Id < 0)
|
if (category.Id <= 0)
|
||||||
{
|
{
|
||||||
// add
|
// add
|
||||||
int maxId;
|
|
||||||
if (App.Categories.Count > 0)
|
|
||||||
{
|
|
||||||
maxId = App.Categories.Max(b => b.Id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maxId = -1;
|
|
||||||
}
|
|
||||||
category.Id = maxId + 1;
|
|
||||||
App.Categories.Add(category);
|
App.Categories.Add(category);
|
||||||
Categories.Add(WrapCategory(category));
|
Categories.Add(WrapCategory(category));
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,7 @@
|
|||||||
CommandParameter="{Binding .}"/>
|
CommandParameter="{Binding .}"/>
|
||||||
</Grid.GestureRecognizers>
|
</Grid.GestureRecognizers>
|
||||||
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
||||||
|
ui:TintHelper.TintColor="{Binding TintColor}"
|
||||||
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
||||||
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user