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/Product/PptPlan/ProductionBudgetAction.cs

193 lines
11 KiB
C#

using ICSharpCode.Core;
using Mesnac.Action.Base;
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
{
class ProductionBudgetAction : ChemicalWeighingAction, IAction
{
#region 字段定义
private RuntimeParameter _runtime;
//public static event EventHandler ReloadPlan;
private DbMCControl _clientGridControl = null; //网格计划控件
private string selectedPlanId = null;//选中计划号
private string selectedPlanState = null;
#endregion
#region IAction接口实现
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
this._runtime = runtime;
ICSharpCode.Core.LoggingService<ReloadPlanInfo>.Debug("重传计划信息...");
//获取界面控件
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Base_PlanInfo").FirstOrDefault();
if (clientGridControl == null)
{
ICSharpCode.Core.LoggingService<ReloadPlanInfo>.Error("{生产计划-重传计划信息} 缺少计划列表网格控件...");
return;
}
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 == "执行中")
{
//获取当前选中计划
entity.Base_PlanInfo planInfo = PlanHelper.getPlanInfoByPlanId(this.selectedPlanId);
//调试时注释
//if (WriteRecipeInfoToPLC(planInfo))
if(true)
{
ICSharpCode.Core.LoggingService<StopAction>.Debug("{生产计划-计划下传} 计划重传成功...");
//planInfo.plan_beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//Product.PptPlan.PlanHelper.UpdateBasePlanStateInfo(planInfo);
MessageBox.Show("计划重传成功!");
return;
}
else
{
MessageBox.Show("计划重传失败!");
return;
}
#region 触发事件
//if (ReloadPlan != null)
//{
// ReloadPlan(runtime.BaseControl.MCRoot, System.EventArgs.Empty);
//}
#endregion
}
else
{
MessageBox.Show("仅限重传执行中的计划", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
#endregion
/// <summary>
/// 下发PLC计划信息
/// </summary>
/// <param name="base_PlanInfo"></param>
/// <returns></returns>
public static bool WriteRecipeInfoToPLC(Product.PptPlan.entity.Base_PlanInfo base_PlanInfo)
{
try
{
Base_RecipeInfo info = Technical.PmtRecipe.RecipeHelper.GetRecipeById(base_PlanInfo.recipe_Id);
//编号
var plan_Id = Convert.ToInt32(base_PlanInfo.plan_Id);
object[] recipeidArray = Mesnac.Basic.DataProcessor.ToSiemensPLCDataArray(plan_Id);
bool resultPlanNoPlc = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_PlanNo, new object[] { recipeidArray });
//配方编号
bool resultFromPlc = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_RecipeCode, new object[] { int.Parse(base_PlanInfo.recipe_Id) });
//配方名称,测试暂用配方编号代替
bool writeResult = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_RecipeName, new object[] { int.Parse(base_PlanInfo.recipe_Id) });
//设定车数
var writeResult1 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SetCarNumber, new object[] { base_PlanInfo.car_Amount });
//格数
var writeResult2 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SetGeNumber, new object[] { base_PlanInfo.grid_Amount });
//层数
var writeResult3 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SetLineNumber, new object[] { base_PlanInfo.line_Amount });
//通过配方编号获取物料信息、参数信息
List<Base_RecipeMaterial> recipeMaterials = Technical.PmtRecipe.RecipeHelper.GetRecipeMaterialInfoByRecipeId(info.recipeId);
//VCC加料
Base_RecipeMaterial recipeMaterial = recipeMaterials.Where(x => x.materialName.Contains("VCC")).FirstOrDefault();
decimal vccJl = recipeMaterial.materialWeight;
var writeResult9 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_VCCJl, (float)vccJl);
////GFA加料
Base_RecipeMaterial recipeMaterial2 = recipeMaterials.Where(x => x.materialName.Contains("GFA")).FirstOrDefault();
decimal gfajl = recipeMaterial2.materialWeight;
var writeResult10 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_GFAJl, (float)gfajl);
////树脂加料
Base_RecipeMaterial recipeMaterial3 = recipeMaterials.Where(x => x.materialName.Contains("树脂")).FirstOrDefault();
decimal szjl = recipeMaterial3.materialWeight;
var writeResult11 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SZJl, (float)szjl);
//通过配方编号获取工艺参数信息
List<Base_RecipeCratParam> recipeCratParams = Technical.PmtRecipe.RecipeHelper.GerCratParamListByRecipeAndMaterial(info.recipeId, string.Empty);
//混料速度1
Base_RecipeCratParam base_RecipeCratParam1 = recipeCratParams.Where(x => x.paramName.Contains("混料速度1")).FirstOrDefault();
int hlsd1 = int.Parse(base_RecipeCratParam1.paramValue);
var writeResult4 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Hlsd1, new object[] { hlsd1 });
//混料速度2
Base_RecipeCratParam base_RecipeCratParam2 = recipeCratParams.Where(x => x.paramName.Contains("混料速度2")).FirstOrDefault();
int hlsd2 = int.Parse(base_RecipeCratParam2.paramValue);
var writeResult5 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Hlsd2, new object[] { hlsd2 });
//混料速度3
Base_RecipeCratParam base_RecipeCratParam3 = recipeCratParams.Where(x => x.paramName.Contains("混料速度3")).FirstOrDefault();
int hlsd3 = int.Parse(base_RecipeCratParam3.paramValue);
var writeResult6 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Hlsd3, new object[] { hlsd3 });
//进料时间
Base_RecipeCratParam base_RecipeCratParam4 = recipeCratParams.Where(x => x.paramName.Contains("进料时间")).FirstOrDefault();
int jlsj = int.Parse(base_RecipeCratParam4.paramValue);
var writeResult7 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Jlsj, new object[] { jlsj });
//混料时间
Base_RecipeCratParam base_RecipeCratParam5 = recipeCratParams.Where(x => x.paramName.Contains("混料时间")).FirstOrDefault();
int hlsj = int.Parse(base_RecipeCratParam5.paramValue);
var writeResult8 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_Hlsj, new object[] { hlsj });
//VCC加料误差
Base_RecipeCratParam base_RecipeCratParam6 = recipeCratParams.Where(x => x.paramName.Contains("VCC加料误差")).FirstOrDefault();
decimal vccjlwc = decimal.Parse(base_RecipeCratParam6.paramValue);
var writeResult12 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_VCCJlWc, (float)vccjlwc);
//GFA加料误差
Base_RecipeCratParam base_RecipeCratParam7 = recipeCratParams.Where(x => x.paramName.Contains("GFA加料误差")).FirstOrDefault();
decimal gfajlwc = decimal.Parse(base_RecipeCratParam7.paramValue);
var writeResult13 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_GFAJlWc, (float)gfajlwc);
//树脂加料误差
Base_RecipeCratParam base_RecipeCratParam8 = recipeCratParams.Where(x => x.paramName.Contains("树脂加料误差")).FirstOrDefault();
decimal szjlwc = decimal.Parse(base_RecipeCratParam8.paramValue);
var writeResult14 = BasePlcHelper.Instance.PlcWriteFloatByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_SZJlWc, (float)szjlwc);
//配方下传完成
object[] flag = Mesnac.Basic.DataProcessor.ToPLCDataArray("1");
var writeResult15 = BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.ChemicalWeighing_PC_RpFinished, flag);
//计划下传成功后需要修改计划状态为执行中
return true;
}
catch (Exception ex)
{
return true;
}
}
}
}