using DataBlockHelper.DBHelpers; using DataBlockHelper.Entity.DB2104Entity; using DataBlockHelper.Entity.DB2106Entity; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.AutoControl.DB; using Mesnac.Action.ChemicalWeighing.AutoControl.Entity; using Mesnac.Action.ChemicalWeighing.LjMixManager; using Mesnac.Controls.Base; using Mesnac.Controls.Default; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Button = System.Windows.Forms.Button; using Mesnac.Action.ChemicalWeighing.LjPlanning; using System.Diagnostics.SymbolStore; using Mesnac.Basic; using Mesnac.Action.ChemicalWeighing.FreeDb; using Microsoft.Office.Interop.Excel; using System.Reflection; using Mesnac.Action.ChemicalWeighing.MainDetailControl.Entity; using Mesnac.Controls.ChemicalWeighing; using IAction = Mesnac.Action.Base.IAction; using Mesnac.Core.Service; namespace Mesnac.Action.ChemicalWeighing.AutoControl { internal class AutoControl : ChemicalWeighingAction, IAction { private List McControls; MCTextBoxEntity TextE = new MCTextBoxEntity(); ButtonEntity ButtonE = new ButtonEntity(); MCLabelEntity LabelE = new MCLabelEntity(); MCComboBoxEntity ComboE = new MCComboBoxEntity(); MCRadioButtonEntity RadioE = new MCRadioButtonEntity(); public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用 McControls = GetAllControls(); ControlsHelper.ControlImport(TextE, ButtonE, ComboE, LabelE, RadioE, McControls); try { BottomSelect(runtime); } catch(Exception e) { MessageBox.Show("请检查输入内容格式是否正确!"); } } private void BottomSelect(RuntimeParameter runtime) { #region 自动参数下传 #region 湿混机糊化机参数下传 if (ButtonE.Download == runtime.Sender) { if (MessageBox.Show("确认下传数据?", "下传确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int b1 = Convert.ToInt32(ComboE.ChooseMaterial1.MCValue.ToString()); int b2 = Convert.ToInt32(ComboE.ChooseMaterial2.MCValue.ToString()); short bin1 = (short)StockMaterrialDbHelp.GetCodeById(b1); short bin2 = (short)StockMaterrialDbHelp.GetCodeById(b2); float MatTol1 = Convert.ToSingle(TextE.MaterialTolerance1.MCValue.ToString()); float MatTol2 = Convert.ToSingle(TextE.MaterialTolerance2.MCValue.ToString()); float MatWei1 = Convert.ToSingle(TextE.MaterialWeight1.MCValue.ToString()); float MatWei2 = Convert.ToSingle(TextE.MaterialWeight2.MCValue.ToString()); float GelSpeed = Convert.ToSingle(TextE.GelSpeedSet.MCValue.ToString()); float GelPosA = Convert.ToSingle(TextE.GelPosTimeA.MCValue.ToString()); float GelNagB = Convert.ToSingle(TextE.GelNagTimeB.MCValue.ToString()); short GelPosC = Convert.ToInt16(TextE.GelPosTimeC.MCValue.ToString()); short GelWater = Convert.ToInt16(TextE.GelWaterTime.MCValue.ToString()); short GelWait = Convert.ToInt16(TextE.GelWaitTime.MCValue.ToString()); short GelCloseHeat = Convert.ToInt16(TextE.GelCloseHeatTime.MCValue.ToString()); float GelDelayTime = Convert.ToSingle(TextE.GelOutDelayTime.MCValue.ToString()); if (b2 == -1) { if (MatTol1 < 0.1) { MessageBox.Show("公差不能小于0.1!"); return; } } else { if (MatTol1 < 0.1 || MatTol2 < 0.1) { MessageBox.Show("公差不能小于0.1!"); return; } } List recipes = new List(); RecipePlcView recipe1 = new RecipePlcView() { Bin = bin1, Set = MatWei1, Tolerance = MatTol1, }; RecipePlcView recipe2 = new RecipePlcView() { Bin = bin2, Set = MatWei2, Tolerance = MatTol2, }; recipes.Add(recipe1); recipes.Add(recipe2); List steps = new List(); Step step1 = new Step() { MixCode = 1, MixSpeed = GelSpeed }; Step step2 = new Step() { MixCode = 2, }; Step step3 = new Step() { MixCode = 3, MixTime = GelPosC, MixTemp = GelPosA, MixSpeed = GelNagB }; Step step4 = new Step() { MixCode = 4, }; Step step5 = new Step() { MixCode = 5, MixTime = GelWater }; Step step6 = new Step() { MixCode = 6, }; Step step7 = new Step() { MixCode = 5, MixTime = GelWait }; Step step8 = new Step() { MixCode = 7, MixTime = GelCloseHeat, MixTemp = GelDelayTime }; steps.Add(step1); steps.Add(step2); steps.Add(step3); steps.Add(step4); steps.Add(step5); steps.Add(step6); steps.Add(step7); steps.Add(step8); float WetDryWei = Convert.ToSingle(TextE.WetDryWeight.MCValue.ToString()); short WetMix = Convert.ToInt16(TextE.WetMixTime.MCValue.ToString()); short WetOutDelay = Convert.ToInt16(TextE.WetOutDelayTime.MCValue.ToString()); List mixSteps = new List(); MixStep mixStep1 = new MixStep() { MixCode = 1, }; MixStep mixStep2 = new MixStep() { MixCode = 2, SetValue = WetDryWei }; MixStep mixStep3 = new MixStep() { MixCode = 3, MixTime = WetMix }; MixStep mixStep4 = new MixStep() { MixCode = 4, }; MixStep mixStep5 = new MixStep() { MixCode = 5, MixTime = WetOutDelay }; mixSteps.Add(mixStep1); mixSteps.Add(mixStep2); mixSteps.Add(mixStep3); mixSteps.Add(mixStep4); mixSteps.Add(mixStep5); List materials = new List(); DeviceMaterrial deviceMaterial1 = new DeviceMaterrial() { DeviceId = SingleSelect(), MaterrialId = b1, Type = 2, Code = StockMaterrialDbHelp.GetCodeById(b1) }; DeviceMaterrial deviceMaterial2 = new DeviceMaterrial() { DeviceId = SingleSelect(), MaterrialId = b2, Type = 2, Code = StockMaterrialDbHelp.GetCodeById(b2) }; materials.Add(deviceMaterial1); materials.Add(deviceMaterial2); switch (SingleSelect()) { case 1: LjPlanningPlcHelp.DownG1Recipe(recipes, steps); LjPlanningPlcHelp.DownM1Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 2: LjPlanningPlcHelp.DownG2Recipe(recipes, steps); LjPlanningPlcHelp.DownM2Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 3: LjPlanningPlcHelp.DownG3Recipe(recipes, steps); LjPlanningPlcHelp.DownM3Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 4: LjPlanningPlcHelp.DownG4Recipe(recipes, steps); LjPlanningPlcHelp.DownM4Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 5: LjPlanningPlcHelp.DownG5Recipe(recipes, steps); LjPlanningPlcHelp.DownM5Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 6: LjPlanningPlcHelp.DownG6Recipe(recipes, steps); LjPlanningPlcHelp.DownM6Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 7: LjPlanningPlcHelp.DownG7Recipe(recipes, steps); LjPlanningPlcHelp.DownM7Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 8: LjPlanningPlcHelp.DownG8Recipe(recipes, steps); LjPlanningPlcHelp.DownM8Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; default: MessageBox.Show("请选择一条产线!"); return; } Auto_Log log = new Auto_Log() { ActionKind = "糊化湿混数据下传", LogTime = DateTime.Now, UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, LineNo = SingleSelect(), MaterialBin1 = bin1, MaterialBin2 = bin2, MaterialWeight1 = MatWei1, MaterialWeight2 = MatWei2, MaterialTolerance1 = MatTol1, MaterialTolerance2 = MatTol2, GelSpeedSet = GelSpeed, GelPosTimeA = GelPosA, GelNagTimeB = GelNagB, GelPosTimeC = GelPosC, GelWaterTime = GelWater, GelWaitTime = GelWait, GelCloseHeatTime = GelCloseHeat, GelOutDelayTime = GelDelayTime, WetDryWeight = WetDryWei, WetMixTime = WetMix, WetOutDelayTime = WetOutDelay }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("数据下传成功!"); } #endregion #region 水称参数下传 if (ButtonE.WaterDownload == runtime.Sender) { if (MessageBox.Show("确认下发水称数据?", "下发确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } WaterEntity HotA = new WaterEntity(); WaterEntity ColdA = new WaterEntity(); WaterEntity HotB = new WaterEntity(); WaterEntity ColdB = new WaterEntity(); float hotASet, hotBSet, coldASet, coldBSet, hotATol, hotBTol, coldATol, coldBTol; if (float.TryParse(Convert.ToString(TextE.HotValueA.MCValue), out hotASet) && float.TryParse(Convert.ToString(TextE.HotToleranceA.MCValue), out hotATol) && float.TryParse(Convert.ToString(TextE.HotValueB.MCValue), out hotBSet) && float.TryParse(Convert.ToString(TextE.HotToleranceB.MCValue), out hotBTol) && float.TryParse(Convert.ToString(TextE.ColdValueA.MCValue), out coldASet) && float.TryParse(Convert.ToString(TextE.ColdToleranceA.MCValue), out coldATol) && float.TryParse(Convert.ToString(TextE.ColdValueB.MCValue), out coldBSet) && float.TryParse(Convert.ToString(TextE.ColdToleranceB.MCValue), out coldBTol)) { HotA.Set = hotASet; HotB.Set = hotBSet; ColdA.Set = coldASet; ColdB.Set = coldBSet; HotA.Tolerance = hotATol; HotB.Tolerance = hotBTol; ColdA.Tolerance = coldATol; ColdB.Tolerance = coldBTol; Db2104WriteHelper.WriteAHostWater(HotA); Db2104WriteHelper.WriteBHostWater(HotB); Db2104WriteHelper.WriteAColWater(ColdA); Db2104WriteHelper.WriteBColWater(ColdB); MesnacServiceManager.Instance.LoggingService.Info("水称数据下发成功!"); MessageBox.Show("水称数据下发成功"); } else { MesnacServiceManager.Instance.LoggingService.Info("输入数值的格式有误"); MessageBox.Show("输入数值的格式有误!"); return; } } #endregion #region 干混机参数下传 if(ButtonE.DryDownload == runtime.Sender) { if (MessageBox.Show("确认下传干混机数据?", "下传确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int b1 = Convert.ToInt32(ComboE.DryM1.MCValue.ToString()); int b2 = Convert.ToInt32(ComboE.DryM2.MCValue.ToString()); int b3 = Convert.ToInt32(ComboE.DryM3.MCValue.ToString()); int b4 = Convert.ToInt32(ComboE.DryM4.MCValue.ToString()); int b5 = Convert.ToInt32(ComboE.DryM5.MCValue.ToString()); int b6 = Convert.ToInt32(ComboE.DryM6.MCValue.ToString()); int b7 = Convert.ToInt32(ComboE.DryM7.MCValue.ToString()); int b8 = Convert.ToInt32(ComboE.DryM8.MCValue.ToString()); int b9 = Convert.ToInt32(ComboE.DryM9.MCValue.ToString()); int b10 = Convert.ToInt32(ComboE.DryM10.MCValue.ToString()); int b11 = Convert.ToInt32(ComboE.DryM11.MCValue.ToString()); int b12 = Convert.ToInt32(ComboE.DryM12.MCValue.ToString()); short bin1 = (short)StockMaterrialDbHelp.GetCodeById(b1); short bin2 = (short)StockMaterrialDbHelp.GetCodeById(b2); short bin3 = (short)StockMaterrialDbHelp.GetCodeById(b3); short bin4 = (short)StockMaterrialDbHelp.GetCodeById(b4); short bin5 = (short)StockMaterrialDbHelp.GetCodeById(b5); short bin6 = (short)StockMaterrialDbHelp.GetCodeById(b6); short bin7 = (short)StockMaterrialDbHelp.GetCodeById(b7); short bin8 = (short)StockMaterrialDbHelp.GetCodeById(b8); short bin9 = (short)StockMaterrialDbHelp.GetCodeById(b9); short bin10 = (short)StockMaterrialDbHelp.GetCodeById(b10); short bin11 = (short)StockMaterrialDbHelp.GetCodeById(b11); short bin12 = (short)StockMaterrialDbHelp.GetCodeById(b12); int w1 = Convert.ToInt32(TextE.DryW1.MCValue.ToString()); int w2 = Convert.ToInt32(TextE.DryW2.MCValue.ToString()); int w3 = Convert.ToInt32(TextE.DryW3.MCValue.ToString()); int w4 = Convert.ToInt32(TextE.DryW4.MCValue.ToString()); int w5 = Convert.ToInt32(TextE.DryW5.MCValue.ToString()); int w6 = Convert.ToInt32(TextE.DryW6.MCValue.ToString()); int w7 = Convert.ToInt32(TextE.DryW7.MCValue.ToString()); int w8 = Convert.ToInt32(TextE.DryW8.MCValue.ToString()); int w9 = Convert.ToInt32(TextE.DryW9.MCValue.ToString()); int w10 = Convert.ToInt32(TextE.DryW10.MCValue.ToString()); int w11 = Convert.ToInt32(TextE.DryW11.MCValue.ToString()); int w12 = Convert.ToInt32(TextE.DryW12.MCValue.ToString()); int t1 = Convert.ToInt32(TextE.DryT1.MCValue.ToString()); int t2 = Convert.ToInt32(TextE.DryT2.MCValue.ToString()); int t3 = Convert.ToInt32(TextE.DryT3.MCValue.ToString()); int t4 = Convert.ToInt32(TextE.DryT4.MCValue.ToString()); int t5 = Convert.ToInt32(TextE.DryT5.MCValue.ToString()); int t6 = Convert.ToInt32(TextE.DryT6.MCValue.ToString()); int t7 = Convert.ToInt32(TextE.DryT7.MCValue.ToString()); int t8 = Convert.ToInt32(TextE.DryT8.MCValue.ToString()); int t9 = Convert.ToInt32(TextE.DryT9.MCValue.ToString()); int t10 = Convert.ToInt32(TextE.DryT10.MCValue.ToString()); int t11 = Convert.ToInt32(TextE.DryT11.MCValue.ToString()); int t12 = Convert.ToInt32(TextE.DryT12.MCValue.ToString()); List recipes = new List(); RecipePlcView recipe1 = new RecipePlcView() { Bin = bin1, Set = w1, Tolerance = t1, }; RecipePlcView recipe2 = new RecipePlcView() { Bin = bin2, Set = w2, Tolerance = t2, }; RecipePlcView recipe3 = new RecipePlcView() { Bin = bin3, Set = w3, Tolerance = t3, }; RecipePlcView recipe4 = new RecipePlcView() { Bin = bin4, Set = w4, Tolerance = t4, }; RecipePlcView recipe5 = new RecipePlcView() { Bin = bin5, Set = w5, Tolerance = t5, }; RecipePlcView recipe6 = new RecipePlcView() { Bin = bin6, Set = w6, Tolerance = t6, }; RecipePlcView recipe7 = new RecipePlcView() { Bin = bin7, Set = w7, Tolerance = t7, }; RecipePlcView recipe8 = new RecipePlcView() { Bin = bin8, Set = w8, Tolerance = t8, }; RecipePlcView recipe9 = new RecipePlcView() { Bin = bin9, Set = w9, Tolerance = t9, }; RecipePlcView recipe10 = new RecipePlcView() { Bin = bin10, Set = w10, Tolerance = t10, }; RecipePlcView recipe11 = new RecipePlcView() { Bin = bin11, Set = w11, Tolerance = t11, }; RecipePlcView recipe12 = new RecipePlcView() { Bin = bin12, Set = w12, Tolerance = t12, }; recipes.Add(recipe1); recipes.Add(recipe2); recipes.Add(recipe3); recipes.Add(recipe4); recipes.Add(recipe5); recipes.Add(recipe6); recipes.Add(recipe7); recipes.Add(recipe8); recipes.Add(recipe9); recipes.Add(recipe10); recipes.Add(recipe11); recipes.Add(recipe12); List steps = new List(); List materials = new List(); DeviceMaterrial deviceMaterial1 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b1, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b1) }; DeviceMaterrial deviceMaterial2 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b2, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b2) }; DeviceMaterrial deviceMaterial3 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b3, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b3) }; DeviceMaterrial deviceMaterial4 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b4, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b4) }; DeviceMaterrial deviceMaterial5 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b5, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b5) }; DeviceMaterrial deviceMaterial6 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b6, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b6) }; DeviceMaterrial deviceMaterial7 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b7, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b7) }; DeviceMaterrial deviceMaterial8 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b8, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b8) }; DeviceMaterrial deviceMaterial9 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b9, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b9) }; DeviceMaterrial deviceMaterial10 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b10, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b10) }; DeviceMaterrial deviceMaterial11 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b11, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b11) }; DeviceMaterrial deviceMaterial12 = new DeviceMaterrial() { DeviceId = DrySelect(), MaterrialId = b12, Type = 1, Code = StockMaterrialDbHelp.GetCodeById(b12) }; materials.Add(deviceMaterial1); materials.Add(deviceMaterial2); materials.Add(deviceMaterial3); materials.Add(deviceMaterial4); materials.Add(deviceMaterial5); materials.Add(deviceMaterial6); materials.Add(deviceMaterial7); materials.Add(deviceMaterial8); materials.Add(deviceMaterial9); materials.Add(deviceMaterial10); materials.Add(deviceMaterial11); materials.Add(deviceMaterial12); switch (DrySelect()) { case 1: LjPlanningPlcHelp.DownD1Recipe(recipes, steps); DeviceMaterrialService.Save(materials); break; case 2: LjPlanningPlcHelp.DownD2Recipe(recipes, steps); DeviceMaterrialService.Save(materials); break; case 3: LjPlanningPlcHelp.DownD3Recipe(recipes, steps); DeviceMaterrialService.Save(materials); break; case 4: LjPlanningPlcHelp.DownD4Recipe(recipes, steps); DeviceMaterrialService.Save(materials); break; } MessageBox.Show("数据下传成功!"); } #endregion #endregion #region 手动控制 if (ButtonE.GelManualPowder == runtime.Sender) { if (MessageBox.Show("确认手动下粉料?", "下粉确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } bool isReady; switch (SingleSelect()) { case 1: isReady = DB2105WriteHelper.WriteG1Pd(); break; case 2: isReady = DB2105WriteHelper.WriteG2Pd(); break; case 3: isReady = DB2105WriteHelper.WriteG3Pd(); break; case 4: isReady = DB2105WriteHelper.WriteG4Pd(); break; case 5: isReady = DB2105WriteHelper.WriteG5Pd(); break; case 6: isReady = DB2105WriteHelper.WriteG6Pd(); break; case 7: isReady = DB2105WriteHelper.WriteG7Pd(); break; case 8: isReady = DB2105WriteHelper.WriteG8Pd(); break; default: isReady = true; MessageBox.Show("当前未选择产线!"); return; } if (!isReady) { MessageBox.Show("信号未准备好!"); } else { Auto_Log log = new Auto_Log() { ActionKind = "手动下粉料", LogTime = DateTime.Now, LineNo = SingleSelect(), UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("信号下达成功!"); } } if (ButtonE.GelManualColdWater == runtime.Sender) { if (MessageBox.Show("确认下冷水?", "下水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } bool isReady; switch (SingleSelect()) { case 1: isReady = DB2105WriteHelper.WriteG1Cw(); break; case 2: isReady = DB2105WriteHelper.WriteG2Cw(); break; case 3: isReady = DB2105WriteHelper.WriteG3Cw(); break; case 4: isReady = DB2105WriteHelper.WriteG4Cw(); break; case 5: isReady = DB2105WriteHelper.WriteG5Cw(); break; case 6: isReady = DB2105WriteHelper.WriteG6Cw(); break; case 7: isReady = DB2105WriteHelper.WriteG7Cw(); break; case 8: isReady = DB2105WriteHelper.WriteG8Cw(); break; default: isReady = true; MessageBox.Show("当前未选择产线!"); return; } if (!isReady) { MessageBox.Show("信号未准备好!"); } else { Auto_Log log = new Auto_Log() { ActionKind = "手动下冷水", LogTime = DateTime.Now, LineNo = SingleSelect(), UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("信号下达成功!"); } } if (ButtonE.GelManualHotWater == runtime.Sender) { if (MessageBox.Show("确认下热水?", "下水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } bool isReady; switch (SingleSelect()) { case 1: isReady = DB2105WriteHelper.WriteG1Hw(); break; case 2: isReady = DB2105WriteHelper.WriteG2Hw(); break; case 3: isReady = DB2105WriteHelper.WriteG3Hw(); break; case 4: isReady = DB2105WriteHelper.WriteG4Hw(); break; case 5: isReady = DB2105WriteHelper.WriteG5Hw(); break; case 6: isReady = DB2105WriteHelper.WriteG6Hw(); break; case 7: isReady = DB2105WriteHelper.WriteG7Hw(); break; case 8: isReady = DB2105WriteHelper.WriteG8Hw(); break; default: isReady = true; MessageBox.Show("当前未选择产线!"); return; } if (!isReady) { MessageBox.Show("信号未准备好!"); } else { Auto_Log log = new Auto_Log() { ActionKind = "手动下热水", LogTime = DateTime.Now, LineNo = SingleSelect(), UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("信号下达成功!"); } } if (ButtonE.WetManualGel == runtime.Sender) { if (MessageBox.Show("确认下糊化料?", "下糊化料确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } bool isReady; switch (SingleSelect()) { case 1: isReady = DB2105WriteHelper.WriteM1(); break; case 2: isReady = DB2105WriteHelper.WriteM2(); break; case 3: isReady = DB2105WriteHelper.WriteM3(); break; case 4: isReady = DB2105WriteHelper.WriteM4(); break; case 5: isReady = DB2105WriteHelper.WriteM5(); break; case 6: isReady = DB2105WriteHelper.WriteM6(); break; case 7: isReady = DB2105WriteHelper.WriteM7(); break; case 8: isReady = DB2105WriteHelper.WriteM8(); break; default: isReady = false; MessageBox.Show("当前未选择产线!"); return; } if (!isReady) { MessageBox.Show("信号未准备好!"); } else { Auto_Log log = new Auto_Log() { ActionKind = "手动下糊化料", LogTime = DateTime.Now, LineNo = SingleSelect(), UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("信号下达成功!"); } } if (ButtonE.WetManualControl == runtime.Sender) { if (MessageBox.Show("确认下传数据?", "下传确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } float t = Convert.ToSingle(TextE.ManualTolerance.MCValue.ToString()); float w = Convert.ToSingle(TextE.ManualWeight.MCValue.ToString()); if (t < 0.1) { MessageBox.Show("公差不能小于0.1!"); return; } SetValue value = new SetValue() { Value = w, Toterance = t }; switch (SingleSelect()) { case 1: DB2105WriteHelper.WriteManScrewH1(); DB2105WriteHelper.WriteSetValueH1(value); break; case 2: DB2105WriteHelper.WriteManScrewH2(); DB2105WriteHelper.WriteSetValueH1(value); break; case 3: DB2105WriteHelper.WriteManScrewH3(); DB2105WriteHelper.WriteSetValueH2(value); break; case 4: DB2105WriteHelper.WriteManScrewH4(); DB2105WriteHelper.WriteSetValueH2(value); break; case 5: DB2105WriteHelper.WriteManScrewH5(); DB2105WriteHelper.WriteSetValueH3(value); break; case 6: DB2105WriteHelper.WriteManScrewH6(); DB2105WriteHelper.WriteSetValueH3(value); break; case 7: DB2105WriteHelper.WriteManScrewH7(); DB2105WriteHelper.WriteSetValueH4(value); break; case 8: DB2105WriteHelper.WriteManScrewH8(); DB2105WriteHelper.WriteSetValueH4(value); break; default: MessageBox.Show("当前未选择产线!"); return; } Auto_Log log = new Auto_Log() { ActionKind = "手动下黑粉", LogTime = DateTime.Now, UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, ManualTolerance = t, LineNo = SingleSelect(), ManualWeight = w, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("数据下传成功!"); } #endregion #region 自动启停 if (ButtonE.LineStart == runtime.Sender) { if (MessageBox.Show("确认启动生产?", "启动确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } switch (SingleSelect()) { case 1: DB2105WriteHelper.WriteStartJob1(); break; case 2: DB2105WriteHelper.WriteStartJob2(); break; case 3: DB2105WriteHelper.WriteStartJob3(); break; case 4: DB2105WriteHelper.WriteStartJob4(); break; case 5: DB2105WriteHelper.WriteStartJob5(); break; case 6: DB2105WriteHelper.WriteStartJob6(); break; case 7: DB2105WriteHelper.WriteStartJob7(); break; case 8: DB2105WriteHelper.WriteStartJob8(); break; default: MessageBox.Show("请选择一条产线!"); return; } Auto_Log log = new Auto_Log() { ActionKind = "产线启动", LogTime = DateTime.Now, LineNo = SingleSelect(), UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("产线已启动!"); } if (ButtonE.LineStop == runtime.Sender) { switch (SingleSelect()) { case 1: DB2105WriteHelper.WriteStopJob1(); break; case 2: DB2105WriteHelper.WriteStopJob2(); break; case 3: DB2105WriteHelper.WriteStopJob3(); break; case 4: DB2105WriteHelper.WriteStopJob4(); break; case 5: DB2105WriteHelper.WriteStopJob5(); break; case 6: DB2105WriteHelper.WriteStopJob6(); break; case 7: DB2105WriteHelper.WriteStopJob7(); break; case 8: DB2105WriteHelper.WriteStopJob8(); break; default: MessageBox.Show("请选择一条产线!"); return; } Auto_Log log = new Auto_Log() { ActionKind = "产线停止", LogTime = DateTime.Now, LineNo = SingleSelect(), UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("已经停止生产"); } #endregion #region 维修模式 if(ButtonE.RepairMode == runtime.Sender) { if (LabelE.RepairState.MCValue.ToString() == "关") { if (MessageBox.Show("是否开启维修模式?", "维修模式确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } Db3000Helper.WriteModel(SingleSelect(), true); LabelE.RepairState.MCValue = "开"; Auto_Log log = new Auto_Log() { ActionKind = "维修模式开启", LogTime = DateTime.Now, LineNo = SingleSelect(), UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("维修模式已开启"); } else { if (LabelE.RepairState.MCValue.ToString() == "开") { if (MessageBox.Show("是否关闭维修模式?", "维修模式确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } Db3000Helper.WriteModel(SingleSelect(), false); LabelE.RepairState.MCValue = "关"; Auto_Log log = new Auto_Log() { ActionKind = "维修模式关闭", LogTime = DateTime.Now, LineNo = SingleSelect(), UserID = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName, }; FreeSqlUnit.Instance.Insert(log).ExecuteIdentity(); MessageBox.Show("维修模式已关闭"); } } } #endregion } #region 帮助类 /// /// 单选选择 /// /// 返回单选的产线号 如果未选择返回0 private int SingleSelect() { if (Convert.ToBoolean(RadioE.Line1.MCValue) == true) { return 1; } else if (Convert.ToBoolean(RadioE.Line2.MCValue) == true) { return 2; } else if (Convert.ToBoolean(RadioE.Line3.MCValue) == true) { return 3; } else if (Convert.ToBoolean(RadioE.Line4.MCValue) == true) { return 4; } else if (Convert.ToBoolean(RadioE.Line5.MCValue) == true) { return 5; } else if (Convert.ToBoolean(RadioE.Line6.MCValue) == true) { return 6; } else if (Convert.ToBoolean(RadioE.Line7.MCValue) == true) { return 7; } else if (Convert.ToBoolean(RadioE.Line8.MCValue) == true) { return 8; } else { return 0; } } /// /// 单混机单选选择 /// /// private int DrySelect() { 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; } } #endregion } }