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/LjPlanning/DownloadAction.cs

585 lines
20 KiB
C#

1 year ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
1 year ago
using DevExpress.Office.Utils;
1 year ago
using DevExpress.XtraRichEdit.Import.OpenXml;
1 year ago
using Mesnac.Action.Base;
1 year ago
using Mesnac.Action.ChemicalWeighing.Entity;
1 year ago
using Mesnac.Action.ChemicalWeighing.LjMixManager;
1 year ago
using Mesnac.Action.ChemicalWeighing.LjPlanning.Db;
using Mesnac.Action.ChemicalWeighing.LjPlanning.Entity;
1 year ago
using Mesnac.Action.ChemicalWeighing.LjProdcutLine;
1 year ago
using Mesnac.PlcUtils;
1 year ago
1 year ago
namespace Mesnac.Action.ChemicalWeighing.LjPlanning
1 year ago
{
1 year ago
public class DownloadAction : ChemicalWeighingAction, IAction
1 year ago
{
1 year ago
private DbMCControl _materialGridControl = null; //物料列表控件
1 year ago
private RuntimeParameter _runtime;
public static event EventHandler OnDown;
1 year ago
1 year ago
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
this._runtime = runtime;
DbMCControl materialGridControl =
this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "lj_planning")
.FirstOrDefault(); //获取物料数据控件
this._materialGridControl = materialGridControl;
1 year ago
1 year ago
DataGridView clientGridView = this._materialGridControl.BaseControl as DataGridView;
1 year ago
1 year ago
//验证是否选中某物料
if (clientGridView.SelectedRows.Count != 1)
{
1 year ago
MessageBox.Show("请选择要下发的数据", Mesnac.Basic.LanguageHelper.Caption,
1 year ago
MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
1 year ago
1 year ago
var dataGridViewRow = clientGridView.SelectedRows[0];
var id = Convert.ToInt32(dataGridViewRow.Cells["Id"].Value);
var ljPlanningView = LjPlanningDb.GetById(id);
1 year ago
1 year ago
LoadingHelper.ShowLoadingScreen();
var watchDog = LjHelp.WatchDog;
if (watchDog == 0)
{
LoadingHelper.CloseForm();
MessageBox.Show("PLC通讯失败");
return;
}
if (ljPlanningView != null)
{
1 year ago
if (ljPlanningView.Status !="0")
{
MessageBox.Show("状态不是新建 禁止下发");
return;
}
1 year ago
//List<RecipePlcView> recipePlcViews = new List<RecipePlcView>();
//List<RecipePlcView> recipePlcViews2 = new List<RecipePlcView>();
//List<Step> recipeSteps = new List<Step>();
//List<MixStep> mixSteps = new List<MixStep>();
//配方名称
1 year ago
var formulaId = ljPlanningView.FormulaId;
var unit = ljPlanningView.Unit;
1 year ago
var plc = BasePlcHelper.Instance;
1 year ago
var formulDetail = LjFormulaDb.GetDetail(formulaId);
Clean(unit);
//单元
switch (unit)
1 year ago
{
case 1:
1 year ago
//单元1 干混1 糊化1 2 湿混 1 2
var dataDry1 = GetUnitDryView(formulDetail);
LjPlanningPlcHelp.DownD1Recipe(dataDry1.H1, dataDry1.R1);
if (dataDry1.H1 != null && dataDry1.H1.Count>0)
1 year ago
{
1 year ago
WriteEnbale(plc.EnableDryD1);
}
else
{
WriteCanel(plc.EnableDryD1);
}
1 year ago
var dataSilo1A = GetUnitSiloView(formulDetail, "A");
LjPlanningPlcHelp.DownG1Recipe(dataSilo1A.H1, dataSilo1A.H2, dataSilo1A.R1);
if (dataSilo1A.H1 != null && dataSilo1A.H1.Count > 0)
1 year ago
{
WriteEnbale(plc.EnableDryG1);
}
else
{
WriteCanel(plc.EnableDryG1);
}
1 year ago
var dataSilo1B = GetUnitSiloView(formulDetail, "B");
LjPlanningPlcHelp.DownG2Recipe(dataSilo1B.H1, dataSilo1B.H2, dataSilo1B.R1);
if (dataSilo1B.H1 != null && dataSilo1B.H1.Count > 0)
1 year ago
{
1 year ago
WriteEnbale(plc.EnableDryG2);
}
else
{
WriteCanel(plc.EnableDryG2);
}
1 year ago
var dataWeter1A = GetUnitWeterView(formulDetail, "A");
LjPlanningPlcHelp.DownM1Recipe(dataWeter1A.R2);
if (dataWeter1A.R2 != null && dataWeter1A.R2.Count>0)
1 year ago
{
WriteEnbale(plc.EnableDryM1);
}
else
{
WriteCanel(plc.EnableDryM1);
}
1 year ago
var dataWeter1B = GetUnitWeterView(formulDetail, "B");
LjPlanningPlcHelp.DownM2Recipe(dataWeter1B.R2);
1 year ago
if (dataWeter1B.R2 != null && dataWeter1B.R2.Count > 0)
1 year ago
{
WriteEnbale(plc.EnableDryM2);
}
else
{
WriteCanel(plc.EnableDryM2);
}
1 year ago
plc.PlcWriteByDataKey(plc.Plan0_RecipeCode, new object[] { formulaId });
plc.PlcWriteByDataKey(plc.Plan0_PlanCode, new object[] { ljPlanningView.Id });
1 year ago
plc.PlcWriteByDataKey(plc.Plan0_Batch, new object[] { ljPlanningView.NumCar });
plc.PlcWriteByDataKey(plc.Plan0_Start, new object[] { 1 });
//把状态变成执行
LjPlanningDb.UpdateStatus(1, ljPlanningView.Id);
1 year ago
break;
case 2:
1 year ago
//单元2 干混2 糊化3 4 湿混 3 4
var dataDry2 = GetUnitDryView(formulDetail);
LjPlanningPlcHelp.DownD2Recipe(dataDry2.H1, dataDry2.R1);
if (dataDry2.H1 != null)
{
WriteEnbale(plc.EnableDryD2);
}
else
{
WriteCanel(plc.EnableDryD2);
}
1 year ago
var dataSilo2A = GetUnitSiloView(formulDetail, "A");
LjPlanningPlcHelp.DownG3Recipe(dataSilo2A.H1, dataSilo2A.H2, dataSilo2A.R1);
if (dataSilo2A.H1 != null)
{
WriteEnbale(plc.EnableDryG3);
}
else
{
WriteCanel(plc.EnableDryG3);
}
1 year ago
var dataSilo2B = GetUnitSiloView(formulDetail, "B");
LjPlanningPlcHelp.DownG4Recipe(dataSilo2B.H1, dataSilo2B.H2, dataSilo2B.R1);
if (dataSilo2B.H1 != null)
{
WriteEnbale(plc.EnableDryG4);
}
else
{
WriteCanel(plc.EnableDryG4);
}
1 year ago
var dataWeter2A = GetUnitWeterView(formulDetail, "A");
LjPlanningPlcHelp.DownM3Recipe(dataWeter2A.R2);
if (dataWeter2A.R2 != null)
{
WriteEnbale(plc.EnableDryM3);
}
var dataWeter2B = GetUnitWeterView(formulDetail, "B");
LjPlanningPlcHelp.DownM4Recipe(dataWeter2B.R2);
if (dataWeter2B.R2 != null)
{
WriteEnbale(plc.EnableDryM4);
}
plc.PlcWriteByDataKey(plc.Plan1_RecipeCode, new object[] { formulaId });
plc.PlcWriteByDataKey(plc.Plan1_RecipeCode, new object[] { ljPlanningView.Id });
plc.PlcWriteByDataKey(plc.Plan1_Batch, new object[] { ljPlanningView.NumCar });
plc.PlcWriteByDataKey(plc.Plan1_Start, new object[] { 1 });
//把状态变成执行
LjPlanningDb.UpdateStatus(1, ljPlanningView.Id);
break;
case 3:
1 year ago
//单元3 干混3 糊化5 6 湿混 5 6
var dataDry3 = GetUnitDryView(formulDetail);
LjPlanningPlcHelp.DownD3Recipe(dataDry3.H1, dataDry3.R1);
if (dataDry3.H1 != null)
{
WriteEnbale(plc.EnableDryD3);
}
var dataSilo3A = GetUnitSiloView(formulDetail, "A");
LjPlanningPlcHelp.DownG5Recipe(dataSilo3A.H1, dataSilo3A.H2, dataSilo3A.R1);
if (dataSilo3A.H1 != null)
{
WriteEnbale(plc.EnableDryG5);
}
var dataSilo3B = GetUnitSiloView(formulDetail, "B");
LjPlanningPlcHelp.DownG6Recipe(dataSilo3B.H1, dataSilo3B.H2, dataSilo3B.R1);
if (dataSilo3B.H1 != null)
{
WriteEnbale(plc.EnableDryG6);
}
var dataWeter3A = GetUnitWeterView(formulDetail, "A");
LjPlanningPlcHelp.DownM5Recipe(dataWeter3A.R2);
if (dataWeter3A.R2 != null)
{
WriteEnbale(plc.EnableDryM5);
}
var dataWeter3B = GetUnitWeterView(formulDetail, "B");
LjPlanningPlcHelp.DownM6Recipe(dataWeter3B.R2);
if (dataWeter3B.R2 != null)
{
WriteEnbale(plc.EnableDryM6);
}
plc.PlcWriteByDataKey(plc.Plan2_RecipeCode, new object[] { formulaId });
plc.PlcWriteByDataKey(plc.Plan2_RecipeCode, new object[] { ljPlanningView.Id });
plc.PlcWriteByDataKey(plc.Plan2_Batch, new object[] { ljPlanningView.NumCar });
plc.PlcWriteByDataKey(plc.Plan2_Start, new object[] { 1 });
//把状态变成执行
LjPlanningDb.UpdateStatus(1, ljPlanningView.Id);
1 year ago
break;
case 4:
1 year ago
//单元4 干混4 糊化7 8 湿混 7 8
var dataDry4 = GetUnitDryView(formulDetail);
LjPlanningPlcHelp.DownD4Recipe(dataDry4.H1, dataDry4.R1);
if (dataDry4.H1 != null)
{
WriteEnbale(plc.EnableDryD4);
}
var dataSilo4A = GetUnitSiloView(formulDetail, "A");
LjPlanningPlcHelp.DownG7Recipe(dataSilo4A.H1, dataSilo4A.H2, dataSilo4A.R1);
if (dataSilo4A.H1 != null)
{
WriteEnbale(plc.EnableDryG7);
}
var dataSilo4B = GetUnitSiloView(formulDetail, "B");
LjPlanningPlcHelp.DownG8Recipe(dataSilo4B.H1, dataSilo4B.H2, dataSilo4B.R1);
if (dataSilo4B.H1 != null)
{
WriteEnbale(plc.EnableDryG8);
}
var dataWeter4A = GetUnitWeterView(formulDetail, "A");
LjPlanningPlcHelp.DownM7Recipe(dataWeter4A.R2);
if (dataWeter4A.R2 != null)
{
WriteEnbale(plc.EnableDryM7);
}
var dataWeter4B = GetUnitWeterView(formulDetail, "B");
LjPlanningPlcHelp.DownM8Recipe(dataWeter4B.R2);
if (dataWeter4B.R2 != null)
{
WriteEnbale(plc.EnableDryM8);
}
plc.PlcWriteByDataKey(plc.Plan3_RecipeCode, new object[] { formulaId });
plc.PlcWriteByDataKey(plc.Plan3_RecipeCode, new object[] { ljPlanningView.Id });
plc.PlcWriteByDataKey(plc.Plan3_Batch, new object[] { ljPlanningView.NumCar });
plc.PlcWriteByDataKey(plc.Plan3_Start, new object[] { 1 });
//把状态变成执行
LjPlanningDb.UpdateStatus(1, ljPlanningView.Id);
break;
1 year ago
}
1 year ago
1 year ago
1 year ago
}
else
{
MessageBox.Show("数据下发失败");
}
1 year ago
1 year ago
LoadingHelper.CloseForm();
MessageBox.Show("数据下发成功");
1 year ago
if (OnDown != null)
{
OnDown(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
1 year ago
}
public void WriteEnbale(DataKeyValue key)
{
var plc = BasePlcHelper.Instance;
bool b= plc.PlcWriteByDataKey(key, new object[] { 1 });
}
public void WriteCanel(DataKeyValue key)
{
var plc = BasePlcHelper.Instance;
plc.PlcWriteByDataKey(key, new object[] {0});
1 year ago
}
public UnitView GetUnitDryView(List<LjFormulaDetail> formulDetail)
{
UnitView unitView = new UnitView();
//获取干混机1
var dataDry1C = formulDetail.Where(x => x.MachineType == "Dry" && x.FormulaType == 1 && x.Machine == "A").ToList();
var dataDry1CPlcView = dataDry1C.Select(x => new RecipePlcView()
{
Bin = x.BinNo,
Set = x.Weight,
1 year ago
TolErance = x.Tolerance
}).ToList();
unitView.H1 = dataDry1CPlcView;
var dataDry1H = formulDetail.Where(x => x.MachineType == "Dry" && x.FormulaType == 2 && x.Machine == "A").ToList();
var dataDry1HPlcView = dataDry1H.Select(x => new Step()
{
MixCode = x.ActionCode,
MixSpeed = x.Speed,
MixTemp = x.Temp,
MixTime = x.TimeInfo
}).ToList();
unitView.R1 = dataDry1HPlcView;
return unitView;
}
public UnitView GetUnitSiloView(List<LjFormulaDetail> formulDetail, string machine)
{
UnitView unitView = new UnitView();
// 糊化1 水 称量 称量
var dataSilo1C = formulDetail.Where(x => x.MachineType == "Silo" && x.FormulaType == 1 && x.Machine == machine).ToList();
1 year ago
var dataSilo1CPlcView = dataSilo1C.Select(x => new RecipePlcView()
{
Bin = x.BinNo,
Set = x.Weight,
1 year ago
TolErance = x.Tolerance
}).ToList();
unitView.H1 = dataSilo1CPlcView;
var dataSilo1CWater = formulDetail.Where(x => x.MachineType == "Silo_Water" && x.FormulaType == 1 && x.Machine == machine).ToList();
var dataSilo1CWaterPlcView = dataSilo1CWater.Select(x => new RecipePlcView()
{
Bin = x.BinNo,
Set = x.Weight,
1 year ago
TolErance = x.Tolerance
}).ToList();
unitView.H2 = dataSilo1CWaterPlcView;
var dataSilo1H = formulDetail.Where(x => x.MachineType == "Silo" && x.FormulaType == 2 && x.Machine == machine).ToList();
var dataSilo1HPlcView = dataSilo1H.Select(x => new Step()
{
MixCode = x.ActionCode,
MixSpeed = x.Speed,
MixTemp = x.Temp,
MixTime = x.TimeInfo
}).ToList();
unitView.R1 = dataSilo1HPlcView;
return unitView;
}
public UnitView GetUnitWeterView(List<LjFormulaDetail> formulDetail, string machine)
{
//单元1 干混1 糊化1 2 湿混 1 2
UnitView unitView = new UnitView();
// 糊化2 水 称量 称量
var dataSilo2C = formulDetail.Where(x => x.MachineType == "Weter" && x.FormulaType == 1 && x.Machine == machine).ToList();
var dataSilo2CPlcView = dataSilo2C.Select(x => new RecipePlcView()
{
Bin = x.BinNo,
Set = x.Weight,
1 year ago
TolErance = x.Tolerance
}).ToList();
unitView.H1 = dataSilo2CPlcView;
var dataSilo2H = formulDetail.Where(x => x.MachineType == "Weter" && x.FormulaType == 2 && x.Machine == machine).ToList();
var dataSilo2HPlcView = dataSilo2H.Select(x => new MixStep()
{
MixCode = x.ActionCode,
MixSpeed = x.Speed,
MixTemp = x.Temp,
MixTime = x.TimeInfo,
SetValue = x.SetValue,
SetTolerance = x.SetTolerance
1 year ago
}).ToList();
unitView.R2 = dataSilo2HPlcView;
return unitView;
1 year ago
}
public void Clean(int unit)
{
List<RecipePlcView> H1 = new List<RecipePlcView>();
List< Step > sto = new List< Step >();
List < MixStep > mixSteps=new List<MixStep> ();
for (int i = 0; i < 12; i++) {
H1.Add(new RecipePlcView()
{
Bin = 0,
Set = 0,
TolErance = 0
});
sto.Add(new Step()
{
MixCode = 0,
MixSpeed = 0,
MixTemp = 0,
MixTime = 0
});
mixSteps.Add(new MixStep()
{
MixCode = 0,
MixSpeed = 0,
MixTemp = 0,
MixTime = 0,
SetTolerance = 0,
SetValue = 0
});
}
if(unit == 1)
{
LjPlanningPlcHelp.DownD1Recipe(H1, sto);
LjPlanningPlcHelp.DownG1Recipe(H1, H1, sto);
LjPlanningPlcHelp.DownG2Recipe(H1, H1, sto);
LjPlanningPlcHelp.DownM1Recipe(mixSteps);
LjPlanningPlcHelp.DownM2Recipe(mixSteps);
}
if (unit == 2)
{
LjPlanningPlcHelp.DownD2Recipe(H1, sto);
LjPlanningPlcHelp.DownG3Recipe(H1, H1, sto);
LjPlanningPlcHelp.DownG4Recipe(H1, H1, sto);
LjPlanningPlcHelp.DownM3Recipe(mixSteps);
LjPlanningPlcHelp.DownM4Recipe(mixSteps);
}
if (unit == 3)
{
LjPlanningPlcHelp.DownD3Recipe(H1, sto);
LjPlanningPlcHelp.DownG5Recipe(H1, H1, sto);
LjPlanningPlcHelp.DownG6Recipe(H1, H1, sto);
LjPlanningPlcHelp.DownM5Recipe(mixSteps);
LjPlanningPlcHelp.DownM6Recipe(mixSteps);
}
if (unit == 4)
{
LjPlanningPlcHelp.DownD4Recipe(H1, sto);
LjPlanningPlcHelp.DownG7Recipe(H1, H1, sto);
LjPlanningPlcHelp.DownG8Recipe(H1, H1, sto);
LjPlanningPlcHelp.DownM7Recipe(mixSteps);
LjPlanningPlcHelp.DownM8Recipe(mixSteps);
}
}
1 year ago
}
1 year ago
1 year ago
}