98 lines
2.8 KiB
C#
98 lines
2.8 KiB
C#
using Billing.Languages;
|
|
using Billing.Models;
|
|
using System;
|
|
using System.Globalization;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Billing.UI
|
|
{
|
|
public class TitleDateConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is DateTime date)
|
|
{
|
|
return date.ToString(Resource.TitleDateFormat);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return value;
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
public class NotNullConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return value != null;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
} |