using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Net;

namespace FLY.Thick.Base.UI.Converter
{
    public class BoltNo2BoltIndexConverter : IMultiValueConverter
    {
        #region IMultiValueConverter 成员

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int firstBoltNo = (int)values[0];
            int boltNo = (int)values[1];
            return boltNo - firstBoltNo;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }





    public class DoubleConverter : IValueConverter
    {
        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double thick = (double)value;
            return thick.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double thick = 0;
            if (double.TryParse(value as string, out thick))
            {
                return thick;
            }
            return thick;
        }

        #endregion
    }
    
    public class NormalConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value.ToString();
        }


        #endregion

        #region IValueConverter 成员


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

        #endregion
    }
    public class FileAttrConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((System.IO.FileAttributes)value == System.IO.FileAttributes.Directory)
            {
                return @"Images\folder2.png";
            }
            else
            {
                return @"Images\document.png";
            }
        }


        #endregion

        #region IValueConverter 成员


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

        #endregion
    }
    public class UpdateConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((bool)value == true)
            {
                return @"Images\download.png";
            }
            else
            {
                return null;
            }
        }


        #endregion

        #region IValueConverter 成员


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

        #endregion
    }


    public class LanguageConverter : IValueConverter
    {
        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            string language = (string)value;
            
            string str = (string)parameter;

            if ((str.CompareTo(language) == 0))
            {
                return true;
            }
            else
                return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool b = (bool)value;
            string str = (string)parameter;

            if (b)
                return str;
            else
                return null;
        }

        #endregion
    }

}
