领胜LDS 键盘AOI检测项目
xcd
2020-06-24 d6c577e17ee7bb5331dd51d803f9b42441b0f0e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using static Bro.Common.Helper.EnumHelper;
 
namespace Bro.UI.Converter
{
    /// <summary>
    /// 取反转换
    /// </summary>
    public class InverseConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return !(bool)value;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return !(bool)value;
        }
    }
 
    /// <summary>
    /// 设备状态转换
    /// </summary>
    public class DeviceStateColorConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DeviceState state = (DeviceState)value;
            return state.GetEnumSelectedColorString();
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
 
    /// <summary>
    /// 布尔状态显示转换
    /// </summary>
    public class CurrentStateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return "LightBlue";
            }
            else if ((bool)value == true)
            {
                return "LightGreen";
            }
            else
            {
                return "LightGray";
            }
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
 
    /// <summary>
    /// 布尔状态显示转换
    /// </summary>
    public class IndicatorStateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return "Transparent";
            }
            else if ((bool)value == true)
            {
                return "LightGreen";
            }
            else
            {
                return "Red";
            }
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
 
    /// <summary>
    /// 布尔状态显示转换
    /// </summary>
    public class IndicatorTextConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return "TBD";
            }
            else if ((bool)value == true)
            {
                return "OK";
            }
            else
            {
                return "NG";
            }
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
 
    [ValueConversion(typeof(float), typeof(float))]
    public class SimpleCalculationConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            float input = System.Convert.ToSingle(value);
            string paraStr = parameter?.ToString();
 
            if (!(paraStr == null || paraStr.Trim().Length <= 1))
            {
                string opChar = paraStr[0].ToString();
                float para = 0;
 
                if (Single.TryParse(paraStr.Substring(1), out para))
                {
                    switch (opChar)
                    {
                        case "+":
                            input += para;
                            break;
                        case "-":
                            input -= para;
                            break;
                        case "*":
                            input *= para;
                            break;
                        case "/":
                            input /= para;
                            break;
                    }
                }
            }
 
            return input;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}