using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace BPA.SingleDevice.Converters
{
    public class MateialCodeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is not null && !String.IsNullOrEmpty(value.ToString()))
            {
                var code = value.ToString();
                var result = SqlHelper.GetInstance.GetListAsync<MaterialTB>().Result;
                if (result.IsSuccess)
                {
                    var b= result.Content.FirstOrDefault(m => m.MaterialCode == code);
                    if (b is not null)
                    {
                        return b.Name;
                    }
                }
            }
            return Binding.DoNothing;
        }

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