using Mesnac.Action.ChemicalWeighing.AutoControl.DB; using Mesnac.Action.ChemicalWeighing.AutoControl.Entity; using Mesnac.Action.ChemicalWeighing.FreeDb; using Mesnac.Action.ChemicalWeighing.LjMixManager; using Mesnac.Action.ChemicalWeighing.LjPlanning; using Mesnac.Action.ChemicalWeighing.Util; using System; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Json; namespace Mesnac.Action.ChemicalWeighing.AutoControl { public class ControlsHelper : ControlsImprot { /// /// 单选选择 /// /// 返回单选的产线号 如果未选择返回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; } } public static void GWInit(int select, MCComboBoxEntity ComboE, MCTextBoxEntity TextE) { var selected = FreeSqlUnit.Instance.Select().Where(x => x.DeviceId == select && x.Type == 2).ToList(); if (selected.Count != 0) { ComboE.ChooseMaterial1.SelectedValue = selected[0].MaterrialId; ComboE.ChooseMaterial2.SelectedValue = selected[1].MaterrialId; } else { ComboE.ChooseMaterial1.SelectedIndex = 0; ComboE.ChooseMaterial2.SelectedIndex = 0; } var getGelatG1 = LjPlanningPlcHelp.GetGelatG1; var getWeterM1 = LjPlanningPlcHelp.GetWeterM1; var getGelatG2 = LjPlanningPlcHelp.GetGelatG2; var getWeterM2 = LjPlanningPlcHelp.GetWeterM2; var getGelatG3 = LjPlanningPlcHelp.GetGelatG3; var getWeterM3 = LjPlanningPlcHelp.GetWeterM3; var getGelatG4 = LjPlanningPlcHelp.GetGelatG4; var getWeterM4 = LjPlanningPlcHelp.GetWeterM4; var getGelatG5 = LjPlanningPlcHelp.GetGelatG5; var getWeterM5 = LjPlanningPlcHelp.GetWeterM5; var getGelatG6 = LjPlanningPlcHelp.GetGelatG6; var getWeterM6 = LjPlanningPlcHelp.GetWeterM6; var getGelatG7 = LjPlanningPlcHelp.GetGelatG7; var getWeterM7 = LjPlanningPlcHelp.GetWeterM7; var getGelatG8 = LjPlanningPlcHelp.GetGelatG8; var getWeterM8 = LjPlanningPlcHelp.GetWeterM8; switch (select) { case 1: GWDataShow(getGelatG1, getWeterM1, TextE); break; case 2: GWDataShow(getGelatG2, getWeterM2, TextE); break; case 3: GWDataShow(getGelatG3, getWeterM3, TextE); break; case 4: GWDataShow(getGelatG4, getWeterM4, TextE); break; case 5: GWDataShow(getGelatG5, getWeterM5, TextE); break; case 6: GWDataShow(getGelatG6, getWeterM6, TextE); break; case 7: GWDataShow(getGelatG7, getWeterM7, TextE); break; case 8: GWDataShow(getGelatG8, getWeterM8, TextE); break; default: return; } } public static void DInit(int select, MCComboBoxEntity ComboE, MCTextBoxEntity TextE) { var drtSelected = FreeSqlUnit.Instance.Select(). Where(x => x.DeviceId == select && x.Type == 1).ToList(); if (drtSelected.Count != 0) { ComboE.DryM1.SelectedValue = drtSelected[0].MaterrialId; ComboE.DryM2.SelectedValue = drtSelected[1].MaterrialId; ComboE.DryM3.SelectedValue = drtSelected[2].MaterrialId; ComboE.DryM4.SelectedValue = drtSelected[3].MaterrialId; ComboE.DryM5.SelectedValue = drtSelected[4].MaterrialId; ComboE.DryM6.SelectedValue = drtSelected[5].MaterrialId; ComboE.DryM7.SelectedValue = drtSelected[6].MaterrialId; ComboE.DryM8.SelectedValue = drtSelected[7].MaterrialId; ComboE.DryM9.SelectedValue = drtSelected[8].MaterrialId; ComboE.DryM10.SelectedValue = drtSelected[9].MaterrialId; ComboE.DryM11.SelectedValue = drtSelected[10].MaterrialId; ComboE.DryM12.SelectedValue = drtSelected[11].MaterrialId; } else { ComboE.DryM1.SelectedIndex = 0; ComboE.DryM2.SelectedIndex = 0; ComboE.DryM3.SelectedIndex = 0; ComboE.DryM4.SelectedIndex = 0; ComboE.DryM5.SelectedIndex = 0; ComboE.DryM6.SelectedIndex = 0; ComboE.DryM7.SelectedIndex = 0; ComboE.DryM8.SelectedIndex = 0; ComboE.DryM9.SelectedIndex = 0; ComboE.DryM10.SelectedIndex = 0; ComboE.DryM11.SelectedIndex = 0; ComboE.DryM12.SelectedIndex = 0; } var getDryerD1 = LjPlanningPlcHelp.GetDryerD1; var getDryerD2 = LjPlanningPlcHelp.GetDryerD2; var getDryerD3 = LjPlanningPlcHelp.GetDryerD3; var getDryerD4 = LjPlanningPlcHelp.GetDryerD4; switch (select) { case 1: DryDataShow(getDryerD1, TextE); break; case 2: DryDataShow(getDryerD2, TextE); break; case 3: DryDataShow(getDryerD3, TextE); break; case 4: DryDataShow(getDryerD4, TextE); break; default: return; } } public static void DryDataShow(DryerView Dry, MCTextBoxEntity TextE) { TextE.DryW1.MCValue = Dry.RecipePlcViews[0].Set; TextE.DryW2.MCValue = Dry.RecipePlcViews[1].Set; TextE.DryW3.MCValue = Dry.RecipePlcViews[2].Set; TextE.DryW4.MCValue = Dry.RecipePlcViews[3].Set; TextE.DryW5.MCValue = Dry.RecipePlcViews[4].Set; TextE.DryW6.MCValue = Dry.RecipePlcViews[5].Set; TextE.DryW7.MCValue = Dry.RecipePlcViews[6].Set; TextE.DryW8.MCValue = Dry.RecipePlcViews[7].Set; TextE.DryW9.MCValue = Dry.RecipePlcViews[8].Set; TextE.DryW10.MCValue = Dry.RecipePlcViews[9].Set; TextE.DryW11.MCValue = Dry.RecipePlcViews[10].Set; TextE.DryW12.MCValue = Dry.RecipePlcViews[11].Set; TextE.DryWaitTime.MCValue = Dry.RecipeSteps[1].MixTime; TextE.DryOutDelayTime.MCValue = Dry.RecipeSteps[2].MixTime; } public static void GWDataShow(DryerView Gel, List Wet, MCTextBoxEntity TextE) { TextE.MaterialWeight1.MCValue = Gel.RecipePlcViews[0].Set; TextE.MaterialWeight2.MCValue = Gel.RecipePlcViews[1].Set; TextE.GelSpeedSet.MCValue = Gel.RecipeSteps[0].MixSpeed; TextE.GelPosTimeA.MCValue = Gel.RecipeSteps[2].MixTemp; TextE.GelNagTimeB.MCValue = Gel.RecipeSteps[2].MixSpeed; TextE.GelPosTimeC.MCValue = Gel.RecipeSteps[2].MixTime; TextE.GelWaterTime.MCValue = Gel.RecipeSteps[4].MixTime; TextE.GelWaitTime.MCValue = Gel.RecipeSteps[6].MixTime; TextE.GelCloseHeatTime.MCValue = Gel.RecipeSteps[7].MixTime; TextE.GelOutDelayTime.MCValue = Gel.RecipeSteps[7].MixTemp; TextE.WetDryWeight.MCValue = Wet[1].SetValue; TextE.WetMixTime.MCValue = Wet[2].MixTime; TextE.WetOutDelayTime.MCValue = Wet[4].MixTime; } /// /// 将C#数据实体转化为JSON数据 /// /// 要转化的数据实体 /// JSON格式字符串 public static string JsonSerialize(T obj) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T)); MemoryStream stream = new MemoryStream(); serializer.WriteObject(stream, obj); stream.Position = 0; StreamReader sr = new StreamReader(stream); string resultStr = sr.ReadToEnd(); sr.Close(); stream.Close(); return resultStr; } /// /// 将JSON数据转化为C#数据实体 /// /// 符合JSON格式的字符串 /// T类型的对象 public static T JsonDeserialize(string json) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T)); MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json.ToCharArray())); T obj = (T)serializer.ReadObject(ms); ms.Close(); return obj; } } }