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;
|
}
|
}
|
}
|