48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Windows.Data;
|
|
using Prism.Ioc;
|
|
|
|
namespace Cowain.Bake.BLL.Converter
|
|
{
|
|
public class StationIdConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value == null)
|
|
throw new ArgumentNullException("value can not be null");
|
|
if (value is int val)
|
|
{
|
|
var p = MyAppContainer.Current.Resolve<MemoryDataProvider>().AllStation.Where(x => x.Id == val).FirstOrDefault();
|
|
if (null == p)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return p.Desc;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is string val)
|
|
{
|
|
var p = MyAppContainer.Current.Resolve<MemoryDataProvider>().AllStation.Where(x => x.Name == val).FirstOrDefault();
|
|
if (null == p)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return p.Id;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
}
|