add account

This commit is contained in:
2022-02-26 12:36:32 +08:00
parent fae6d2ce50
commit 4d69bea70b
12 changed files with 192 additions and 23 deletions

View File

@ -1,4 +1,5 @@
using Billing.Languages;
using Billing.Models;
using System;
using System.Globalization;
using Xamarin.Forms;
@ -24,17 +25,36 @@ namespace Billing.UI
public class MoneyConverter : IValueConverter
{
public bool MarkVisible { get; set; } = true;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is decimal d)
{
return "¥ " + d.ToString("n2", CultureInfo.InvariantCulture);
var number = d.ToString("n2");
if (MarkVisible)
{
return "¥ " + number;
}
return number;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string s)
{
if (s.StartsWith("¥ "))
{
s = s[2..];
}
if (decimal.TryParse(s, out decimal d))
{
return d;
}
return 0m;
}
return value;
}
}
@ -51,4 +71,28 @@ namespace Billing.UI
return value;
}
}
public class AccountCategoryConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is AccountCategory category)
{
return category switch
{
AccountCategory.Cash => Resource.Cash,
AccountCategory.CreditCard => Resource.CreditCard,
AccountCategory.DebitCard => Resource.DebitCard,
AccountCategory.ElecAccount => Resource.ElecAccount,
_ => category.ToString()
};
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
}