|
|
|
|
using ICSharpCode.Core;
|
|
|
|
|
using Mesnac.Action.Base;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Product.PptPlan.entity;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.entity;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Product.PptPlan
|
|
|
|
|
{
|
|
|
|
|
public class PlanDownloadAction : ChemicalWeighingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
private RuntimeParameter _runtime;
|
|
|
|
|
private DbMCControl _clientGridControl = null; //网格计划控件
|
|
|
|
|
|
|
|
|
|
private string selectedPlanId = null;//选中计划号
|
|
|
|
|
private string selectedPlanState = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime); //必须要调用的
|
|
|
|
|
ICSharpCode.Core.LoggingService<AutoDownloadAction>.Debug("下传计划信息...");
|
|
|
|
|
|
|
|
|
|
//获取界面控件
|
|
|
|
|
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Base_PlanInfo").FirstOrDefault();
|
|
|
|
|
if (clientGridControl == null)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<StopAction>.Error("{生产计划-修改计划信息} 缺少计划列表网格控件...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this._runtime = runtime;
|
|
|
|
|
this._clientGridControl = clientGridControl;
|
|
|
|
|
DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView;
|
|
|
|
|
|
|
|
|
|
if (clientGridView.SelectedRows.Count != 1)
|
|
|
|
|
{
|
|
|
|
|
string msg1_1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_ModifyPlanNumAction_msg1_1")); //请选择一条要修改计划数的计划!
|
|
|
|
|
MessageBox.Show(msg1_1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
this._runtime.IsReturn = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取选中的计划号
|
|
|
|
|
this.selectedPlanId = clientGridView.SelectedRows[0].Cells["plan_Id"].Value as string;
|
|
|
|
|
this.selectedPlanState = clientGridView.SelectedRows[0].Cells["plan_state"].Value as string;
|
|
|
|
|
|
|
|
|
|
if(this.selectedPlanState != "待执行")
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("计划正在执行中,是否要重传该计划!!!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断下位机准备好信号
|
|
|
|
|
/*if (!(BasePlcHelper.Instance.ChemicalWeighing_PC_ConfirmRemote.NowValue.ToInt() == 1 && BasePlcHelper.Instance.ChemicalWeighing_PC_ConfirmReady.NowValue.ToInt() == 1))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("下位机未准备好!!!");
|
|
|
|
|
return;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
//获取配方编号 recipe_id
|
|
|
|
|
string reciprId = clientGridView.SelectedRows[0].Cells["recipe_id"].Value as string;
|
|
|
|
|
|
|
|
|
|
writeToPlc(reciprId, this.selectedPlanId);
|
|
|
|
|
//判断下传是否成功
|
|
|
|
|
|
|
|
|
|
if (reciprId == readRecipeId())
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<StopAction>.Info("{生产计划-计划下传} 计划下传成功...");
|
|
|
|
|
//下传成功后下传RpFinished信号
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("计划下传失败!!!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//开启线程读取计划执行状态
|
|
|
|
|
|
|
|
|
|
//执行完成后判断下一计划执行方式,自动方式则继续执行下发流程
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string readRecipeId()
|
|
|
|
|
{
|
|
|
|
|
bool readResult = BasePlcHelper.Instance.PlcRead(BasePlcHelper.Instance.ChemicalWeighing_PC_RecipeCode, out int[] res);
|
|
|
|
|
|
|
|
|
|
string readRecipeId = "";
|
|
|
|
|
|
|
|
|
|
if (res.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < res.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (res[i] > 0)
|
|
|
|
|
{
|
|
|
|
|
readRecipeId = readRecipeId + res[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return readRecipeId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 将配方数据写入PLC地址
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="recipe"></param>
|
|
|
|
|
/// <param name="planId"></param>
|
|
|
|
|
public void writeToPlc(string recipe,string planId)
|
|
|
|
|
{
|
|
|
|
|
//获取配方信息、获取工艺参数信息
|
|
|
|
|
Base_RecipeInfo info = RecipeHelper.GetRecipeById(recipe);
|
|
|
|
|
|
|
|
|
|
//通过计划编号获取选中计划
|
|
|
|
|
Base_PlanInfo planInfo = PlanHelper.getPlanInfoByPlanId(planId);
|
|
|
|
|
|
|
|
|
|
#region 下传配方参数
|
|
|
|
|
|
|
|
|
|
//配方编号info.recipeId
|
|
|
|
|
string recipeId = info.recipeId.PadRight(10, '0');
|
|
|
|
|
string recipeName = info.recipeName;
|
|
|
|
|
object[] recipeidArray = new object[10];
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 10; i++)
|
|
|
|
|
{
|
|
|
|
|
recipeidArray[i] = recipeId.Substring(i, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//配方编号
|
|
|
|
|
bool resultFromPlc = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_RecipeCode, recipeidArray);
|
|
|
|
|
|
|
|
|
|
//配方名称
|
|
|
|
|
bool writeResult = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_RecipeName, recipeidArray);
|
|
|
|
|
|
|
|
|
|
//设定车数
|
|
|
|
|
var writeResult1 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SetCarNumber, new object[] { planInfo.car_Amount });
|
|
|
|
|
|
|
|
|
|
//格数
|
|
|
|
|
var writeResult2 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SetGeNumber, new object[] { planInfo.grid_Amount });
|
|
|
|
|
|
|
|
|
|
//层数
|
|
|
|
|
var writeResult3 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SetLineNumber, new object[] { planInfo.line_Amount });
|
|
|
|
|
|
|
|
|
|
//通过配方编号获取物料信息、参数信息
|
|
|
|
|
List<Base_RecipeMaterial> recipeMaterials = RecipeHelper.GetRecipeMaterialInfoByRecipeId(info.recipeId);
|
|
|
|
|
|
|
|
|
|
//混料速度1
|
|
|
|
|
var writeResult4 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Hlsd1, new object[] { 18 });
|
|
|
|
|
|
|
|
|
|
//混料速度2
|
|
|
|
|
var writeResult5 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Hlsd2, new object[] { 20 });
|
|
|
|
|
|
|
|
|
|
//混料速度3
|
|
|
|
|
var writeResult6 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Hlsd3, new object[] { 22 });
|
|
|
|
|
|
|
|
|
|
//进料时间
|
|
|
|
|
var writeResult13 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Jlsj, new object[] { 12 });
|
|
|
|
|
|
|
|
|
|
//混料时间
|
|
|
|
|
var writeResult14 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Hlsj, new object[] { 17 });
|
|
|
|
|
|
|
|
|
|
//VCC加料
|
|
|
|
|
Base_RecipeMaterial recipeMaterial = recipeMaterials.Where(x => x.materialId.Contains("202205280001")).FirstOrDefault();
|
|
|
|
|
decimal vccJl = recipeMaterial.materialWeight;
|
|
|
|
|
var writeResult7 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_VCCJl, (float)vccJl);
|
|
|
|
|
|
|
|
|
|
////VCC加料误差
|
|
|
|
|
List<Base_RecipeCratParam> recipeCratParams1 = RecipeHelper.GerCratParamListByRecipeAndMaterial(info.recipeId, "202205280001");
|
|
|
|
|
Base_RecipeCratParam recipeCratParam = recipeCratParams1.Where(x => x.materialId.Equals(recipeMaterial.materialId) && x.paramName.Contains("VCC加料误差")).FirstOrDefault();
|
|
|
|
|
decimal vccjlwc = Convert.ToDecimal(recipeCratParam.paramValue);
|
|
|
|
|
var writeResult8 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_VCCJlWc, (float)vccjlwc);
|
|
|
|
|
|
|
|
|
|
////GFA加料
|
|
|
|
|
Base_RecipeMaterial recipeMaterial2 = recipeMaterials.Where(x => x.materialId.Contains("202205280002")).FirstOrDefault();
|
|
|
|
|
decimal gfajl = recipeMaterial2.materialWeight;
|
|
|
|
|
var writeResult9 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_GFAJl, (float)gfajl);
|
|
|
|
|
|
|
|
|
|
////GFA加料误差
|
|
|
|
|
List<Base_RecipeCratParam> recipeCratParams2 = RecipeHelper.GerCratParamListByRecipeAndMaterial(info.recipeId, "202205280002");
|
|
|
|
|
Base_RecipeCratParam recipeCratParam2 = recipeCratParams2.Where(x => x.materialId.Equals(recipeMaterial2.materialId) && x.paramName.Contains("GFA加料误差")).FirstOrDefault();
|
|
|
|
|
decimal gfajlwc = Convert.ToDecimal(recipeCratParam2.paramValue);
|
|
|
|
|
var writeResult10 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_GFAJlWc, (float)gfajlwc);
|
|
|
|
|
|
|
|
|
|
////树脂加料
|
|
|
|
|
Base_RecipeMaterial recipeMaterial3 = recipeMaterials.Where(x => x.materialId.Contains("202205280003")).FirstOrDefault();
|
|
|
|
|
decimal szjl = recipeMaterial3.materialWeight;
|
|
|
|
|
var writeResult11 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SZJl, (float)szjl);
|
|
|
|
|
|
|
|
|
|
////树脂加料误差
|
|
|
|
|
List<Base_RecipeCratParam> recipeCratParams3 = RecipeHelper.GerCratParamListByRecipeAndMaterial(info.recipeId, "202205280003");
|
|
|
|
|
Base_RecipeCratParam recipeCratParam3 = recipeCratParams3.Where(x => x.materialId.Equals(recipeMaterial3.materialId) && x.paramName.Contains("树脂加料误差")).FirstOrDefault();
|
|
|
|
|
decimal szjlwc = Convert.ToDecimal(recipeCratParam3.paramValue);
|
|
|
|
|
var writeResult12 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SZJlWc, (float)szjlwc);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|