首次提交:添加src文件夹代码

This commit is contained in:
2026-02-27 14:02:43 +08:00
commit d330cfbca7
4184 changed files with 5546478 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
using Cowain.Bake.Common.Enums;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class BatteryStatusConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
value = System.Convert.ToInt32(value);
EBatteryStatus status = (EBatteryStatus)value;
return status.FetchDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace Cowain.Bake.Common.Converter
{
public class BindingColor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value.ToString() == "报警")
{
return new SolidColorBrush(Colors.Red);
}
else if (value.ToString() == "警告")
{
return new SolidColorBrush(Colors.Gold);
}
else
{
return new SolidColorBrush(Colors.Green);
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,29 @@
using Cowain.Bake.Common.Enums;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace Cowain.Bake.Common.Converter
{
public class BoolToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return boolValue ? Brushes.Green : Brushes.Red;
}
return Brushes.Gray;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return boolValue ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,43 @@
using Cowain.Bake.Common.Enums;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class DeviceTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var list = EnumHelper.GetEnumList<EDeviceType>();
return list.FirstOrDefault(s => s.EnumString == value.ToString())?.EnumDesc;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (value is true) ? parameter : Binding.DoNothing;
}
}
public class OperTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
OperTypeEnum paramEnum = (OperTypeEnum)int.Parse(value.ToString());
return paramEnum.GetDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (value is true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Cowain.Bake.Common.Enums;
namespace Cowain.Bake.Common.Converter
{
public class DummyRuleConvertor:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) { return null; }
int rule = System.Convert.ToInt32(value);
DummyPlaceRule a = (DummyPlaceRule)rule;
return a.GetDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Cowain.Bake.Common.Enums;
namespace Cowain.Bake.Common.Converter
{
public class DummyStatusConvertor:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
value = System.Convert.ToInt32(value);
EPalletDummyState EPalletDummyState = (EPalletDummyState)value;
return EPalletDummyState.FetchDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class EnumDescriptionConverter : IValueConverter
{
private string GetEnumDescription(Enum enumObj)
{
FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
var descriptionAttr = fieldInfo
.GetCustomAttributes(false)
.OfType<DescriptionAttribute>()
.Cast<DescriptionAttribute>()
.SingleOrDefault();
if (descriptionAttr == null)
{
return enumObj.ToString();
}
else
{
return descriptionAttr.Description;
}
}
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Enum myEnum = (Enum)value;
string description = GetEnumDescription(myEnum);
return description;
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.Empty;
}
}
public class EnumDescriptionTypeConverter : EnumConverter
{
public EnumDescriptionTypeConverter(Type type) : base(type)
{
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
if (null != value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
if (null != fi)
{
var attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
return ((attributes.Length > 0) && (!string.IsNullOrEmpty(attributes[0].Description)))
? attributes[0].Description
: value.ToString();
}
}
return string.Empty;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}

View File

@@ -0,0 +1,30 @@
using Cowain.Bake.Common.Enums;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class IntToDeviceTypeConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
value = System.Convert.ToInt32(value);
EDeviceType status = (EDeviceType)value;
return status.FetchDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
/// <summary>
/// 状态转换器
/// </summary>
public class ObjectConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string[] parray = parameter.ToString().ToLower().Split(':'); //将参数字符分段 parray[0]为比较值parray[1]为true返回值parray[2]为false返回值
if (value == null)
return parray[2]; //如果数据源为空默认返回false返回值
if (parray[0].Contains("|")) //判断有多个比较值的情况
return parray[0].Split('|').Contains(value.ToString().ToLower()) ? parray[1] : parray[2]; //多值比较
return parray[0].Equals(value.ToString().ToLower()) ? parray[1] : parray[2]; //单值比较
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var returnValue = "otherValue";
string[] parray = parameter.ToString().ToLower().Split(':');
if (value == null)
return returnValue;
var valueStr = value.ToString().ToLower();
if (valueStr != parray[1])
return returnValue;
else
return parray[0].Contains('|') ? parray[0].Split('|')[0] : parray[0];
}
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Cowain.Bake.Common.Enums;
namespace Cowain.Bake.Common.Converter
{
public class PalletStatusConvertor:IValueConverter
{
private string GetEnumDescription(Enum enumObj)
{
FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
var descriptionAttr = fieldInfo
.GetCustomAttributes(false)
.OfType<DescriptionAttribute>()
.Cast<DescriptionAttribute>()
.SingleOrDefault();
if (descriptionAttr == null)
{
return enumObj.ToString();
}
else
{
return descriptionAttr.Description;
}
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
value = System.Convert.ToInt32(value);
EPalletStatus status = (EPalletStatus)value;
return status.FetchDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
EPalletStatus e = EnumHelper.GetValueByDescription<EPalletStatus>((string)value);
return (int)e;
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class ProductOutputTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (value is true) ? parameter : Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class RadioButtonToIndexConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// 将 RadioButton 的值与 ViewModel 中的值进行比较并返回是否匹配
if (value == null || parameter == null)
return false;
return value.ToString() == parameter.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// 这个转换通常不需要,可以简单地返回 DependencyProperty.UnsetValue
if ((bool)value)
{
return parameter;
}
return DependencyProperty.UnsetValue;
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class ScaleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter == null)
throw new ArgumentNullException("value can not be null");
if (value == null)
throw new ArgumentNullException("value can not be null");
double c = System.Convert.ToDouble(parameter);
double index = System.Convert.ToDouble(value);
return index / c;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter == null)
throw new ArgumentNullException("value can not be null");
if (value == null)
throw new ArgumentNullException("value can not be null");
double c = System.Convert.ToDouble(parameter);
double index = System.Convert.ToDouble(value);
return System.Convert.ToInt32(index * c);
}
}
}

View File

@@ -0,0 +1,26 @@
using Cowain.Bake.Common.Enums;
using System;
using System.Globalization;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class SendFlagConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
value = System.Convert.ToInt32(value);
EMesUpLoadStatus status = (EMesUpLoadStatus)value;
return status.FetchDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using Cowain.Bake.Common.Enums;
using Prism.Ioc;
namespace Cowain.Bake.Common.Converter
{
public class StationTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
value = System.Convert.ToInt32(value);
EStationType status = (EStationType)value;
return status.FetchDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
EStationType e = EnumHelper.GetValueByDescription<EStationType>((string)value);
return (int)e;
}
}
}

View File

@@ -0,0 +1,26 @@
using Cowain.Bake.Common.Enums;
using System;
using System.Globalization;
using System.Windows.Data;
namespace Cowain.Bake.Common.Converter
{
public class TaskCmdConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
value = System.Convert.ToInt32(value);
ETaskStep status = (ETaskStep)value;
return status.FetchDescription();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}