using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data; using ICSharpCode.Core; using Mesnac.Controls.Base; using Mesnac.Action.Base; using Mesnac.Codd.Session; using Mesnac.Action.ChemicalWeighing.Entity; using DevExpress.Utils.Drawing.Helpers; namespace Mesnac.Action.ChemicalWeighing.Product.XlPlan { /// /// 生产管理-当班计划-终止计划业务 /// public class StopAction : ChemicalWeighingAction, IAction { #region 字段定义 private RuntimeParameter _runtime; private DbMCControl _clientGridControl = null; //本机计划控件 #endregion #region 事件定义 /// /// 刷新计划事件 /// public static event EventHandler OnStopPlan; #endregion #region 业务入口 public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用的 if (runtime.Sender is Control) { (runtime.Sender as Control).Enabled = false; } try { ICSharpCode.Core.LoggingService.Debug("生产管理-生产计划-终止计划业务..."); #region 定义变量 string selectedPlanId = null; //选中的计划号 int selectedPlanSerial = 0; //保存选中的计划序号 int selectedPlanCommand = 5; //计划命令:pcStart = 1 , pcHold = 2 , pcEdit = 3 , pcDelete = 4 , pcTerminate=5 int selectedPlanNum = 0; //保存选中计划的计划数 int selectedPlanUnfinished = 0; //计划的剩余数 #endregion #region 检验执行终止计划的条件 #region 判断当班计划界面是否打开 if (PlanHelper.IsInit == false) { string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_StopAction_msg1")); // 当班计划还未初始化,请先打开当班计划,再进行此操作! MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } #endregion #region 检验本地数据连接 DbHelper localHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (localHelper == null) { string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_StopAction_msg2")); //本地数据库连接异常,不能终止计划{0}请在数据库连接正常后再进行“终止”操作。 msg2 = String.Format(msg2, "\r\n"); MessageBox.Show(msg2, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } #endregion #region 获取界面控件 DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_plan").FirstOrDefault(); if (clientGridControl == null) { ICSharpCode.Core.LoggingService.Error("{生产计划-终止计划} 缺少计划列表网格控件..."); return; } this._runtime = runtime; this._clientGridControl = clientGridControl; DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView; #endregion #region 判断是否选择了要终止的计划 if (clientGridView.SelectedRows.Count != 1) { string msg6_1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_StopAction_msg6_1")); //请选择一条要终止的计划! MessageBox.Show(msg6_1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this._runtime.IsReturn = true; return; } selectedPlanId = clientGridView.SelectedRows[0].Cells["Plan_Id"].Value as string; //获取选中的计划号 selectedPlanSerial = Convert.ToInt32(clientGridView.SelectedRows[0].Cells["Plan_Serial"].Value); //获取选中的计划序号 selectedPlanNum = Convert.ToInt32(clientGridView.SelectedRows[0].Cells["Plan_Num"].Value); //获取选中的计划数 selectedPlanUnfinished = selectedPlanNum - Convert.ToInt32(clientGridView.SelectedRows[0].Cells["Real_Num"].Value); //获取选中的剩余数 //int.TryParse(clientGridView.SelectedRows[0].Cells["PlanNum"].Value.ToString(), out selectedPlanNum); #endregion #region 判断计划状态是否合法 PlanState planState = (PlanState)PlanHelper.StateToValue(clientGridView.SelectedRows[0].Cells["Plan_StateText"].Value.ToString()); if (planState == PlanState.Terminated) { string msg7 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_StopAction_msg7_2")); //当前计划已终止,不能执行此操作! MessageBox.Show(msg7, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (planState == PlanState.UnStart) { string msg7 = "该计划尚未开始!"; MessageBox.Show(msg7, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (planState == PlanState.Completed) { string msg7 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_StopAction_msg7_3")); //当前计划已完成,不能执行此操作! MessageBox.Show(msg7, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } #endregion #endregion #region 终止计划业务 if (planState == PlanState.Producting)//终止程序 { string msg8 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_StopAction_msg8")); //当前计划序号{0}设定{1}车,{2}您确认暂停? msg8 = String.Format(msg8, selectedPlanSerial, selectedPlanNum, "\r\n"); DialogResult result = MessageBox.Show(msg8, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { if (true) { PlanHelper.UpdatePlanState(selectedPlanId, 7); BasePlcHelper.Instance.PlcWriteByDataKey(BasePlcHelper.Instance.plt_plc_Stop, new object[] { 1 });//终止PLC程序 string msg11 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_StopAction_msg11")); //终止计划命令发送成功! Mesnac.Basic.MessageBoxTimeOut.Show(msg11, Mesnac.Basic.LanguageHelper.Caption, 3000); } #region 触发终止计划事件 if (OnStopPlan != null) { OnStopPlan(runtime, System.EventArgs.Empty); } #endregion } } #endregion } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("终止计划失败:" + ex.Message, ex); #region 记录操作日志 //base.DBLog(ex.Message); #endregion MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { if (runtime.Sender is Control) { (runtime.Sender as Control).Enabled = true; } } } #endregion } }