using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.PlnSaleOrd.BaseMethod; using Core.StlMes.Client.PlnSaleOrd.Entity; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using Core.Mes.Client.Comm.Format; using com.steering.pss.plnsaleord.processOrder.entity; namespace Core.StlMes.Client.PlnSaleOrd { /// /// 制程变更 /// public partial class FrmMscPlineChange : FrmBase { public FrmMscPlineChange() { this.IsLoadUserView = true; InitializeComponent(); System.Threading.Thread t = new System.Threading.Thread(setGridColunmName); t.Start(); } private void setGridColunmName() { System.Threading.Thread.Sleep(3000); if (!this.IsDisposed) { EntityHelper.ShowGridCaption(ultraGridProc.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGridBom.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGridPline.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGridGrade.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGridProcess.DisplayLayout.Bands[0]); } } /// /// 待分配排产总量 /// private double _finishSumWgt = 0; /// /// 交货行主键 /// private string _ordLnDlyPk = ""; /// /// 排产流水号 /// private string _plnDivideId = ""; /// /// 成品完成量 /// private double _finishWgt = 0; /// /// 变更的工序 /// private string _processCode = ""; /// /// 排产联动组号 /// private string _planGroupId = ""; /// /// 工艺序号 /// private string _craftSeq = ""; /// /// 制程号 /// private string _mscPline = ""; /// /// BOM /// private string _bom = ""; /// /// 轧制机组 /// private string _dPine = ""; /// /// 合同行 /// private string _orderNoSeq = ""; /// /// 合同来源 /// private string _orderSource = ""; private double _initProcessWgt = 0; /// /// 排产实体类集合 /// private Dictionary _dicProcs = new Dictionary(); /// /// 制程变更传递数据类集合 /// private Dictionary _dicChanges = new Dictionary(); public FrmMscPlineChange(string ordLnDlyPk, string processCode, string plnDivideId, string planGroupId,double initProcessWgt, double finishWgt, OpeBase ob,string orderNoSeq,string orderSource) { this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this._ordLnDlyPk = ordLnDlyPk; this._plnDivideId = plnDivideId; this._finishWgt = finishWgt; this._processCode = processCode; this._planGroupId = planGroupId; this._initProcessWgt = initProcessWgt; this._orderNoSeq = orderNoSeq; this._orderSource = orderSource; this.ob = ob; this.IsLoadUserView = true; InitializeComponent(); System.Threading.Thread t = new System.Threading.Thread(setGridColunmName); t.Start(); } /// /// 初始化界面 /// /// /// private void FrmMscPlineChange_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(ultraGridProc.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGridBom.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGridPline.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGridGrade.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGridProcess.DisplayLayout.Bands[0]); BaseHelper.setOtherColumnReadOnly(ultraGridProc, new string[] { "PlanWtD", "PlanNumD" }); BaseHelper.setOtherColumnReadOnly(ultraGridPline, new string[] { "CHC" }); BaseHelper.setOtherColumnReadOnly(ultraGridGrade, new string[] { "" }); BaseHelper.setOtherColumnReadOnly(ultraGridProcess, new string[] { "" }); QuerySaleOrdProc(_ordLnDlyPk); InitPlanWgt(); userControlSaleordProc1.UltraGridSaleordProc1.AfterRowActivate += UltraGridSaleordProc1_AfterRowActivate; } /// /// 初始化排产量 /// private void InitPlanWgt() { UltraGridRow ugrProduc = userControlSaleordProc1.getUltraGridRow(_plnDivideId); if (ugrProduc != null) { string planWtD = ugrProduc.Cells["PlanWtD"].Text.Equals("") ? "0" : ugrProduc.Cells["PlanWtD"].Text; _finishSumWgt = double.Parse(planWtD); ugrProduc.Cells["PlanWtD"].Value = _finishWgt.ToString(); NumPlanWgt.Value = _finishSumWgt - _finishWgt; } } /// /// 激活排产记录查询制程 /// /// /// void UltraGridSaleordProc1_AfterRowActivate(object sender, EventArgs e) { QueryPline(_ordLnDlyPk); } /// /// 查询排产行工艺制程物料产线 /// private void DoQueryProc(string r_ordLnDlyPk, string r_plnDivideId) { DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.processOrder.CoreMscPlineChange.queryProcCraftIndex", new object[] { r_ordLnDlyPk, r_plnDivideId }, this.ob); if (dt != null && dt.Rows.Count > 0) { _craftSeq = dt.Rows[0]["CRAFT_SEQ"].ToString(); _mscPline = dt.Rows[0]["INDEX_SEQ"].ToString(); _bom = dt.Rows[0]["BOM"].ToString(); _dPine = dt.Rows[0]["GROUP_ROLL"].ToString(); } } /// /// 查询合同排产 /// /// private void QuerySaleOrdProc(string ordLnDlyPk) { DoQueryProc(ordLnDlyPk, _plnDivideId); userControlSaleordProc1.Query(ordLnDlyPk, _plnDivideId, this.ob); } /// /// 查询制程 /// /// private void QueryPline(string ordLnDlyPk) { List listPline = EntityHelper.GetData ("com.steering.pss.plnsaleord.processOrder.CoreMscPlineChange.queryPline", new object[] { ordLnDlyPk }, this.ob); craftOrdDesignMscPlEntityBindingSource.DataSource = listPline; if (listPline.Count > 0) { UltraGridRow uRow = userControlSaleordProc1.UltraGridSaleordProc1.ActiveRow; foreach (UltraGridRow ugr in ultraGridPline.Rows) { if (ugr.Cells["CraftSeq"].Text.Equals(_craftSeq) && ugr.Cells["MscPline"].Text.Equals(_mscPline)) { ugr.Appearance.BackColor = Color.GreenYellow; } if (ugr.Cells["CraftSeq"].Text.Equals(uRow.Cells["CraftSeq"].Value.ToString()) && ugr.Cells["MscPline"].Text.Equals(uRow.Cells["IndexSeq"].Value.ToString())) { ultraGridPline.ActiveRow = ugr; } } } } /// /// 查询钢种 /// /// private void QueryGrade(string designKey, string mscPline) { List listGrade = EntityHelper.GetData ("com.steering.pss.plnsaleord.processOrder.CoreMscPlineChange.queryGrade", new object[] { designKey, mscPline }, this.ob); craftOrdDesignMscPlGzEntityBindingSource.DataSource = listGrade; } /// /// 查询工序 /// /// private void QueryOperation(string designKey, string mscPline) { List listPrc = EntityHelper.GetData ("com.steering.pss.plnsaleord.processOrder.CoreMscPlineChange.queryOperation", new object[] { designKey, mscPline }, this.ob); craftOrdDesignMscPlPrcEntityBindingSource.DataSource = listPrc; } /// /// 查询工序点 /// private void QueryOperationPoint(string designKey, string mscPline) { DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.processOrder.CoreMscPlineChange.queryOperationPoint", new object[] { designKey, mscPline }, this.ob); if (dt != null && dt.Rows.Count > 0) { string points = dt.Rows[0][0].ToString(); pointTxt.Text = points.Substring(0, points.LastIndexOf("->")); } else { pointTxt.Text = ""; } } /// /// 查询BOM /// /// 物料编码 /// 冶金规范码 /// 制程号 /// 全程途径码 private void QueryBom(string materialNo, string msc, string mscPline, string wholeBacklog) { List listBom = EntityHelper.GetData ("com.steering.pss.plnsaleord.processOrder.CoreMscPlineChange.queryBom", new object[] { materialNo, msc, mscPline, wholeBacklog }, this.ob); slmOrdDesignBomEntityBindingSource.DataSource = listBom; if (listBom.Count > 0) { UltraGridRow uRow = userControlSaleordProc1.UltraGridSaleordProc1.ActiveRow; foreach (UltraGridRow ugr in ultraGridBom.Rows) { if (ugr.Cells["Bom"].Text.Equals(_bom)) { ugr.Appearance.BackColor = Color.GreenYellow; } if (ugr.Cells["Bom"].Text.Equals(uRow.Cells["Bom"].Value.ToString())) { ultraGridBom.ActiveRow = ugr; } } } } /// /// 查询产线 /// /// /// /// private void QueryLine(string designKey, string mscPline, string dInMaterialNo, string dOutMaterialNo) { DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.processOrder.CoreMscPlineChange.queryLine", new object[] { designKey, mscPline, dInMaterialNo, dOutMaterialNo }, this.ob); GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true); if (dt!=null && dt.Rows.Count > 0) { UltraGridRow uRow = userControlSaleordProc1.UltraGridSaleordProc1.ActiveRow; foreach (UltraGridRow ugr in ultraGridLine.Rows) { if (ugr.Cells["PLINE_CODE"].Text.Equals(_dPine)) { ugr.Appearance.BackColor = Color.GreenYellow; } if (ugr.Cells["PLINE_CODE"].Text.Equals(uRow.Cells["GroupRoll"].Value.ToString())) { ultraGridLine.ActiveRow = ugr; } } } } /// /// 激活制程行 /// /// /// private void ultraGridPline_AfterRowActivate(object sender, EventArgs e) { UltraGridRow ugrActive = ultraGridPline.ActiveRow; if (ugrActive == null) { return; } string designKey = ugrActive.Cells["DesginKey"].Text; string mscPline = ugrActive.Cells["MscPline"].Text; //查询数据 QueryGrade(designKey, mscPline); QueryOperation(designKey, mscPline); QueryOperationPoint(designKey, mscPline); //获取变更的行 UltraGridRow ugrChange = userControlSaleordProc1.getUltraGridRow(_plnDivideId); string msc = ugrChange.Cells["Msc"].Text; string materialNo = ugrChange.Cells["MaterialNo"].Text; string wholeBacklog = ugrActive.Cells["WholeBacklog"].Text; //查询BOM QueryBom(materialNo, msc, mscPline, wholeBacklog); } /// /// BOM激活行(查询产线) /// /// /// private void ultraGridBom_AfterRowActivate(object sender, EventArgs e) { UltraGridRow ugrBom = ultraGridBom.ActiveRow; if (ugrBom == null) { return; } UltraGridRow ugrPline = ultraGridPline.ActiveRow; if (ugrPline == null) { return; } string designKey = ugrPline.Cells["DesginKey"].Text; string mscPline = ugrPline.Cells["MscPline"].Text; string inMaterialNo = ugrBom.Cells["DInMaterialNo"].Text; string outMaterialNo = ugrBom.Cells["DOutMaterialNo"].Text; QueryLine(designKey, mscPline, inMaterialNo, outMaterialNo); } private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { switch (e.Tool.Key) { case "新增": AddMscPline(); break; case "修改": ModifyMscPine(); break; case "删除": deleteMscPline(); break; case "下发": downMscPline(); break; case "关闭": this.Close(); break; case "刷新": DoRefresDate(); break; default: break; } } /// /// 刷新 /// private void DoRefresDate() { foreach (UltraGridRow uRow in userControlSaleordProc1.UltraGridSaleordProc1.Rows) { if (uRow != null && uRow.Cells["Planstatus"].Text.Equals("维护")) { PlnSaleordProcEntity proEntity = EntityHelper.CopyEntity(uRow.ListObject); //删除排产实体类 _dicProcs.Remove(proEntity.PlnDivideId); //删除制程变更传递数据类 _dicChanges.Remove(proEntity.PlnDivideId); } } QuerySaleOrdProc(_ordLnDlyPk); InitPlanWgt(); } /// /// 新增排产记录 /// private void AddMscPline() { ultraGridPline.UpdateData(); ultraGridBom.UpdateData(); ultraGridLine.UpdateData(); double waitPlanWtD = double.Parse(NumPlanWgt.Value.ToString()); if (waitPlanWtD <= 0) { MessageUtil.ShowWarning("待分配排产量为0,不能新增排产记录!"); return; } IQueryable ugrPlines = ultraGridPline.Rows.AsQueryable().Where(" CHC = 'True' "); if (ugrPlines == null || ugrPlines.Count() != 1) { MessageUtil.ShowWarning("请选择一个制程!"); return; } //制程 CraftOrdDesignMscPlEntity plEntity = (CraftOrdDesignMscPlEntity)ugrPlines.First().ListObject; IQueryable ugrBoms = ultraGridBom.Rows.AsQueryable().Where(" CHC = 'True' "); if (ugrBoms == null || ugrBoms.Count() != 1) { MessageUtil.ShowWarning("请选择一条Bom!"); return; } //bom SlmOrdDesignBomEntity bomEntity = (SlmOrdDesignBomEntity)ugrBoms.First().ListObject; IQueryable ugrLines = ultraGridLine.Rows.AsQueryable().Where(" CHC = 'True' "); if (ugrLines == null || ugrLines.Count() != 1) { MessageUtil.ShowWarning("请选择一条轧管产线!"); return; } //产线 UltraGridRow ugrLine = ugrLines.First(); if (plEntity.CraftSeq.Equals(_craftSeq) && plEntity.MscPline.Equals(_mscPline) && bomEntity.Bom.Equals(_bom) && ugrLine.Cells["PLINE_CODE"].Value.ToString().Equals(_dPine)) { MessageUtil.ShowWarning("您所选取的工艺、制程、物料、产线与原记录完全相同!"); return; } //排产原始行 UltraGridRow ugrProduc = userControlSaleordProc1.getUltraGridRow(_plnDivideId); //获取排产分配量 FrmPlanWgtIn frmPlanWgtIn = new FrmPlanWgtIn(waitPlanWtD); frmPlanWgtIn.ShowDialog(); Boolean wgtFlag = frmPlanWgtIn.Flag; if (!wgtFlag) { return; } double planWgt = frmPlanWgtIn.PlanWgt; PlnSaleordProcEntity plnProcEntity = EntityHelper.CopyEntity(ugrProduc.ListObject); string plnDivideId = userControlSaleordProc1.getMaxPlnDivideId(); plnProcEntity.PlnDivideId = plnDivideId; plnProcEntity.PlanWtD = (decimal?)planWgt; plnProcEntity.CraftFileNo = plEntity.CraftNo; plnProcEntity.ProcessSeq = plEntity.WholeBacklog; plnProcEntity.Bom = bomEntity.Bom; plnProcEntity.Gradecode = bomEntity.Gradecode; plnProcEntity.Planstatus = "维护"; //界面增加一条记录 userControlSaleordProc1.AddLine(plnProcEntity); //修改待分配排产量 NumPlanWgt.Value = double.Parse(NumPlanWgt.Value.ToString()) - planWgt; //保存排产实体类 _dicProcs.Add(plnDivideId, plnProcEntity); //保存制程变更传递数据类 MscPlineChangeEntity changeEntity = new MscPlineChangeEntity(); changeEntity.CreatName = UserInfo.GetUserName(); changeEntity.OrdLnDlyPk = plnProcEntity.OrdLnDlyPk; changeEntity.PlnDivideId = _plnDivideId; changeEntity.PlanWeightD = planWgt; changeEntity.CraftSeq = plEntity.CraftSeq; changeEntity.MscPline = plEntity.MscPline; changeEntity.Bom = bomEntity.Bom; changeEntity.DPline = ugrLine.Cells["PLINE_CODE"].Text; _dicChanges.Add(plnDivideId, changeEntity); } /// /// 删除排产记录 /// private void deleteMscPline() { UltraGridRow ugr = userControlSaleordProc1.getActiveRow(); if (ugr == null || !ugr.Cells["Planstatus"].Text.Equals("维护")) { MessageUtil.ShowWarning("请选择一条维护的排产记录"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否删除此排产记录!") == DialogResult.No) { return; } //转化为实体类 PlnSaleordProcEntity proEntity = EntityHelper.CopyEntity(ugr.ListObject); double planWtD = double.Parse(proEntity.PlanWtD.ToString()); userControlSaleordProc1.RemoveLine((PlnSaleordProcEntity)ugr.ListObject); //刷新待分配排产量 NumPlanWgt.Value = double.Parse(NumPlanWgt.Value.ToString()) + planWtD; //删除排产实体类 _dicProcs.Remove(proEntity.PlnDivideId); //删除制程变更传递数据类 _dicChanges.Remove(proEntity.PlnDivideId); } /// /// 修改原排产记录 /// private void ModifyMscPine() { ultraGridPline.UpdateData(); ultraGridBom.UpdateData(); ultraGridLine.UpdateData(); IQueryable ugrPlines = ultraGridPline.Rows.AsQueryable().Where(" CHC = 'True' "); if (ugrPlines == null || ugrPlines.Count() != 1) { MessageUtil.ShowWarning("请选择一个制程!"); return; } //制程 CraftOrdDesignMscPlEntity plEntity = (CraftOrdDesignMscPlEntity)ugrPlines.First().ListObject; IQueryable ugrBoms = ultraGridBom.Rows.AsQueryable().Where(" CHC = 'True' "); if (ugrBoms == null || ugrBoms.Count() != 1) { MessageUtil.ShowWarning("请选择一条Bom!"); return; } //bom SlmOrdDesignBomEntity bomEntity = (SlmOrdDesignBomEntity)ugrBoms.First().ListObject; IQueryable ugrLines = ultraGridLine.Rows.AsQueryable().Where(" CHC = 'True' "); if (ugrLines == null || ugrLines.Count() != 1) { MessageUtil.ShowWarning("请选择一条轧管产线!"); return; } //产线 UltraGridRow ugrLine = ugrLines.First(); if (plEntity.CraftSeq.Equals(_craftSeq) && plEntity.MscPline.Equals(_mscPline) && bomEntity.Bom.Equals(_bom) && ugrLine.Cells["PLINE_CODE"].Value.ToString().Equals(_dPine)) { MessageUtil.ShowWarning("您所选取的工艺、制程、物料、产线与原记录完全相同!"); return; } //排产原始行 UltraGridRow ugrProduc = userControlSaleordProc1.getUltraGridRow(_plnDivideId); PlnSaleordProcEntity plnProcEntity = EntityHelper.CopyEntity(ugrProduc.ListObject); string plnDivideId = userControlSaleordProc1.getMaxPlnDivideId(); MscPlineChangeEntity changeEntity = new MscPlineChangeEntity(); changeEntity.CreatName = UserInfo.GetUserName(); changeEntity.OrdLnDlyPk = plnProcEntity.OrdLnDlyPk; changeEntity.PlnDivideId = _plnDivideId; changeEntity.CraftSeq = plEntity.CraftSeq; changeEntity.MscPline = plEntity.MscPline; changeEntity.Bom = bomEntity.Bom; changeEntity.DPline = ugrLine.Cells["PLINE_CODE"].Text; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.plnsaleord.processOrder.CoreProcessOrder"; ccp.MethodName = "modifyChangeProc"; ccp.ServerParams = new object[] { changeEntity,_orderNoSeq,_orderSource }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { MessageUtil.ShowTips("修改成功!"); DoRefresDate(); } else { MessageUtil.ShowError("修改失败:" + ccp.ReturnInfo); return; } } /// /// 下发 /// private void downMscPline() { double waitPlanWtD = double.Parse(NumPlanWgt.Value.ToString()); if (waitPlanWtD > 0) { MessageUtil.ShowWarning("待分配排产量未分配完全,不能下发!"); return; } List addProcEntitys = new List(); //新增的排产集合 foreach (string key in _dicProcs.Keys) { addProcEntitys.Add(_dicProcs[key]); } //制程变更传递数据类集合 List addChangeEntitys = new List(); foreach (string key in _dicChanges.Keys) { addChangeEntitys.Add(_dicChanges[key]); } if (addProcEntitys.Count != addChangeEntitys.Count) { MessageUtil.ShowWarning("数据异常,请重新新增数据!"); return; } //原始排产记录 UltraGridRow ugrProc = userControlSaleordProc1.getUltraGridRow(_plnDivideId); PlnSaleordProcEntity beginProcEntity = (PlnSaleordProcEntity)ugrProc.ListObject; if (MessageUtil.ShowYesNoAndQuestion("是否下发维护中的排产记录?") == DialogResult.No) { return; } bool isUseNewCraft = false; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.plnsaleord.processOrder.CoreMscPlineChange"; ccp.MethodName = "getIsUseNewCraft"; ccp.ServerParams = new object[] { _planGroupId, _processCode, addChangeEntitys[0] }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { bool isAllow = (Boolean)ccp.ReturnObject; if (isAllow) { if (MessageUtil.ShowYesNoAndQuestion("原记录" + processCodeToDesc(_processCode) + "之后的工序是否使用新的工艺?") == DialogResult.Yes) { isUseNewCraft = true; } } } else { MessageUtil.ShowError(ccp.ReturnInfo); return; } //CoreClientParam ccp = new CoreClientParam(); //ccp.ServerName = "com.steering.pss.plnsaleord.processOrder.CoreProcessOrder"; //ccp.MethodName = "getGetRate"; //ccp.ServerParams = new object[] { _processCode, _planGroupId, _initProcessWgt.ToString(), //_finishSumWgt.ToString(), beginProcEntity, addProcEntitys, addChangeEntitys }; //ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); //if (ccp.ReturnCode != -1) //{ ccp.ServerName = "com.steering.pss.plnsaleord.processOrder.CoreProcessOrder"; ccp.MethodName = "saveChangeProc"; ccp.ServerParams = new object[] { JSONFormat.Format(beginProcEntity), addChangeEntitys, _processCode, isUseNewCraft, _orderNoSeq, _orderSource }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { MessageUtil.ShowTips("下发成功!"); DoRefresDate(); } else { MessageUtil.ShowError("下发失败:" + ccp.ReturnInfo); return; } } /// /// 工序点代码转描述 /// /// /// public static string processCodeToDesc(string processCode) { string processDesc = ""; switch (processCode) { case "A": processDesc = "炼钢"; break; case "B": processDesc = "铸造"; break; case "C": processDesc = "锻造"; break; case "D": processDesc = "轧制"; break; case "E": processDesc = "镦拔扩"; break; case "F": processDesc = "热处理"; break; case "G": processDesc = "加工"; break; case "H": processDesc = "接箍加工"; break; } return processDesc; } } }