上传界面显示
This commit is contained in:
771
DH.Commons/Helper/EnumHelper.cs
Normal file
771
DH.Commons/Helper/EnumHelper.cs
Normal file
@ -0,0 +1,771 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DH.Commons.Enums
|
||||
{
|
||||
public static class EnumHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据枚举的代码名称获取枚举列表信息
|
||||
/// </summary>
|
||||
/// <param name="enumName"></param>
|
||||
/// <returns></returns>
|
||||
public static List<dynamic> GetEnumListByName(string enumName, string assemblyName = "Common.Model.Helper.EnumHelper+")
|
||||
{
|
||||
List<dynamic> list = new List<dynamic>();
|
||||
|
||||
string fullName = assemblyName + enumName;
|
||||
|
||||
Type t = typeof(EnumHelper).Assembly.GetType(fullName);
|
||||
|
||||
t.GetEnumNames().ToList().ForEach(e =>
|
||||
{
|
||||
int value = Convert.ToInt32(Enum.Parse(t, e));
|
||||
string desc = ((Enum)Enum.Parse(t, e)).GetEnumDescription();
|
||||
var item = new { Value = value, Desc = desc, Code = e };
|
||||
list.Add(item);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举的列表信息,一般供下拉列表使用
|
||||
/// </summary>
|
||||
/// <param name="enumType">枚举类型</param>
|
||||
/// <returns>Desc:中文描述 Value:整形值 Code:枚举值</returns>
|
||||
public static List<dynamic> GetEnumListByType(Type enumType)
|
||||
{
|
||||
List<dynamic> list = new List<dynamic>();
|
||||
|
||||
enumType.GetEnumNames().ToList().ForEach(e =>
|
||||
{
|
||||
int value = Convert.ToInt32(Enum.Parse(enumType, e));
|
||||
string desc = ((Enum)Enum.Parse(enumType, e)).GetEnumDescription();
|
||||
var item = new { Value = value, Desc = desc, Code = e };
|
||||
list.Add(item);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取具体某一枚举的中文描述
|
||||
/// </summary>
|
||||
/// <param name="enumObj"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetEnumDescription(this Enum enumObj)
|
||||
{
|
||||
Type t = enumObj.GetType();
|
||||
FieldInfo f = t.GetField(enumObj.ToString());
|
||||
if (f == null)
|
||||
{
|
||||
return enumObj.ToString();
|
||||
}
|
||||
DescriptionAttribute attr = f.GetCustomAttribute<DescriptionAttribute>();
|
||||
if (attr != null)
|
||||
{
|
||||
return attr.Description;
|
||||
}
|
||||
else
|
||||
{
|
||||
return enumObj.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
//public static System.Windows.Media.Color GetEnumSelectedMediaColor(this Enum enumObj)
|
||||
//{
|
||||
// Type t = enumObj.GetType();
|
||||
// FieldInfo f = t.GetField(enumObj.ToString());
|
||||
|
||||
// ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
|
||||
// if (attr != null)
|
||||
// {
|
||||
// var prop = typeof(System.Windows.Media.Colors).GetProperties().FirstOrDefault(p => p.Name == attr.SelectedColor);
|
||||
// if (prop != null)
|
||||
// {
|
||||
// return (System.Windows.Media.Color)prop.GetValue(null);
|
||||
// }
|
||||
// }
|
||||
// return System.Windows.Media.Colors.Transparent;
|
||||
//}
|
||||
|
||||
//public static System.Drawing.Color GetEnumSelectedColor(this Enum enumObj)
|
||||
//{
|
||||
// Type t = enumObj.GetType();
|
||||
// FieldInfo f = t.GetField(enumObj.ToString());
|
||||
|
||||
// ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
|
||||
// if (attr != null)
|
||||
// {
|
||||
// return System.Drawing.Color.FromName(attr.SelectedColor);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return System.Drawing.Color.Transparent;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public static System.Drawing.Color GetEnumSelectedFontColor(this Enum enumObj)
|
||||
//{
|
||||
// Type t = enumObj.GetType();
|
||||
// FieldInfo f = t.GetField(enumObj.ToString());
|
||||
|
||||
// var attr = f.GetCustomAttribute<FontColorSelectAttribute>();
|
||||
// if (attr != null)
|
||||
// {
|
||||
// return System.Drawing.Color.FromName(attr.SelectedColor);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return System.Drawing.Color.Transparent;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public static string GetEnumSelectedColorString(this Enum enumObj)
|
||||
//{
|
||||
// Type t = enumObj.GetType();
|
||||
// FieldInfo f = t.GetField(enumObj.ToString());
|
||||
|
||||
// ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
|
||||
// if (attr != null)
|
||||
// {
|
||||
// return attr.SelectedColor;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return "Transparent";
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当枚举牵涉到状态变换,检查现状态是否满足待转换的状态的前置状态要求
|
||||
/// </summary>
|
||||
/// <param name="stateToBe"></param>
|
||||
/// <param name="currentState"></param>
|
||||
/// <returns></returns>
|
||||
//public static bool CheckPreStateValid(this Enum stateToBe, int currentState)
|
||||
//{
|
||||
// Type t = stateToBe.GetType();
|
||||
// FieldInfo f = t.GetField(stateToBe.ToString());
|
||||
|
||||
// PreStateAttribute attr = f.GetCustomAttribute<PreStateAttribute>();
|
||||
// if (attr == null)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return attr.CheckPreStateValid(currentState);
|
||||
// }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 设备状态定义
|
||||
/// 未初始化和异常状态无前置状态要求
|
||||
/// 初始化操作前置状态必须是未初始化、关闭状态和异常状态
|
||||
/// 打开前置必须是初始化和暂停
|
||||
/// 关闭前置必须是打开和暂停和异常
|
||||
/// 暂停前置必须是打开
|
||||
/// </summary>
|
||||
//public enum DeviceState
|
||||
//{
|
||||
// TBD = -1,
|
||||
|
||||
// [ColorSelect("Gray")]
|
||||
// [FontColorSelect("Black")]
|
||||
// [Description("未初始化")]
|
||||
// DSUninit = 1,
|
||||
|
||||
// [ColorSelect("Gold")]
|
||||
// [FontColorSelect("White")]
|
||||
// [PreState(1 + 2 + 4 + 8 + 32)]
|
||||
// [Description("初始化")]
|
||||
// DSInit = 2,
|
||||
|
||||
// [ColorSelect("Lime")]
|
||||
// [FontColorSelect("Black")]
|
||||
// [PreState(2 + 4 + 16)]
|
||||
// [Description("运行中")]
|
||||
// DSOpen = 4,
|
||||
|
||||
// [ColorSelect("Gray")]
|
||||
// [FontColorSelect("White")]
|
||||
// [PreState(1 + 4 + 8 + 16 + 32)]
|
||||
// [Description("关闭")]
|
||||
// DSClose = 8,
|
||||
|
||||
// [ColorSelect("Gold")]
|
||||
// [FontColorSelect("White")]
|
||||
// [PreState(4 + 16)]
|
||||
// [Description("暂停")]
|
||||
// DSPause = 16,
|
||||
|
||||
// [ColorSelect("Red")]
|
||||
// [FontColorSelect("White")]
|
||||
// [Description("异常")]
|
||||
// DSExcept = 32
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// 工序状态
|
||||
///// </summary>
|
||||
//public enum RunState
|
||||
//{
|
||||
// [ColorSelect("Gold")]
|
||||
// [Description("空闲")]
|
||||
// Idle = 1,
|
||||
// [ColorSelect("Lime")]
|
||||
// [Description("运行中")]
|
||||
// Running = 2,
|
||||
// [ColorSelect("Gray")]
|
||||
// [Description("停止")]
|
||||
// Stop = 3,
|
||||
// [ColorSelect("Red")]
|
||||
// [Description("宕机")]
|
||||
// Down = 99,
|
||||
//}
|
||||
|
||||
[Flags]
|
||||
public enum DeviceAttributeType
|
||||
{
|
||||
[Description("设备驱动")]
|
||||
Device = 1,
|
||||
|
||||
[Description("初始配置")]
|
||||
InitialConfig = 2,
|
||||
[Description("操作配置")]
|
||||
OperationConfig = 4,
|
||||
[Description("设备配置")]
|
||||
DeviceConfig = 8,
|
||||
[Description("输入配置")]
|
||||
InputConfig = 16,
|
||||
|
||||
[Description("初始配置控件")]
|
||||
InitialConfigCtrl = 32,
|
||||
[Description("操作配置控件")]
|
||||
OperationConfigCtrl = 64,
|
||||
[Description("设备配置控件")]
|
||||
DeviceConfigCtrl = 128,
|
||||
[Description("输入配置控件")]
|
||||
InputConfigCtrl = 256,
|
||||
|
||||
[Description("运行控件")]
|
||||
RunCtrl = 512,
|
||||
|
||||
[Description("操作配置面板")]
|
||||
OperationConfigPanel = 1024,
|
||||
}
|
||||
|
||||
public enum EnableState
|
||||
{
|
||||
[Description("启用")]
|
||||
Enabled = 0,
|
||||
[Description("禁用")]
|
||||
Disabled = 1,
|
||||
}
|
||||
|
||||
public enum EnableStateFilter
|
||||
{
|
||||
[Description("全部")]
|
||||
All = -1,
|
||||
[Description("启用")]
|
||||
Enabled = 0,
|
||||
[Description("禁用")]
|
||||
Disabled = 1,
|
||||
}
|
||||
|
||||
public enum OutputResult
|
||||
{
|
||||
[Description("OK")]
|
||||
OK = 1,
|
||||
[Description("NG")]
|
||||
NG = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PLC项目的值的类型
|
||||
/// </summary>
|
||||
public enum PLCItemType
|
||||
{
|
||||
[Description("布尔类型")]
|
||||
Bool = 0,
|
||||
[Description("整型")]
|
||||
Integer = 1,
|
||||
[Description("字符串型")]
|
||||
String = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对PLC项目的操作类型
|
||||
/// </summary>
|
||||
public enum PLCOpType
|
||||
{
|
||||
[Description("读取")]
|
||||
Read = 1,
|
||||
[Description("写入")]
|
||||
Write = 2,
|
||||
[Description("监控")]
|
||||
Monitor = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 报警监控 1+8
|
||||
/// </summary>
|
||||
[Description("报警监控")]
|
||||
WarningMonitor = 9,
|
||||
|
||||
/// <summary>
|
||||
/// CT监控 1+16
|
||||
/// </summary>
|
||||
[Description("CT监控")]
|
||||
CTMonitor = 17,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 相机运行模式
|
||||
/// </summary>
|
||||
public enum CameraOpMode
|
||||
{
|
||||
[Description("单次拍照")]
|
||||
SingleSnapShot = 1,
|
||||
[Description("连续模式")]
|
||||
ContinuousMode = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日志类型
|
||||
/// </summary>
|
||||
public enum LogType
|
||||
{
|
||||
[Description("警告信息")]
|
||||
Exception_Warning = 1,
|
||||
[Description("错误信息")]
|
||||
Exception_Error = 2,
|
||||
[Description("致命信息")]
|
||||
Exception_Fatal = 3,
|
||||
|
||||
[Description("设备信息")]
|
||||
Info_Device = 11,
|
||||
[Description("工序信息")]
|
||||
Info_Process = 12,
|
||||
[Description("操作信息")]
|
||||
Info_Operation = 13,
|
||||
|
||||
[Description("用户操作信息")]
|
||||
User_Operation = 21,
|
||||
|
||||
[Description("测量结果")]
|
||||
MeasureResult = 31,
|
||||
}
|
||||
|
||||
//public enum CameraDriverType
|
||||
//{
|
||||
// Halcon,
|
||||
// //HalconPlugIn,
|
||||
// Hik,
|
||||
//}
|
||||
|
||||
//public enum ImageType
|
||||
//{
|
||||
// Bmp,
|
||||
// Png,
|
||||
// Jpeg,
|
||||
//}
|
||||
|
||||
//public enum ReplyValue
|
||||
//{
|
||||
// OK = 1,
|
||||
// NG = -1,
|
||||
// IGNORE = -999,
|
||||
//}
|
||||
|
||||
public enum PriorityDirection
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
}
|
||||
|
||||
public enum ElementState
|
||||
{
|
||||
New = 1,
|
||||
MouseHover = 2,
|
||||
MouseInSide = 3,
|
||||
Selected = 4,
|
||||
Moving = 5,
|
||||
Editing = 6,
|
||||
|
||||
Normal = 11,
|
||||
|
||||
Measuring = 21,
|
||||
MeasureDoneOK = 22,
|
||||
MeasureDoneNG = 23,
|
||||
|
||||
CanStretchLeft = 41,
|
||||
CanStretchRight = 42,
|
||||
CanStretchTop = 43,
|
||||
CanStretchBottom = 44,
|
||||
|
||||
CanStretchLeftUpperCorner = 45,
|
||||
CanStretchLeftLowerCorner = 46,
|
||||
CanStretchRightUpperCorner = 47,
|
||||
CanStretchRightLowerCorner = 48,
|
||||
|
||||
StretchingLeft = 31,
|
||||
StretchingRight = 32,
|
||||
StretchingTop = 33,
|
||||
StretchingBottom = 34,
|
||||
|
||||
StretchingLeftUpperCorner = 35,
|
||||
StretchingLeftLowerCorner = 36,
|
||||
StretchingRightUpperCorner = 37,
|
||||
StretchingRightLowerCorner = 38,
|
||||
}
|
||||
|
||||
public enum MouseState
|
||||
{
|
||||
Normal = 1,
|
||||
HoverElement = 2,
|
||||
InSideElement = 3,
|
||||
|
||||
MoveElement = 4,
|
||||
|
||||
StretchingLeft = 11,
|
||||
StretchingRight = 12,
|
||||
StretchingTop = 13,
|
||||
StretchingBottom = 14,
|
||||
|
||||
StretchingLeftUpperCorner = 15,
|
||||
StretchingLeftLowerCorner = 16,
|
||||
StretchingRightUpperCorner = 17,
|
||||
StretchingRightLowerCorner = 18,
|
||||
|
||||
New = 21,
|
||||
Editing = 22,
|
||||
//SelectedElement = 23,
|
||||
|
||||
MovingAll = 31,
|
||||
|
||||
SelectionZone = 41,
|
||||
SelectionZoneDoing = 42,
|
||||
}
|
||||
|
||||
public enum RunMode
|
||||
{
|
||||
[Description("正常运行模式")]
|
||||
NormalMode = 1,
|
||||
[Description("调试模式")]
|
||||
DebugMode = 0,
|
||||
[Description("模拟模式")]
|
||||
DemoMode = 2,
|
||||
}
|
||||
|
||||
public enum MoveType
|
||||
{
|
||||
[Description("绝对运动")]
|
||||
AbsoluteMove = 1,
|
||||
[Description("机器人坐标系相对运动")]
|
||||
RobotRelativeMove = 2,
|
||||
[Description("相对某个基准点位的相对运动")]
|
||||
BasedPointRelativeMove = 3,
|
||||
[Description("回原点")]
|
||||
Origin = 4,
|
||||
[Description("左侧姿势")]
|
||||
LeftPose = 6,
|
||||
[Description("右侧姿势")]
|
||||
RightPose = 5,
|
||||
[Description("前侧姿势")]
|
||||
FrontPose = 7,
|
||||
[Description("相机坐标系相对运动")]
|
||||
CameraRelativeMove = 12,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 马达/运动板卡运行模式
|
||||
/// </summary>
|
||||
public enum MotionMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 普通点位运动
|
||||
/// </summary>
|
||||
[Description("普通点位运动")]
|
||||
P2P = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 找正限位运动
|
||||
/// </summary>
|
||||
[Description("找正限位运动")]
|
||||
FindPositive = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 离开正限位
|
||||
/// </summary>
|
||||
[Description("离开正限位")]
|
||||
LeavePositive = 5,
|
||||
|
||||
/// <summary>
|
||||
/// 找负限位运动
|
||||
/// </summary>
|
||||
[Description("找负限位运动")]
|
||||
FindNegative = 6,
|
||||
|
||||
/// <summary>
|
||||
/// 离开负限位
|
||||
/// </summary>
|
||||
[Description("离开负限位")]
|
||||
LeaveNegative = 7,
|
||||
|
||||
/// <summary>
|
||||
/// 找原点运动
|
||||
/// </summary>
|
||||
[Description("回原点运动")]
|
||||
GoHome = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Jog模式
|
||||
/// </summary>
|
||||
[Description("Jog模式")]
|
||||
Jog = 9,
|
||||
|
||||
///// <summary>
|
||||
///// 读数头找原点方式
|
||||
///// </summary>
|
||||
//[Description("找原点inde")]
|
||||
//FindOriIndex = 10,
|
||||
|
||||
///// <summary>
|
||||
///// 插补模式
|
||||
///// </summary>
|
||||
//[Description("插补模式")]
|
||||
//Coordinate = 11
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IO预定义类型 主要针对输出
|
||||
/// </summary>
|
||||
public enum IOPrestatement
|
||||
{
|
||||
[Description("自定义")]
|
||||
Customized = 0,
|
||||
|
||||
[Description("指示灯-黄")]
|
||||
Light_Yellow = 1,
|
||||
[Description("指示灯-绿")]
|
||||
Light_Green = 2,
|
||||
[Description("指示灯-红")]
|
||||
Light_Red = 3,
|
||||
[Description("蜂鸣器")]
|
||||
Beep = 4,
|
||||
[Description("照明灯")]
|
||||
Light = 5,
|
||||
|
||||
[Description("急停")]
|
||||
EmergencyStop = 99,
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// GTS运动板卡控制返回控制码
|
||||
///// </summary>
|
||||
//public enum GTSRetCode
|
||||
//{
|
||||
// [Description("指令执行成功")]
|
||||
// GRCRunOK = 0, // 指令执行成功
|
||||
// [Description("指令执行错误")]
|
||||
// GRCRunErr = 1, // 指令执行错误
|
||||
// [Description("icense不支持")]
|
||||
// GRCNotSupport = 2, // icense不支持
|
||||
// [Description("指令参数错误")]
|
||||
// GRCInvalidParam = 7, // 指令参数错误
|
||||
// [Description("主机和运动控制器通讯失败")]
|
||||
// GRCCommErr = -1, // 主机和运动控制器通讯失败
|
||||
// [Description("打开控制器失败")]
|
||||
// GRCOpenErr = -6, // 打开控制器失败
|
||||
// [Description("运动控制器没有响应")]
|
||||
// GRCNotAck = -7 // 运动控制器没有响应
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 运动板卡 IO 类型(IN OUT)
|
||||
/// </summary>
|
||||
public enum IOType
|
||||
{
|
||||
[Description("INPUT")]
|
||||
INPUT = 0,
|
||||
[Description("OUTPUT")]
|
||||
OUTPUT = 1
|
||||
}
|
||||
|
||||
public enum IOValue
|
||||
{
|
||||
[Description("关闭")]
|
||||
FALSE = 0,
|
||||
[Description("开启")]
|
||||
TRUE = 1,
|
||||
[Description("反转")]
|
||||
REVERSE = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PubSubCenter事件中心的消息类型
|
||||
/// </summary>
|
||||
public enum PubSubCenterMessageType
|
||||
{
|
||||
/// <summary>
|
||||
/// 运行界面更新产品下拉
|
||||
/// </summary>
|
||||
[Description("更新产品下拉")]
|
||||
UpdateProductionCodes,
|
||||
|
||||
/// <summary>
|
||||
/// 流程是否关闭
|
||||
/// </summary>
|
||||
[Description("流程是否打开")]
|
||||
IsProcessOpened,
|
||||
|
||||
/// <summary>
|
||||
/// 清除数据
|
||||
/// </summary>
|
||||
[Description("清除数据")]
|
||||
ClearData,
|
||||
/// <summary>
|
||||
/// 更新批次信息
|
||||
/// </summary>
|
||||
[Description("更新批次信息")]
|
||||
UpdateBatchNO,
|
||||
/// <summary>
|
||||
/// 请求批次信息
|
||||
/// </summary>
|
||||
[Description("更新批次信息")]
|
||||
RequestBatchNO,
|
||||
|
||||
/// <summary>
|
||||
/// 模型检测异常
|
||||
/// </summary>
|
||||
[Description("模型检测异常")]
|
||||
MLDetectException,
|
||||
}
|
||||
public enum SizeEnum
|
||||
{
|
||||
[Description("圆形测量")]
|
||||
Circle = 1,
|
||||
[Description("直线测量")]
|
||||
Line = 2,
|
||||
[Description("线线测量")]
|
||||
LineLine = 3,
|
||||
[Description("线圆测量")]
|
||||
LineCircle = 4,
|
||||
[Description("高度测量")]
|
||||
Height = 5,
|
||||
}
|
||||
|
||||
public enum MachineState
|
||||
{
|
||||
Unknown = 0,
|
||||
Ready = 1,
|
||||
Running = 2,
|
||||
Alarm = 3,
|
||||
Pause = 4,
|
||||
Resetting = 5,
|
||||
Closing = 6,
|
||||
ClearProduct = 7,
|
||||
Warning = 8,
|
||||
}
|
||||
|
||||
public enum ResultState
|
||||
{
|
||||
[Description("NA")]
|
||||
NA = -5,
|
||||
[Description("尺寸NG")]
|
||||
SizeNG = -4,
|
||||
[Description("检测NG")]
|
||||
DetectNG = -3,
|
||||
|
||||
//[Description("检测不足TBD")]
|
||||
// ShortageTBD = -2,
|
||||
[Description("检测结果TBD")]
|
||||
ResultTBD = -1,
|
||||
[Description("OK")]
|
||||
OK = 1,
|
||||
// [Description("NG")]
|
||||
// NG = 2,
|
||||
//统计结果
|
||||
[Description("A类NG")]
|
||||
A_NG = 25,
|
||||
[Description("B类NG")]
|
||||
B_NG = 26,
|
||||
[Description("C类NG")]
|
||||
C_NG = 27,
|
||||
}
|
||||
public enum HikCameraType
|
||||
{
|
||||
[Description("HikCamera-Gige")]
|
||||
Gige = 0,
|
||||
[Description("HikCamera-USB")]
|
||||
USB = 1
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 光源操作
|
||||
/// </summary>
|
||||
public enum LightOperation
|
||||
{
|
||||
[Description("打开")]
|
||||
Open = 1,
|
||||
[Description("关闭")]
|
||||
Close = 2,
|
||||
[Description("写入")]
|
||||
Write = 3,
|
||||
[Description("读取")]
|
||||
Read = 4,
|
||||
[Description("频闪")]
|
||||
Flash = 5,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监听反馈数据值
|
||||
/// </summary>
|
||||
public enum ReturnValue
|
||||
{
|
||||
OKVALUE = 1,
|
||||
NGVALUE = -1,
|
||||
EXCEPTIONVALUE = -2,
|
||||
UNAUTHORIZATION = -10,
|
||||
IGNORE = -999,
|
||||
}
|
||||
|
||||
//public enum LogLevel
|
||||
//{
|
||||
// [Description("详细")]
|
||||
// [ColorSelect("White")]
|
||||
// [FontColorSelect("Green")]
|
||||
// Detail = 2,
|
||||
// [Description("信息")]
|
||||
// [ColorSelect("White")]
|
||||
// [FontColorSelect("Dark")]
|
||||
// Information = 3,
|
||||
// [Description("辅助")]
|
||||
// [ColorSelect("White")]
|
||||
// [FontColorSelect("Blue")]
|
||||
// Assist = 4,
|
||||
// [Description("动作")]
|
||||
// [ColorSelect("DarkGreen")]
|
||||
// [FontColorSelect("Yellow")]
|
||||
// Action = 5,
|
||||
// [Description("错误")]
|
||||
// [ColorSelect("Orange")]
|
||||
// [FontColorSelect("White")]
|
||||
// Error = 6,
|
||||
// [Description("警报")]
|
||||
// [ColorSelect("Brown")]
|
||||
// [FontColorSelect("White")]
|
||||
// Warning = 7,
|
||||
// [Description("异常")]
|
||||
// [ColorSelect("Red")]
|
||||
// [FontColorSelect("White")]
|
||||
// Exception = 8,
|
||||
//}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ using System.Drawing.Imaging;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace XKRS.Common.Model
|
||||
namespace DH.Commons.Enums
|
||||
{
|
||||
public class HDevEngineTool : IDisposable
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XKRS.Common.Model
|
||||
namespace DH.Commons.Enums
|
||||
{
|
||||
public class OpenCVEngineTool : IDisposable
|
||||
{
|
||||
|
123
DH.Commons/Helper/UIHelper.cs
Normal file
123
DH.Commons/Helper/UIHelper.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DH.Commons.Enums
|
||||
{
|
||||
public static class UIHelper
|
||||
{
|
||||
public static void SetCombo(ComboBox cbo, object dataSource, string display, string value)
|
||||
{
|
||||
cbo.DataSource = dataSource;
|
||||
cbo.DisplayMember = display;
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
cbo.ValueMember = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetCombo(ToolStripComboBox cbo, object dataSource, string display, string value)
|
||||
{
|
||||
cbo.ComboBox.DataSource = dataSource;
|
||||
cbo.ComboBox.DisplayMember = display;
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
cbo.ComboBox.ValueMember = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetCombo(DataGridViewComboBoxColumn cbo, object dataSource, string display, string value)
|
||||
{
|
||||
cbo.DataSource = dataSource;
|
||||
cbo.DisplayMember = display;
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
cbo.ValueMember = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region DataGridView设置列头为复选框
|
||||
public class DataGridViewCheckboxHeaderEventArgs : EventArgs
|
||||
{
|
||||
private bool checkedState = false;
|
||||
|
||||
public bool CheckedState
|
||||
{
|
||||
get { return checkedState; }
|
||||
set { checkedState = value; }
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void DataGridViewCheckboxHeaderEventHander(object sender, DataGridViewCheckboxHeaderEventArgs e);
|
||||
public class DataGridViewCheckboxHeaderCell : DataGridViewColumnHeaderCell
|
||||
{
|
||||
Point checkBoxLocation;
|
||||
Size checkBoxSize;
|
||||
bool _checked = false;
|
||||
Point _cellLocation = new Point();
|
||||
System.Windows.Forms.VisualStyles.CheckBoxState _cbState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
|
||||
|
||||
public event DataGridViewCheckboxHeaderEventHander OnCheckBoxClicked;
|
||||
|
||||
//绘制列头checkbox
|
||||
protected override void Paint(System.Drawing.Graphics graphics,
|
||||
System.Drawing.Rectangle clipBounds,
|
||||
System.Drawing.Rectangle cellBounds,
|
||||
int rowIndex,
|
||||
DataGridViewElementStates dataGridViewElementState,
|
||||
object value,
|
||||
object formattedValue,
|
||||
string errorText,
|
||||
DataGridViewCellStyle cellStyle,
|
||||
DataGridViewAdvancedBorderStyle advancedBorderStyle,
|
||||
DataGridViewPaintParts paintParts)
|
||||
{
|
||||
base.Paint(graphics, clipBounds, cellBounds, rowIndex,
|
||||
dataGridViewElementState, value,
|
||||
formattedValue, errorText, cellStyle,
|
||||
advancedBorderStyle, paintParts);
|
||||
|
||||
Point p = new Point();
|
||||
Size s = CheckBoxRenderer.GetGlyphSize(graphics, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
|
||||
p.X = cellBounds.Location.X + (cellBounds.Width / 2) - (s.Width / 2) - 1; //列头checkbox的X坐标
|
||||
p.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (s.Height / 2); //列头checkbox的Y坐标
|
||||
_cellLocation = cellBounds.Location;
|
||||
checkBoxLocation = p;
|
||||
checkBoxSize = s;
|
||||
if (_checked)
|
||||
_cbState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal;
|
||||
else
|
||||
_cbState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
|
||||
|
||||
CheckBoxRenderer.DrawCheckBox(graphics, checkBoxLocation, _cbState);
|
||||
}
|
||||
|
||||
///
|
||||
/// 点击列头checkbox单击事件
|
||||
///
|
||||
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
Point p = new Point(e.X + _cellLocation.X, e.Y + _cellLocation.Y);
|
||||
if (p.X >= checkBoxLocation.X && p.X <= checkBoxLocation.X + checkBoxSize.Width
|
||||
&& p.Y >= checkBoxLocation.Y && p.Y <= checkBoxLocation.Y + checkBoxSize.Height)
|
||||
{
|
||||
_checked = !_checked;
|
||||
|
||||
//获取列头checkbox的选择状态
|
||||
DataGridViewCheckboxHeaderEventArgs ex = new DataGridViewCheckboxHeaderEventArgs();
|
||||
ex.CheckedState = _checked;
|
||||
|
||||
object sender = new object();//此处不代表选择的列头checkbox,只是作为参数传递。因为列头checkbox是绘制出来的,无法获得它的实例
|
||||
|
||||
if (OnCheckBoxClicked != null)
|
||||
{
|
||||
OnCheckBoxClicked(sender, ex);//触发单击事件
|
||||
DataGridView.InvalidateCell(this);
|
||||
}
|
||||
}
|
||||
base.OnMouseClick(e);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
Reference in New Issue
Block a user