You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/AutoControl/PlcAutoWriteHelper.cs

1440 lines
50 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using DataBlockHelper.DBHelpers;
using DataBlockHelper.Entity.DB2104Entity;
using Mesnac.Action.ChemicalWeighing.AutoControl.DB;
using Mesnac.Action.ChemicalWeighing.AutoControl.Entity;
using Mesnac.Action.ChemicalWeighing.FreeDb;
using Mesnac.Action.ChemicalWeighing.FreeDb.DBEntity;
using Mesnac.Action.ChemicalWeighing.LjMixManager;
using Mesnac.Action.ChemicalWeighing.LjPlanning;
using Mesnac.Action.ChemicalWeighing.MinAn;
using Mesnac.Controls.Default;
using Mesnac.Core.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using static Mesnac.Action.ChemicalWeighing.AutoControl.AutoLogHelper;
namespace Mesnac.Action.ChemicalWeighing.AutoControl
{
public static class PlcAutoWriteHelper
{
/// <summary>
/// 干混公差控制
/// </summary>
private static int TFlag = 0;
#region 湿混糊化下传
public static void GelWetDownload(MCTextBoxEntity TextE, MCComboBoxEntity ComboE, MCRadioButtonEntity RadioE)
{
WetDetail wet=new WetDetail();
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());
wet.MixSpeed = GelSpeed;
float GelPosA = Convert.ToSingle(TextE.GelPosTimeA.MCValue.ToString());
wet.GelPosA = GelPosA;
float GelNagB = Convert.ToSingle(TextE.GelNagTimeB.MCValue.ToString());
wet.GelPosB = GelNagB;
short GelPosC = Convert.ToInt16(TextE.GelPosTimeC.MCValue.ToString());
wet.GelPosC = GelPosC;
short GelWater = Convert.ToInt16(TextE.GelWaterTime.MCValue.ToString());
wet.GelWater = GelWater;
short GelWait = Convert.ToInt16(TextE.GelWaitTime.MCValue.ToString());
wet.GelWait = GelWait;
short GelCloseHeat = Convert.ToInt16(TextE.GelCloseHeatTime.MCValue.ToString());
wet.GelCloseHeat = GelCloseHeat;
float GelDelayTime = Convert.ToSingle(TextE.GelOutDelayTime.MCValue.ToString());
wet.GelDelayTime = GelDelayTime;
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;
}
}
if(b1 == b2)
{
MessageBox.Show("两种物料不可相同!");
return;
}
if(GelSpeed > 50)
{
MessageBox.Show("速度不能大于五十!");
return;
}
List<RecipePlcView> recipes = new List<RecipePlcView>();
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<Step> steps = new List<Step>();
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
};
Step step9 = new Step();
steps.Add(step1);
steps.Add(step2);
steps.Add(step3);
steps.Add(step4);
steps.Add(step5);
steps.Add(step6);
steps.Add(step7);
steps.Add(step8);
steps.Add(step9);
steps.Add(step9);
float WetDryWei = Convert.ToSingle(TextE.WetDryWeight.MCValue.ToString());
wet.WetDryWei = WetDryWei;
short WetMix = Convert.ToInt16(TextE.WetMixTime.MCValue.ToString());
wet.WetMix = WetMix;
short WetOutDelay = Convert.ToInt16(TextE.WetOutDelayTime.MCValue.ToString());
wet.WetOutDelay = WetOutDelay;
List<MixStep> mixSteps = new List<MixStep>();
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
};
MixStep mixStep6 = new MixStep();
mixSteps.Add(mixStep1);
mixSteps.Add(mixStep2);
mixSteps.Add(mixStep3);
mixSteps.Add(mixStep4);
mixSteps.Add(mixStep5);
mixSteps.Add(mixStep6);
mixSteps.Add(mixStep6);
mixSteps.Add(mixStep6);
mixSteps.Add(mixStep6);
mixSteps.Add(mixStep6);
List<DeviceMaterrial> materials = new List<DeviceMaterrial>();
DeviceMaterrial deviceMaterial1 = new DeviceMaterrial()
{
DeviceId = ControlsHelper.SingleSelect(RadioE),
MaterrialId = b1,
Type = 2,
Code = StockMaterrialDbHelp.GetCodeById(b1),
Weight= MatWei1,
Allowance= MatTol1,
};
DeviceMaterrial deviceMaterial2 = new DeviceMaterrial()
{
DeviceId = ControlsHelper.SingleSelect(RadioE),
MaterrialId = b2,
Type = 2,
Code = StockMaterrialDbHelp.GetCodeById(b2),
Weight = MatWei2,
Allowance = MatTol2,
};
materials.Add(deviceMaterial1);
materials.Add(deviceMaterial2);
switch (ControlsHelper.SingleSelect(RadioE))
{
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;
}
wet.Id = ControlsHelper.SingleSelect(RadioE);
FreeDb.FreeSqlUnit.Instance.Update<WetDetail>().SetSource(wet).ExecuteAffrows();
GWlog(recipes, steps, mixSteps, RadioE);
//if (!GWComparePLC(recipes, steps, mixSteps, RadioE))
//{
// MessageBox.Show("湿混糊化产线下传数据不完整,请重新下传数据!");
//}
MessageBox.Show("数据下传成功!");
}
private static bool GWComparePLC(List<RecipePlcView> recipes, List<Step> steps, List<MixStep> mixSteps, MCRadioButtonEntity RadioE)
{
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;
string j1 = ControlsHelper.JsonSerialize(recipes);
string j2 = ControlsHelper.JsonSerialize(steps);
string j3 = ControlsHelper.JsonSerialize(mixSteps);
switch (ControlsHelper.SingleSelect(RadioE))
{
case 1:
return j1 == ControlsHelper.JsonSerialize(getGelatG1.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getGelatG1.RecipeSteps)
&& j3 == ControlsHelper.JsonSerialize(getWeterM1);
case 2:
return j1 == ControlsHelper.JsonSerialize(getGelatG2.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getGelatG2.RecipeSteps)
&& j3 == ControlsHelper.JsonSerialize(getWeterM2);
case 3:
return j1 == ControlsHelper.JsonSerialize(getGelatG3.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getGelatG3.RecipeSteps)
&& j3 == ControlsHelper.JsonSerialize(getWeterM3);
case 4:
return j1 == ControlsHelper.JsonSerialize(getGelatG4.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getGelatG4.RecipeSteps)
&& j3 == ControlsHelper.JsonSerialize(getWeterM4);
case 5:
return j1 == ControlsHelper.JsonSerialize(getGelatG5.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getGelatG5.RecipeSteps)
&& j3 == ControlsHelper.JsonSerialize(getWeterM5);
case 6:
return j1 == ControlsHelper.JsonSerialize(getGelatG6.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getGelatG6.RecipeSteps)
&& j3 == ControlsHelper.JsonSerialize(getWeterM6);
case 7:
return j1 == ControlsHelper.JsonSerialize(getGelatG7.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getGelatG7.RecipeSteps)
&& j3 == ControlsHelper.JsonSerialize(getWeterM7);
case 8:
return j1 == ControlsHelper.JsonSerialize(getGelatG8.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getGelatG8.RecipeSteps)
&& j3 == ControlsHelper.JsonSerialize(getWeterM8);
default:
MessageBox.Show("未选择产线!");
return true;
}
}
#endregion
#region 干混下传
public static void DryDownload(MCTextBoxEntity TextE, MCComboBoxEntity ComboE, MCRadioButtonEntity RadioE)
{
List<RecipePlcView> recipes = new List<RecipePlcView>();
List<Step> steps = new List<Step>();
List<DeviceMaterrial> materials = new List<DeviceMaterrial>();
DryerGetValue(ComboE.DryM1, TextE.DryW1, TextE.DryT1, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM2, TextE.DryW2, TextE.DryT2, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM3, TextE.DryW3, TextE.DryT3, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM4, TextE.DryW4, TextE.DryT4, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM5, TextE.DryW5, TextE.DryT5, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM6, TextE.DryW6, TextE.DryT6, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM7, TextE.DryW7, TextE.DryT7, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM8, TextE.DryW8, TextE.DryT8, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM9, TextE.DryW9, TextE.DryT9, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM10, TextE.DryW10, TextE.DryT10, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM11, TextE.DryW11, TextE.DryT11, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM12, TextE.DryW12, TextE.DryT12, recipes, materials, RadioE);
DryerGetValue(ComboE.DryM13, TextE.DryW13, TextE.DryT13, recipes, materials, RadioE);
//DryerGetValue(ComboE.DryM14, TextE.DryW14, TextE.DryT14, recipes, materials, RadioE);
//DryerGetValue(ComboE.DryM15, TextE.DryW15, TextE.DryT15, recipes, materials, RadioE);
if (TFlag == 1)
{
MessageBox.Show("公差不能小于0.1");
TFlag = 0;
return;
}
var a = recipes.Where(x => x.Bin != -1).GroupBy(x => x.Bin).All(x => x.Count() == 1);
if (!a)
{
MessageBox.Show("两种物料不可相同!");
return;
}
short dryWaitTime = Convert.ToInt16(TextE.DryWaitTime.MCValue.ToString());
short dryOutDelayTime = Convert.ToInt16(TextE.DryOutDelayTime.MCValue.ToString());
float drySpeed1 = Convert.ToSingle(TextE.DrySpeed1.MCValue.ToString());
float drySpeed2 = Convert.ToSingle(TextE.DrySpeed2.MCValue.ToString());
float drySpeed3 = Convert.ToSingle(TextE.DrySpeed3.MCValue.ToString());
DryDownloadDetail detail = new DryDownloadDetail();
detail.WaitTime = dryWaitTime;
detail.OutDelayTime = dryOutDelayTime;
detail.Speed1 = Convert.ToInt32((short)drySpeed1);
detail.Speed2 = Convert.ToInt32((short)drySpeed2);
detail.Speed3 = Convert.ToInt32((short)drySpeed3);
if (drySpeed1 > 50 || drySpeed2 > 50 || drySpeed3 > 50)
{
MessageBox.Show("速度值不能大于五十!");
return;
}
Step dryStep1 = new Step()
{
MixCode = 1,
MixSpeed = drySpeed1,
};
Step dryStep2 = new Step()
{
MixCode = 4,
MixTime = dryWaitTime,
MixSpeed = drySpeed2,
};
Step dryStep3 = new Step()
{
MixCode = 6,
MixTime = dryOutDelayTime,
MixSpeed = drySpeed3,
};
Step dryStep = new Step();
steps.Add(dryStep1);
steps.Add(dryStep2);
steps.Add(dryStep3);
steps.Add(dryStep);
steps.Add(dryStep);
steps.Add(dryStep);
steps.Add(dryStep);
steps.Add(dryStep);
steps.Add(dryStep);
steps.Add(dryStep);
switch (ControlsHelper.DrySelect(RadioE))
{
case 1:
LjPlanningPlcHelp.DownD1Recipe(recipes, steps);
DeviceMaterrialService.Save(materials);
detail.Id = 1;
break;
case 2:
LjPlanningPlcHelp.DownD2Recipe(recipes, steps);
DeviceMaterrialService.Save(materials);
detail.Id = 2;
break;
case 3:
LjPlanningPlcHelp.DownD3Recipe(recipes, steps);
DeviceMaterrialService.Save(materials);
detail.Id = 3;
break;
case 4:
LjPlanningPlcHelp.DownD4Recipe(recipes, steps);
DeviceMaterrialService.Save(materials);
detail.Id = 4;
break;
}
FreeSqlUnit.Instance.Update<DryDownloadDetail>().SetSource(detail).ExecuteUpdated();
//if (!DYComparePLC(recipes, steps, RadioE))
//{
// MessageBox.Show("干混产线下传数据不完整,请重新下传数据!");
//}
MessageBox.Show("数据下传成功!");
}
private static bool DYComparePLC(List<RecipePlcView> recipes, List<Step> steps, MCRadioButtonEntity RadioE)
{
var getDryerD1 = LjPlanningPlcHelp.GetDryerD1;
var getDryerD2 = LjPlanningPlcHelp.GetDryerD2;
var getDryerD3 = LjPlanningPlcHelp.GetDryerD3;
var getDryerD4 = LjPlanningPlcHelp.GetDryerD4;
string j1 = ControlsHelper.JsonSerialize(recipes);
string j2 = ControlsHelper.JsonSerialize(steps);
switch (ControlsHelper.DrySelect(RadioE))
{
case 1:
return j1 == ControlsHelper.JsonSerialize(getDryerD1.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getDryerD1.RecipeSteps);
case 2:
return j1 == ControlsHelper.JsonSerialize(getDryerD2.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getDryerD2.RecipeSteps);
case 3:
return j1 == ControlsHelper.JsonSerialize(getDryerD3.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getDryerD3.RecipeSteps);
case 4:
return j1 == ControlsHelper.JsonSerialize(getDryerD4.RecipePlcViews)
&& j2 == ControlsHelper.JsonSerialize(getDryerD4.RecipeSteps);
default:
MessageBox.Show("未选择产线!");
return true;
}
}
#endregion
#region 水称下传
public static void WaterDownload(MCTextBoxEntity TextE, MCComboBoxEntity ComboE)
{
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;
float cADeviation; ushort cALeftOrRight;
float hADeviation; ushort hALeftOrRight;
float cBDeviation; ushort cBLeftOrRight;
float hBDeviation; ushort hBLeftOrRight;
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)
&& float.TryParse(Convert.ToString(TextE.CADeviation.MCValue), out cADeviation)
&& float.TryParse(Convert.ToString(TextE.HADeviation.MCValue), out hADeviation)
&& float.TryParse(Convert.ToString(TextE.CBDeviation.MCValue), out cBDeviation)
&& float.TryParse(Convert.ToString(TextE.HBDeviation.MCValue), out hBDeviation)
)
{
HotA.Set = hotASet;
HotB.Set = hotBSet;
ColdA.Set = coldASet;
ColdB.Set = coldBSet;
HotA.Tolerance = hotATol;
HotB.Tolerance = hotBTol;
ColdA.Tolerance = coldATol;
ColdB.Tolerance = coldBTol;
HotA.differ = hADeviation;
HotB.differ = hBDeviation;
ColdA.differ = cADeviation;
ColdB.differ= cBDeviation;
HotA.stand = Convert.ToInt16(ComboE.HALeftOrRight.MCValue);
HotB.stand = Convert.ToInt16(ComboE.HBLeftOrRight.MCValue);
ColdA.stand = Convert.ToInt16(ComboE.CALeftOrRight.MCValue);
ColdB.stand = Convert.ToInt16(ComboE.CBLeftOrRight.MCValue);
WaterDownloadEntity entity = new WaterDownloadEntity();
//1 冷水a 2 冷水b 3 热水a 4 热水b
Db2104WriteHelper.WriteAHostWater(HotA);
entity.Id = 3;
entity.Tolerance=HotA.Tolerance;
entity.stand = HotA.stand;
entity.differ = HotA.differ;
entity.Set = HotA.Set;
entity.Bin=HotA.Bin;
FreeSqlUnit.Instance.Update<WaterDownloadEntity>().SetSource(entity).ExecuteUpdated();
Db2104WriteHelper.WriteBHostWater(HotB);
entity.Id = 4;
entity.Tolerance = HotB.Tolerance;
entity.stand = HotB.stand;
entity.differ = HotB.differ;
entity.Set = HotB.Set;
entity.Bin = HotB.Bin;
FreeSqlUnit.Instance.Update<WaterDownloadEntity>().SetSource(entity).ExecuteUpdated();
Db2104WriteHelper.WriteAColWater(ColdA);
entity.Id = 1;
entity.Tolerance = ColdA.Tolerance;
entity.stand = ColdA.stand;
entity.differ = ColdA.differ;
entity.Set = ColdA.Set;
entity.Bin = ColdA.Bin;
FreeSqlUnit.Instance.Update<WaterDownloadEntity>().SetSource(entity).ExecuteUpdated();
Db2104WriteHelper.WriteBColWater(ColdB);
entity.Id = 2;
entity.Tolerance = ColdB.Tolerance;
entity.stand = ColdB.stand;
entity.differ = ColdB.differ;
entity.Set = ColdB.Set;
entity.Bin = ColdB.Bin;
FreeSqlUnit.Instance.Update<WaterDownloadEntity>().SetSource(entity).ExecuteUpdated();
MesnacServiceManager.Instance.LoggingService.Info("水称数据下发成功!");
MessageBox.Show("水称数据下发成功");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
}
#endregion
#region 手动控制
#region 糊化锅手动下粉料
public static bool GelPowderDownload(MCRadioButtonEntity RadioE)
{
bool isReady;
switch (ControlsHelper.SingleSelect(RadioE))
{
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 = false;
MessageBox.Show("当前未选择产线!");
break;
}
return isReady;
}
#endregion
#region 糊化锅手动加冷水
public static bool GelColdWaterDownload(MCRadioButtonEntity RadioE)
{
bool isReady;
switch (ControlsHelper.SingleSelect(RadioE))
{
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 = false;
MessageBox.Show("当前未选择产线!");
break;
}
return isReady;
}
#endregion
#region 糊化锅手动加热水
public static bool GelHotWaterDownload(MCRadioButtonEntity RadioE)
{
bool isReady;
switch (ControlsHelper.SingleSelect(RadioE))
{
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 = false;
MessageBox.Show("当前未选择产线!");
break;
}
return isReady;
}
#endregion
#region 湿混机手动下糊化料
public static bool WetGelatDownload(MCRadioButtonEntity RadioE)
{
bool isReady;
switch (ControlsHelper.SingleSelect(RadioE))
{
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("当前未选择产线!");
break;
}
return isReady;
}
#endregion
#region 湿混机手动下粉料
public static bool WetGelatDownload(MCTextBoxEntity TextE, MCRadioButtonEntity RadioE)
{
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 false;
}
SetValue value = new SetValue()
{
Value = w,
Toterance = t
};
bool run = false;
var singE = ControlsHelper.SingleSelect(RadioE);
if (run == false)
{
switch (singE)
{
case 1:
PowderDownSignel(MinAnPlc.Heir1, 1);
DB2105WriteHelper.WriteSetValueL1(value);
DB2105WriteHelper.WriteHNo(1, "L", true);
// DB2105WriteHelper.WriteManScrewH1();
break;
case 2:
PowderDownSignel(MinAnPlc.Heir1, 1);
DB2105WriteHelper.WriteSetValueR1(value);
DB2105WriteHelper.WriteHNo(1, "R", true);
// DB2105WriteHelper.WriteManScrewH2();
break;
case 3:
PowderDownSignel(MinAnPlc.Heir2, 2);
DB2105WriteHelper.WriteSetValueL2(value);
DB2105WriteHelper.WriteHNo(2, "L", true);
// DB2105WriteHelper.WriteManScrewH3();
break;
case 4:
PowderDownSignel(MinAnPlc.Heir2, 2);
DB2105WriteHelper.WriteSetValueR2(value);
DB2105WriteHelper.WriteHNo(2, "R", true);
// DB2105WriteHelper.WriteManScrewH4();
break;
case 5:
PowderDownSignel(MinAnPlc.Heir3, 3);
DB2105WriteHelper.WriteSetValueL3(value);
DB2105WriteHelper.WriteHNo(3, "L", true);
//DB2105WriteHelper.WriteManScrewH5();
break;
case 6:
PowderDownSignel(MinAnPlc.Heir3, 3);
DB2105WriteHelper.WriteSetValueR3(value);
DB2105WriteHelper.WriteHNo(3, "R", true);
// DB2105WriteHelper.WriteManScrewH6();
break;
case 7:
PowderDownSignel(MinAnPlc.Heir4, 4);
DB2105WriteHelper.WriteSetValueL4(value);
DB2105WriteHelper.WriteHNo(4, "L", true);
// DB2105WriteHelper.WriteManScrewH7();
break;
case 8:
PowderDownSignel(MinAnPlc.Heir4, 4);
DB2105WriteHelper.WriteSetValueR4(value);
DB2105WriteHelper.WriteHNo(4, "R", true);
//DB2105WriteHelper.WriteManScrewH8();
break;
default:
MessageBox.Show("当前未选择产线!");
return false;
}
ManualWeightLog(w, t, RadioE);
return true;
}
return false;
}
public static bool WetSetWeight(SetValue value, MCRadioButtonEntity RadioE)
{
var singE = ControlsHelper.SingleSelect(RadioE);
switch (singE)
{
case 1:
DB2105WriteHelper.WriteSetValueL1(value);
// DB2105WriteHelper.WriteManScrewH1();
break;
case 2:
DB2105WriteHelper.WriteSetValueR1(value);
// DB2105WriteHelper.WriteManScrewH2();
break;
case 3:
DB2105WriteHelper.WriteSetValueL2(value);
// DB2105WriteHelper.WriteManScrewH3();
break;
case 4:
DB2105WriteHelper.WriteSetValueR2(value);
// DB2105WriteHelper.WriteManScrewH4();
break;
case 5:
DB2105WriteHelper.WriteSetValueL3(value);
//DB2105WriteHelper.WriteManScrewH5();
break;
case 6:
DB2105WriteHelper.WriteSetValueR3(value);
// DB2105WriteHelper.WriteManScrewH6();
break;
case 7:
DB2105WriteHelper.WriteSetValueL4(value);
// DB2105WriteHelper.WriteManScrewH7();
break;
case 8:
DB2105WriteHelper.WriteSetValueR4(value);
//DB2105WriteHelper.WriteManScrewH8();
break;
default:
MessageBox.Show("当前未选择产线!");
return false;
}
return true;
}
private static void ShowError()
{
string message = "称量未结束 请稍后";
MessageBox.Show(message);
}
#endregion
public static void WetGelatStopDownload(MCRadioButtonEntity RadioE)
{
var singE = ControlsHelper.SingleSelect(RadioE);
int no = (singE + 1) / 2;
DB2105WriteHelper.WriteHNo(no, "S", true);
}
#endregion
#region 产线启停
#region 产线启动
public static void LineStart(MCRadioButtonEntity RadioE)
{
switch (ControlsHelper.SingleSelect(RadioE))
{
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;
}
SingleLog("产线启动", RadioE);
}
#endregion
#region 产线停止
public static void LineStop(MCRadioButtonEntity RadioE)
{
switch (ControlsHelper.SingleSelect(RadioE))
{
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;
}
SingleLog("产线停止", RadioE);
}
#endregion
#endregion
#region 维修模式
public static void RepairOnOff(MCLabelEntity LabelE, MCRadioButtonEntity RadioE)
{
if (LabelE.RepairState.MCValue.ToString() == "关")
{
if (MessageBox.Show("是否开启维修模式?", "维修模式确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db3000Helper.WriteModel(ControlsHelper.SingleSelect(RadioE), true);
LabelE.RepairState.MCValue = "开";
SingleLog("维修模式开启", RadioE);
MessageBox.Show("维修模式已开启");
}
else
{
if (LabelE.RepairState.MCValue.ToString() == "开")
{
if (MessageBox.Show("是否关闭维修模式?", "维修模式确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db3000Helper.WriteModel(ControlsHelper.SingleSelect(RadioE), false);
LabelE.RepairState.MCValue = "关";
SingleLog("维修模式关闭", RadioE);
MessageBox.Show("维修模式已关闭");
}
}
}
public static void GRepairOnOff(ButtonEntity buttonEntity, MCRadioButtonEntity RadioE)
{
var index = ControlsHelper.SingleSelect(RadioE);
if(index <= 0)
{
MessageBox.Show("请选择机台");
return;
}
if (buttonEntity.GRepairMode.Text.Contains("关"))
{
if (MessageBox.Show("是否开启维修模式?", "维修模式确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
switch (index)
{
case 1:
DB2105WriteHelper.AddFeededPdG1(true);
break;
case 2:
DB2105WriteHelper.AddFeededPdG2(true);
break;
case 3:
DB2105WriteHelper.AddFeededPdG3(true);
break;
case 4:
DB2105WriteHelper.AddFeededPdG4(true);
break;
case 5:
DB2105WriteHelper.AddFeededPdG5(true);
break;
case 6:
DB2105WriteHelper.AddFeededPdG6(true);
break;
case 7:
DB2105WriteHelper.AddFeededPdG7(true);
break;
case 8:
DB2105WriteHelper.AddFeededPdG8(true);
break;
}
}
else
{
if (buttonEntity.GRepairMode.Text.Contains("开"))
{
if (MessageBox.Show("是否关闭维修模式?", "维修模式确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
}
switch (index)
{
case 1:
DB2105WriteHelper.AddFeededPdG1(false);
break;
case 2:
DB2105WriteHelper.AddFeededPdG2(false);
break;
case 3:
DB2105WriteHelper.AddFeededPdG3(false);
break;
case 4:
DB2105WriteHelper.AddFeededPdG4(false);
break;
case 5:
DB2105WriteHelper.AddFeededPdG5(false);
break;
case 6:
DB2105WriteHelper.AddFeededPdG6(false);
break;
case 7:
DB2105WriteHelper.AddFeededPdG7(false);
break;
case 8:
DB2105WriteHelper.AddFeededPdG8(false);
break;
}
}
}
public static void DryStartOrStop(ButtonEntity buttonEntity, MCRadioButtonEntity RadioE)
{
var index = ControlsHelper.DrySelect(RadioE);
if (index <= 0)
{
MessageBox.Show("请选择机台");
return;
}
if (buttonEntity.DryStartOrStop.Text.Contains("关"))
{
if (MessageBox.Show($"是否启动干混机{index}", "干混机确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
switch (index)
{
case 1:
DB2105WriteHelper.WriteStartOrStop(1,true);
break;
case 2:
DB2105WriteHelper.WriteStartOrStop(2,true);
break;
case 3:
DB2105WriteHelper.WriteStartOrStop(3,true);
break;
case 4:
DB2105WriteHelper.WriteStartOrStop(4,true);
break;
}
}
else
{
if (buttonEntity.DryStartOrStop.Text.Contains("开"))
{
if (MessageBox.Show($"是否关闭干混机{index}", "干混机确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
}
switch (index)
{
case 1:
DB2105WriteHelper.WriteStartOrStop(1, false);
break;
case 2:
DB2105WriteHelper.WriteStartOrStop(2, false);
break;
case 3:
DB2105WriteHelper.WriteStartOrStop(3, false);
break;
case 4:
DB2105WriteHelper.WriteStartOrStop(4, false);
break;
}
}
}
public static void DryPauseOrReply(ButtonEntity buttonEntity, MCRadioButtonEntity RadioE)
{
var index = ControlsHelper.DrySelect(RadioE);
if (index <= 0)
{
MessageBox.Show("请选择机台");
return;
}
if (buttonEntity.DryPauseOrReply.Text.Contains("暂停"))
{
if (MessageBox.Show($"是否恢复干混机{index}", "干混机确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
switch (index)
{
case 1:
DB2107WriteHelper.Spare1(true);
break;
case 2:
DB2107WriteHelper.Spare2(true);
break;
case 3:
DB2107WriteHelper.Spare3(true);
break;
case 4:
DB2107WriteHelper.Spare4(true);
break;
}
}
else
{
if (buttonEntity.DryPauseOrReply.Text.Contains("恢复"))
{
if (MessageBox.Show($"是否暂停干混机{index}", "干混机确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
}
switch (index)
{
case 1:
DB2107WriteHelper.Spare1(false);
break;
case 2:
DB2107WriteHelper.Spare2(false);
break;
case 3:
DB2107WriteHelper.Spare3(false);
break;
case 4:
DB2107WriteHelper.Spare4(false);
break;
}
}
}
#endregion
#region 干混机物料封装
/// <summary>
/// 干混机数据打包封装
/// </summary>
/// <param name="DryM">物料类型</param>
/// <param name="DryW">重量</param>
/// <param name="DryT">公差</param>
/// <param name="recipes">物料集合</param>
/// <param name="materials">数据库物料记录</param>
/// <param name="RadioE">产线选择单选框</param>
private static void DryerGetValue(MCCombobox DryM, MCTextBox DryW, MCTextBox DryT,
List<RecipePlcView> recipes, List<DeviceMaterrial> materials, MCRadioButtonEntity RadioE)
{
int b = Convert.ToInt32(DryM.MCValue.ToString());
short bin = (short)StockMaterrialDbHelp.GetCodeById(b);
float w = Convert.ToSingle(DryW.MCValue.ToString());
float t = Convert.ToSingle(DryT.MCValue.ToString());
//验证公差不能小于0.1
if (b != -1 && t < 0.1)
{
TFlag = 1;
}
RecipePlcView recipe1 = new RecipePlcView()
{
Bin = bin,
Set = w,
Tolerance = t,
};
recipes.Add(recipe1);
DeviceMaterrial deviceMaterial1 = new DeviceMaterrial()
{
DeviceId = ControlsHelper.DrySelect(RadioE),
MaterrialId = b,
Type = 1,
Code = StockMaterrialDbHelp.GetCodeById(b),
Weight = w,
Allowance = t
};
materials.Add(deviceMaterial1);
}
#endregion
#region 上料提示封装
private static void PowderDownSignel(bool minanResult, int num)
{
if (minanResult)
{
DialogResult result = MessageBox.Show(num + "号罐正在上料", "温馨提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
return;
}
}
}
#endregion
}
}