using Mesnac.Action.ChemicalWeighing.AutoControl.Entity; using Mesnac.Controls.Base; using Mesnac.Controls.ChemicalWeighing; using Mesnac.Controls.Default; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.AutoControl { public class ControlsHelper { /// /// 控件导入 /// public static void ControlImport(MCTextBoxEntity textE, ButtonEntity buttonE, MCComboBoxEntity comboE, MCLabelEntity labelE, MCRadioButtonEntity radioE, List McControls) { FillBase(textE, McControls); FillBase(buttonE, McControls); FillBase(comboE, McControls); FillBase(labelE, McControls); FillBase(radioE, McControls); } private static void FillBase(object E, List McControls) where T : class { PropertyInfo[] sourcePropertyInfoList = E.GetType().GetProperties(); foreach (PropertyInfo sourceProperty in sourcePropertyInfoList) { string name = sourceProperty.Name; var pro = McControls.FirstOrDefault(x => x.Name == name) as T; sourceProperty.SetValue(E, pro); } } /// /// 单选选择 /// /// 返回单选的产线号 如果未选择返回0 public static int SingleSelect(MCRadioButtonEntity RadioE) { int no = 0; if (Convert.ToBoolean(RadioE.Line1.MCValue)) { no = 1; } else if (Convert.ToBoolean(RadioE.Line2.MCValue)) { no = 2; } else if (Convert.ToBoolean(RadioE.Line3.MCValue)) { no = 3; } else if (Convert.ToBoolean(RadioE.Line4.MCValue)) { no = 4; } else if (Convert.ToBoolean(RadioE.Line5.MCValue)) { no = 5; } else if (Convert.ToBoolean(RadioE.Line6.MCValue)) { no = 6; } else if (Convert.ToBoolean(RadioE.Line7.MCValue)) { no = 7; } else if (Convert.ToBoolean(RadioE.Line8.MCValue)) { no = 8; } return no; } /// /// 单混机单选选择 /// /// public static int DrySelect(MCRadioButtonEntity RadioE) { if (Convert.ToBoolean(RadioE.Dry1.MCValue) == true) { return 1; } else if (Convert.ToBoolean(RadioE.Dry2.MCValue) == true) { return 2; } else if (Convert.ToBoolean(RadioE.Dry3.MCValue) == true) { return 3; } else if (Convert.ToBoolean(RadioE.Dry4.MCValue) == true) { return 4; } else { return 0; } } } }