add account
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user