using Mesnac.Action.ChemicalWeighing.RgvPlc; using Mesnac.Controls.ChemicalWeighing; using Mesnac.Controls.Default; using Mesnac.Controls.Feeding; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.Util { public class ControlsImprot { /// /// 控件导入 /// /// 控件类型 /// 控件实体类 /// 前端控件集合 public static void ControlImport(object obj, List McControls) where T : class { PropertyInfo[] sourcePropertyInfoList = obj.GetType().GetProperties(); foreach (PropertyInfo sourceProperty in sourcePropertyInfoList) { string name = sourceProperty.Name; var pro = McControls.FirstOrDefault(x => x.Name == name) as T; sourceProperty.SetValue(obj, pro); } } #region 图像控件交互 /// /// 看门狗 /// /// /// public static void SetStateButton(StateButton obj, bool set) { if (set == true) { obj.Status = StateButton.Statuses.sssRun; } else { obj.Status = StateButton.Statuses.sssStop; } } /// /// 停止状态 /// /// /// public static void SetSystemStateShow(SystemStateShow obj, bool set) { if (set == true) { obj.Status = SystemStateShow.Statuses.sssRun; } else { obj.Status = SystemStateShow.Statuses.sssStop; } } /// /// 指示灯 /// /// /// /// public static void SetSwitchLight(SwitchLight obj, bool set, bool alarm) { obj.BackColor = Color.Gray; if (set == true && alarm == false) { obj.Status = SwitchLight.Statuses.ylMove; } else if (alarm == true) { obj.Status = SwitchLight.Statuses.ylAlarm; } else { obj.Status = SwitchLight.Statuses.ylNormal; } } public static void SetSwitchLight(SwitchLight obj, bool set) { obj.BackColor = Color.Gray; if (set == true) { obj.Status = SwitchLight.Statuses.ylMove; } else { obj.Status = SwitchLight.Statuses.ylNormal; } } /// /// 阀门 /// /// /// /// public static void SetLjSwith(LjSwith obj, bool set, bool alarm) { if (set == true && alarm == false) { obj.Set = true; obj.Alarm = false; } else if (alarm == true) { obj.Set = false; obj.Alarm = true; } else { obj.Set = false; obj.Alarm = false; } } /// /// 螺旋给料器R /// /// /// public static void SetRSCREWBIG(RSCREWBIG obj, bool set) { if (set == true) { obj.Status = RSCREWBIG.Statuses.ylMove; } else { obj.Status = RSCREWBIG.Statuses.ylNormal; } } /// /// 螺旋给料器L /// /// /// public static void SetLSCREWBIG(LSCREWBIG obj, bool set) { if (set == true) { obj.Status = LSCREWBIG.Statuses.ylMove; } else { obj.Status = LSCREWBIG.Statuses.ylNormal; } } /// /// 脚座阀 /// /// /// public static void SetJzf(Jzf obj, bool set) { if (set == true) { obj.Status = Jzf.Statuses.TurnOn; } else { obj.Status = Jzf.Statuses.TurnOff; } } /// /// 文本标签 /// /// /// public static void SetMCLabel(MCLabel obj, object set) { obj.Text = Convert.ToString(set); } public static void SetMCLabel(MCLabel obj, object set, Color color) { obj.Text = Convert.ToString(set); obj.ForeColor = color; } /// /// 文本标签布尔转换 /// /// /// /// 1为自动手动、2为启动停止 public static void SetMCLabel(MCLabel obj, bool state, int flag) { if (flag == 1) { obj.Text = state ? "自动" : "手动"; } else if (flag == 2) { obj.Text = state ? "启动" : "停止"; } else if (flag == 3) { obj.Text = state ? "启用" : "停用"; } obj.ForeColor = state ? Color.Green : Color.Yellow; } /// /// 三通 /// /// /// /// /// /// public static void SetThreeWayValve(ThreeWayValve obj, bool alarmr, bool setr, bool alarml, bool setl, int kind) { obj.ControlKind = kind; obj.ZLTValue = setr; obj.ZLDValue = setl; obj.ALMTValue = alarmr; obj.ALMDValue = alarml; } /// /// 风扇电机 /// /// /// public static void SetFan(Fan obj, bool set, bool alarm) { if (alarm == true) { obj.Status = Fan.Statuses.zsAlarm; } else if (set == true) { obj.Status = Fan.Statuses.zsTurnOn; } else { obj.Status = Fan.Statuses.zsTurnOff; } } public static void SetFan(Fan obj, bool set) { if (set == true) { obj.Status = Fan.Statuses.zsTurnOn; } else { obj.Status = Fan.Statuses.zsTurnOff; } } /// /// 称量柜 /// /// /// public static void SetControlCabinet(ControlCabinet obj, bool set, bool alarm) { if (alarm == true) { obj.Status = ControlCabinet.Statuses.Alarm; } else if (set == true) { obj.Status = ControlCabinet.Statuses.TurnOn; } else { obj.Status = ControlCabinet.Statuses.TurnOff; } } public static void SetControlCabinet(ControlCabinet obj, bool set) { if (set == true) { obj.Status = ControlCabinet.Statuses.TurnOn; } else { obj.Status = ControlCabinet.Statuses.TurnOff; } } /// /// 胡工报警灯 /// /// /// public static void SetHslLanternAlarm(HslLanternAlarm lanternAlarm, RGVEntity rGV) { lanternAlarm.IsAlarm = false; if (rGV.Error) { lanternAlarm.NormalColor = Color.Red; } else { if (rGV.RequestFeed) { lanternAlarm.NormalColor = Color.Green; } else { lanternAlarm.NormalColor = Color.DarkGray; } } } /// /// 绿色胡工小灯 /// /// /// public static void SetHslLanternSimple(HslLanternSimple lanternSimple, bool su) { if (su == true) { lanternSimple.LanternBackground = Color.LimeGreen; } else { lanternSimple.LanternBackground = Color.DarkGray; } } /// /// 紫色胡工小灯 /// /// /// public static void SetHslLanternSimpleRequest(HslLanternSimple lanternSimple, bool su) { if (su == true) { lanternSimple.LanternBackground = Color.SlateBlue; } else { lanternSimple.LanternBackground = Color.DarkGray; } } /// /// 胡工料罐 /// /// /// 零到一的值 public static void SetHslBottle(HslBottle hslBottle, float value) { hslBottle.ForeColor = Color.White; hslBottle.Value = value; } #endregion } }