using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Judge.Commons; using Core.StlMes.Client.Judge.Forms; using CoreFS.CA06; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Core.StlMes.Client.Judge.Controls { public sealed partial class QcmJudgeLockCtrl : UserControl { private readonly Dal _d; private readonly string _userId; public QcmJudgeLockCtrl(Control container, OpeBase ob, string userId) { InitializeComponent(); _d = new Dal(ob); _userId = userId; container.Controls.Add(this); Dock = DockStyle.Fill; var lockFlagList = new ValueList(); lockFlagList.ValueListItems.Add("0", "未锁定"); lockFlagList.ValueListItems.Add("1", "已锁定"); ultraGrid1.DisplayLayout.Bands[0].Columns["lockFlag"].ValueList = lockFlagList; } private string _judgeStoveNo = ""; private string _orderMngNo = ""; public void Query(string judgeStoveNo, string orderMngNo) { try { Cursor = Cursors.WaitCursor; _judgeStoveNo = judgeStoveNo; _orderMngNo = orderMngNo; var ccp = _d.Set("com.steering.pss.judge.Bll.BllQcmJudgeLock.query", judgeStoveNo, orderMngNo); if (ccp.ReturnInfo.ToString2() != "") { MessageUtil.ShowError(ccp.ReturnInfo.ToString2()); return; } var dt = JsonHelper.toTable(ccp.ReturnObject.ToString2()); GridHelper.CopyDataToDatatable(dt, dataTable1, true); foreach (var row in ultraGrid1.Rows) { row.Cells["lgLock"].Value = false; row.Cells["zgLock"].Value = false; row.Cells["dbkLock"].Value = false; row.Cells["rclLock"].Value = false; row.Cells["jgxLock"].Value = false; row.Cells["jgLock"].Value = false; row.Cells["zcLock"].Value = false; //在途工序之前的工序不能选择 if (row.GetValue("processCode") == "D") { row.Cells["lgLock"].Value = DBNull.Value; row.Cells["lgLock"].Activation = Activation.ActivateOnly; } else if (row.GetValue("processCode") == "E") { row.Cells["lgLock"].Value = DBNull.Value; row.Cells["lgLock"].Activation = Activation.ActivateOnly; row.Cells["zgLock"].Value = DBNull.Value; row.Cells["zgLock"].Activation = Activation.ActivateOnly; } else if (row.GetValue("processCode") == "F") { row.Cells["lgLock"].Value = DBNull.Value; row.Cells["lgLock"].Activation = Activation.ActivateOnly; row.Cells["zgLock"].Value = DBNull.Value; row.Cells["zgLock"].Activation = Activation.ActivateOnly; row.Cells["dbkLock"].Value = DBNull.Value; row.Cells["dbkLock"].Activation = Activation.ActivateOnly; } else if (row.GetValue("processCode") == "G") { row.Cells["lgLock"].Value = DBNull.Value; row.Cells["lgLock"].Activation = Activation.ActivateOnly; row.Cells["zgLock"].Value = DBNull.Value; row.Cells["zgLock"].Activation = Activation.ActivateOnly; row.Cells["dbkLock"].Value = DBNull.Value; row.Cells["dbkLock"].Activation = Activation.ActivateOnly; row.Cells["rclLock"].Value = DBNull.Value; row.Cells["rclLock"].Activation = Activation.ActivateOnly; } else if (row.GetValue("processCode") == "H") { row.Cells["lgLock"].Value = DBNull.Value; row.Cells["lgLock"].Activation = Activation.ActivateOnly; row.Cells["zgLock"].Value = DBNull.Value; row.Cells["zgLock"].Activation = Activation.ActivateOnly; row.Cells["dbkLock"].Value = DBNull.Value; row.Cells["dbkLock"].Activation = Activation.ActivateOnly; row.Cells["rclLock"].Value = DBNull.Value; row.Cells["rclLock"].Activation = Activation.ActivateOnly; row.Cells["jgxLock"].Value = DBNull.Value; row.Cells["jgxLock"].Activation = Activation.ActivateOnly; } else if (row.GetValue("processCode") == "ZC") { row.Cells["lgLock"].Value = DBNull.Value; row.Cells["lgLock"].Activation = Activation.ActivateOnly; row.Cells["zgLock"].Value = DBNull.Value; row.Cells["zgLock"].Activation = Activation.ActivateOnly; row.Cells["dbkLock"].Value = DBNull.Value; row.Cells["dbkLock"].Activation = Activation.ActivateOnly; row.Cells["rclLock"].Value = DBNull.Value; row.Cells["rclLock"].Activation = Activation.ActivateOnly; row.Cells["jgxLock"].Value = DBNull.Value; row.Cells["jgxLock"].Activation = Activation.ActivateOnly; row.Cells["jgLock"].Value = DBNull.Value; row.Cells["jgLock"].Activation = Activation.ActivateOnly; } if (row.Cells["lockProcessCode"].Value.ToString() == "A") row.Cells["lgLock"].Value = true; else if (row.Cells["lockProcessCode"].Value.ToString() == "D") row.Cells["zgLock"].Value = true; else if (row.Cells["lockProcessCode"].Value.ToString() == "E") row.Cells["dbkLock"].Value = true; else if (row.Cells["lockProcessCode"].Value.ToString() == "F") row.Cells["rclLock"].Value = true; else if (row.Cells["lockProcessCode"].Value.ToString() == "G") row.Cells["jgxLock"].Value = true; else if (row.Cells["lockProcessCode"].Value.ToString() == "H") row.Cells["jgLock"].Value = true; else if (row.Cells["lockProcessCode"].Value.ToString() == "ZC") row.Cells["zcLock"].Value = true; row.Update(); } GridHelper.RefreshAndAutoSize(ultraGrid1); } finally { Cursor = Cursors.Default; } } public void Lock() { var chkRows = ultraGrid1.Rows.Where(a => a.GetValue("chk") == "True"); var ultraGridRows = chkRows.ToList(); if (!ultraGridRows.Any()) { MessageUtil.ShowWarning("请选择一行记录!"); return; } var popup = new PopupSubmit("锁定原因", true, "请输入锁定原因"); string lockReason; if (popup.ShowDialog() == DialogResult.Yes) { lockReason = popup.TxtAudit.Text.Trim(); if (lockReason == "") { MessageUtil.ShowWarning("请选择一行记录!"); return; } } else { return; } var jsons = new List(); var lockId = ultraGrid1.ActiveRow.GetValue("lockId"); foreach (var row in ultraGridRows) { SetLockProcess(row); jsons.Add(JsonHelper.ToJson(row)); } var ccp = _d.Set("com.steering.pss.judge.Bll.BllQcmJudgeLock.lock", jsons, lockReason, _userId); if (ccp.ReturnInfo.ToString2() != "") { MessageUtil.ShowWarning(ccp.ReturnInfo.ToString2()); } else { MessageUtil.ShowTips("操作成功!"); Relocate(lockId); } } private void Relocate(string lockId) { Query(_judgeStoveNo, _orderMngNo); var row = ultraGrid1.Rows.FirstOrDefault(a => a.GetValue("lockId") == lockId); if (row != null) row.Activate(); } private void SetLockProcess(UltraGridRow row) { if (row.GetValue("lgLock") != "True" && row.GetValue("zgLock") != "True" && row.GetValue("dbkLock") != "True" && row.GetValue("rclLock") != "True" && row.GetValue("jgxLock") != "True" && row.GetValue("jgLock") != "True" && row.GetValue("zcLock") != "True") row.SetValue("lockProcessCode", row.GetValue("processCode")); else if (row.GetValue("lgLock") == "True") row.SetValue("lockProcessCode", "A"); else if (row.GetValue("zgLock") == "True") row.SetValue("lockProcessCode", "D"); else if (row.GetValue("dbkLock") == "True") row.SetValue("lockProcessCode", "E"); else if (row.GetValue("rclLock") == "True") row.SetValue("lockProcessCode", "F"); else if (row.GetValue("jgxLock") == "True") row.SetValue("lockProcessCode", "G"); else if (row.GetValue("jgLock") == "True") row.SetValue("lockProcessCode", "H"); else if (row.GetValue("zcLock") == "True") row.SetValue("lockProcessCode", "ZC"); } public void Unlock() { var chkRows = ultraGrid1.Rows.Where(a => a.GetValue("chk") == "True"); var ultraGridRows = chkRows.ToList(); if (!ultraGridRows.Any()) { MessageUtil.ShowWarning("请选择一行记录!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认解锁?") == DialogResult.No) return; var jsons = new List(); var lockId = ultraGrid1.ActiveRow.GetValue("lockId"); foreach (var row in ultraGridRows) jsons.Add(JsonHelper.ToJson(row)); var ccp = _d.Set("com.steering.pss.judge.Bll.BllQcmJudgeLock.unlock", jsons, _userId); if (ccp.ReturnInfo.ToString2() != "") { MessageUtil.ShowWarning(ccp.ReturnInfo.ToString2()); } else { MessageUtil.ShowTips("操作成功!"); Relocate(lockId); } } private void ultraGrid1_CellChange(object sender, CellEventArgs e) { e.Cell.Row.Update(); //string[] locks = new string[] { "lgLock", "zgLock", "dbkLock", "rclLock", "jgxLock", "jgLock", "zcLock" }; //foreach (string strLock in locks) //{ // if (strLock == e.Cell.Column.Key) // { // e.Cell.Row.Cells[strLock].Value = true; // } // else // { // e.Cell.Row.Cells[strLock].Value = false; // } //} } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { } private void ultraGrid1_AfterCellUpdate(object sender, CellEventArgs e) { if (e.Cell.Column.Key.EndsWith("Lock") && e.Cell.Value.ToString2() == "True") { string[] locks = { "lgLock", "zgLock", "dbkLock", "rclLock", "jgxLock", "jgLock", "zcLock" }; foreach (var strLock in locks) { if (strLock == e.Cell.Column.Key || e.Cell.Row.Cells[strLock].Value.ToString2() != "True") continue; e.Cell.Row.Cells[strLock].Value = false; } } e.Cell.Row.Update(); } private void ultraGrid1_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e) { _headerCheck = false; } private void ultraGrid1_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e) { if (_headerCheck && e.Cell.Value == DBNull.Value) e.Cancel = true; } private bool _headerCheck; private void ultraGrid1_BeforeHeaderCheckStateChanged(object sender, BeforeHeaderCheckStateChangedEventArgs e) { _headerCheck = true; } } }