ValueConverter.cs 9.74 KB
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;

namespace HH_WCS_Standard
{
    public class TaskStateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "状态错误";
            }
            foreach (E_TaskState enum1 in Enum.GetValues(typeof(E_TaskState)))
            {
                if (value.ToString() == enum1.GetIndexString())
                {
                    return enum1;
                }
            }
            return "异常状态";
        }

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

    public class DeviceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return value;
            }
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return value;
            }
            var result = App.f_ServiceModels.FirstOrDefault(a => a.device.Code == value.ToString());
            if (result != null)
            {
                return result.device.Name;
            }
            else
            {
                return value.ToString();
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    public class TimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "类型错误";
            }
            int millisecond;
            if (int.TryParse(value.ToString(), out millisecond))
            {
                string result = "";
                int hour = 0;
                int minute = 0;
                int second = 0;
                int.TryParse((millisecond/1000).ToString(),out second);
                if (second > 60)
                {
                    if (second > 3600)
                    {
                        hour = second / 3600;
                        minute = second % 3600 / 60;
                        second = second % 3600 % 60 % 60;
                    }
                    else
                    {
                        minute = second / 60;
                        second %= 60;
                    }
                }
                result = hour.ToString().PadLeft(2, '0') + ":" + minute.ToString().PadLeft(2, '0') + ":" + second.ToString().PadLeft(2, '0');
                return result;
            }
            return "异常数值";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
     
    public class TaskTypeConverter : IValueConverter
    {
       
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "状态错误";
            }
            foreach (E_TaskType enum1 in Enum.GetValues(typeof(E_TaskType)))
            {
                if (value.ToString() == enum1.GetIndexString())
                {
                    return enum1;
                }
            }
            return "异常状态";
        }

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

    public class SrmTaskTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "类型错误";
            }
            foreach (E_SrmTaskType enum1 in Enum.GetValues(typeof(E_SrmTaskType)))
            {
                if (value.ToString() == enum1.GetIndexString())
                {
                    return enum1;
                }
            }
            return "异常类型";
        }

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

    public class SrmLimitConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "类型错误";
            }
            foreach (E_TaskLimit enum1 in Enum.GetValues(typeof(E_TaskLimit)))
            {
                if (value.ToString() == enum1.GetIndexString())
                {
                    return enum1;
                }
            }
            return "异常类型";
        }

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

    public class SrmForkStateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "类型错误";
            }
            foreach (E_SrmForkState enum1 in Enum.GetValues(typeof(E_SrmForkState)))
            {
                if (value.ToString() == enum1.GetIndexString())
                {
                    return enum1;
                }
            }
            return "异常类型";
        }

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

    public class SrmModeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "类型错误";
            }
            foreach (E_SrmMode enum1 in Enum.GetValues(typeof(E_SrmMode)))
            {
                if (value.ToString() == enum1.GetIndexString())
                {
                    return enum1;
                }
            }
            return "异常类型";
        }

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

    public class PoseTypeByNameConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "类型错误";
            }
            var pose = App.poseList.FirstOrDefault(a => a.wcName == value.ToString());
            if (pose != null)
            {
                return pose.wcTypeName;
            }
            if (value.ToString() == "InStation")
            {
                return "堆垛机取站台";
            }
            if (value.ToString() == "OutStation")
            {
                return "堆垛机放站台";
            }
            if (value.ToString() == "Entrance")
            {
                return "任务起点";
            }
            if (value.ToString() == "Exit")
            {
                return "任务终点";
            }

            return "异常类型";
        }

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

    public class PoseTypeByTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "类型错误";
            }
            if (value.ToString() == "Entrance")
            {
                return "入库口";
            }
            if (value.ToString() == "Exit")
            {
                return "出库口";
            }
            var pose = App.poseList.FirstOrDefault(a => a.wcType == value.ToString());
            if (pose != null)
            {
                return pose.wcTypeName;
            }

            return "异常类型";
        }

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

    public class StationOccpyByTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "类型错误";
            }
            if (value.ToString() == "1" || value.ToString().ToLower() == "true")
            {
                return "有货";
            }
            else if (value.ToString() == "0" || value.ToString().ToLower() == "false")
            {
                return "无货";
            }
            else
                return "异常类型";
        }

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