schangxiang@126.com
2025-11-04 ca398287db3f5ea01f03aac4a85edb13b28100a6
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
using HxEnum;
using System;
using System.Configuration;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using XCommon;
using XImagingXhandler.XDAL;
 
namespace XHandler.Class
{
    public class CmdBackgroundConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int nVal = int.Parse((string)value);
 
            switch (nVal)
            {
                case 1:
                    return new SolidColorBrush(Color.FromArgb(255, 252, 241, 219));
                case 2:
                    return new SolidColorBrush(Color.FromArgb(255, 223, 244, 255));
                case 3:
                    return new SolidColorBrush(Color.FromArgb(255, 226, 255, 221));
                case 4:
                    return new SolidColorBrush(Color.FromArgb(255, 255, 232, 245));
                case 5:
                    return new SolidColorBrush(Color.FromArgb(255, 239, 247, 255));
                case 6:
                    return new SolidColorBrush(Color.FromArgb(255, 255, 217, 216));
                default:
                    return new SolidColorBrush(Color.FromArgb(255, 242, 242, 242));
            }
                
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    /// <summary>
    /// Todo 暂未使用
    /// </summary>
    public class CmdIconConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string icon = (string)value;
            string iconPath = "pack://application:,,,./Assets/CmdSet/"+icon;
            return (ImageSource)new ImageSourceConverter().ConvertFrom(new Uri(iconPath));
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class IntToVisibleConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int val = (int)value;
            if (val == 1)
                return Visibility.Visible;
            else
                return Visibility.Collapsed;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class BoolToBackgroundConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool val = (int)value == 1 ? true:false;
            if (val)
                return Brushes.LightGreen;
            else
                return Brushes.Transparent;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class IntToEnableConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int val = (int)value;
            if (val == 1)
                return false;
            else
                return true;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class PercentageConverter : IValueConverter
    {
        public object Convert(object value,
            Type targetType,
            object parameter,
            System.Globalization.CultureInfo culture)
        {
            return System.Convert.ToDouble(value) *
                   System.Convert.ToDouble(parameter);
        }
 
        public object ConvertBack(object value,
            Type targetType,
            object parameter,
            System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    
 
    public class ColorConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string strColor = (string)value;
 
            Color color = ComUtility.RGBToColor(strColor);
            //Color color = (Color)ColorConverter.ConvertFromString(strColor);
            return color;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class LeverToThicknessConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int level = (int)value;
            int left = level * 40;
            Thickness thickness = new Thickness(0,0,0,0);
            thickness.Left = left;
            return thickness;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class BrushTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
            //PropertyInfo propertyInfo = value as PropertyInfo;
            //return propertyInfo.GetValue(value) as SolidColorBrush;
            BrushItem item = value as BrushItem;
            return item.Value;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class EnableToBrush : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool enable = (bool)value;
            if (enable)
                return Brushes.Black;
            else
                return Brushes.Gray;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
 
    public class CmdBackgroundMultiConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            int methodGroupId = int.Parse(values[0].ToString());
            int support = int.Parse(values[1].ToString());
 
            // 不支持
            if (support == EnumManagement.GetEnumValue(MethodSupportEnum.NoSupport))
            {
                return new SolidColorBrush(Colors.LightGray);
            }
       
            // 1:单步液体处理
            if (methodGroupId == EnumManagement.GetEnumValue(MethodGroupEnum.SingleStep))
            {
                return new SolidColorBrush(Color.FromArgb(255, 252, 241, 219));
            }
            // 2:组合液体处理
            else if (methodGroupId == EnumManagement.GetEnumValue(MethodGroupEnum.MultiSteps))
            {
                return new SolidColorBrush(Color.FromArgb(255, 223, 244, 255));
            }
            // 3:抓手命令
            else if (methodGroupId == EnumManagement.GetEnumValue(MethodGroupEnum.GripperCommand))
            {
                return new SolidColorBrush(Color.FromArgb(255, 226, 255, 221));
            }
            // 4:控制命令
            else if (methodGroupId == EnumManagement.GetEnumValue(MethodGroupEnum.ControlCommand))
            {
                return new SolidColorBrush(Color.FromArgb(255, 255, 232, 245));
            }
            // 5:数据处理
            else if (methodGroupId == EnumManagement.GetEnumValue(MethodGroupEnum.DataProcess))
            {
                return new SolidColorBrush(Color.FromArgb(255, 239, 247, 255));
            }
            // 6:第三方设备
            else if (methodGroupId == EnumManagement.GetEnumValue(MethodGroupEnum.ThirdPart))
            {
                return new SolidColorBrush(Color.FromArgb(255, 255, 217, 216));
            }
            else
            {
                return new SolidColorBrush(Color.FromArgb(255, 242, 242, 242));
            }
        }
 
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
 
    public class CmdIconMultiConvert : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string icon = values[0].ToString();
            string support = values[1]==null?"" : values[1].ToString();
            int methodGroupId = int.Parse(values[2].ToString());
 
            if (string.IsNullOrEmpty(icon))
                return null;
            // 第三方设备的图片由Base64字符串转换
            if (methodGroupId == EnumManagement.GetEnumValue(MethodGroupEnum.ThirdPart))
            {
                // 字符串转Image
                return ComUtility.StringToImag(icon);
            }
            else
            {
                string iconPath = "pack://application:,,,./Assets/CmdSet/" + icon;
                if (support == "0")
                {
                    string name = System.IO.Path.GetFileNameWithoutExtension(icon);
                    string ext = System.IO.Path.GetExtension(icon);
                    iconPath = "pack://application:,,,./Assets/CmdSet/" + name + "disable" + ext;
                }
 
                Uri uri = new Uri(iconPath, UriKind.Absolute);
                BitmapImage bitmap = new BitmapImage(uri);
 
                return bitmap;
            }
 
        }
 
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            var splitValues = ((string)value).Split(' ');
            return splitValues;
        }
    }
 
    public class WorkflowIconMultiConvert : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string icon = values[0].ToString();
            bool enable = (bool)values[1];
            int methodGroupId = int.Parse(values[2].ToString());
 
            // 第三方设备的图片由Base64字符串转换
            if (methodGroupId == EnumManagement.GetEnumValue(MethodGroupEnum.ThirdPart))
            {
                // 字符串转Image
                return ComUtility.StringToImag(icon);
            }
            else
            {
                string iconPath = "pack://application:,,,./Assets/CmdSet/" + icon;
                if (!enable)
                {
                    string name = System.IO.Path.GetFileNameWithoutExtension(icon);
                    string ext = System.IO.Path.GetExtension(icon);
                    iconPath = "pack://application:,,,./Assets/CmdSet/" + name + "disable" + ext;
                }
 
                Uri uri = new Uri(iconPath, UriKind.Absolute);
                BitmapImage bitmap = new BitmapImage(uri);
                return bitmap;
            }
        }
 
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            var splitValues = ((string)value).Split(' ');
            return splitValues;
        }
    }
 
    /// <summary>
    /// true则隐藏,false则显示
    /// </summary>
    public class IsLastItemConverter : IMultiValueConverter
    {
        #region IValueConverter 成员
 
        public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ContentControl contentPresenter = value[0] as ContentControl;
            ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(contentPresenter);
 
            bool flag = false;
            if (itemsControl != null)
            {
                int index = itemsControl.ItemContainerGenerator.IndexFromContainer(contentPresenter);
                flag = (index == (itemsControl.Items.Count - 1));
            }
 
            return flag;
        }
        public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
        #endregion
    }
 
    public class AutoManulaConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string val = value.ToString();
            if (val == "0")
                return Properties.Resources.strAuto;
            else
                return Properties.Resources.strManual;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class PickModeStringConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool val = (bool)value;
            if (val)
                return Properties.Resources.strManualAdded;
            else
                return Properties.Resources.strImagingSystem;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class YesNoStringConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool val = (bool)value;
            if (val)
                return Properties.Resources.strYes;
            else
                return Properties.Resources.strNo1;
 
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class ExecResultStringConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int val = (int)value;
            if (val == 0)
                return Properties.Resources.strFailed;
            else
                return Properties.Resources.strSuccess;
 
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
    
 
    public class MethodBackgroundConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int error = (int)value;
            if (error == 1)//有错
                return new SolidColorBrush(Color.FromArgb(0x30, 0xFF, 0,0));
            if (error == 2)//运行时
                return new SolidColorBrush(Color.FromArgb(0xFF, 0x80, 0xFF, 0x80));
            else
                return Brushes.White;
 
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    public class MethodSelectedBackgroundConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int error = (int)value;
            if (error == 1)//有错
            {
                return new SolidColorBrush(Color.FromArgb(0x30, 0xFF, 0, 0));
            }
            else if (error == 0)//正常
            {
                return new SolidColorBrush(Color.FromArgb(0xFF, 0xDB, 0xEC, 0xFF));
            }
            else if (error == 2)//运行过
            {
                return new SolidColorBrush(Color.FromArgb(0xFF, 0x80, 0xFF, 0x80));
            }
            else
            {
                return new SolidColorBrush(Color.FromArgb(0xFF, 0xDB, 0xEC, 0xFF));
            }
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    /// <summary>
    /// 已运行的节点颜色
    /// </summary>
    public class MethodRanBackgroundConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool error = (bool)value;
            if (error)
            {
                return new SolidColorBrush(Color.FromRgb(0xFF, 0, 0));
            }
            else
            {
                return new SolidColorBrush(Color.FromRgb(0x90, 0xEE, 0x90));
            }
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
 
    /// <summary>
    /// 图片Base64字符串转换器
    /// </summary>
    public class Base64ToImage : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 字符串转Image
            var base64String = (String)value;
            return ComUtility.StringToImag(base64String);
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
 
    public class StatusToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int val = System.Convert.ToInt32(value.ToString());
            int nVal = val;
 
            switch (nVal)
            {
                case 0:
                    return Properties.UserResource.strLock;
                case 1:
                    return Properties.UserResource.strNormal;
                default:
                    return "";
            }
 
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}