using System;
using System.Globalization;
using System.Windows.Data;

namespace BeWo.Converter
{
    [ValueConversion(typeof(DateTime?), typeof(string))]
    public class DateNullValueToEmptyStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime? dt = System.Convert.ToDateTime(value);

            return (dt == null || dt.Value.Millisecond == 123) ? string.Empty : value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    [ValueConversion(typeof(decimal?), typeof(string))]
    public class DecimalNullValueToEmptyStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            decimal? dec = System.Convert.ToDecimal(value);
            bool empty = value == null || dec == null || dec.Value == (decimal)0.00123;
            return empty ? string.Empty : value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}