QcmJudgeLockCtrl.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Tool;
  3. using Core.StlMes.Client.Judge.Commons;
  4. using Core.StlMes.Client.Judge.Forms;
  5. using CoreFS.CA06;
  6. using Infragistics.Win;
  7. using Infragistics.Win.UltraWinGrid;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Windows.Forms;
  12. namespace Core.StlMes.Client.Judge.Controls
  13. {
  14. public sealed partial class QcmJudgeLockCtrl : UserControl
  15. {
  16. private readonly Dal _d;
  17. private readonly string _userId;
  18. public QcmJudgeLockCtrl(Control container, OpeBase ob, string userId)
  19. {
  20. InitializeComponent();
  21. _d = new Dal(ob);
  22. _userId = userId;
  23. container.Controls.Add(this);
  24. Dock = DockStyle.Fill;
  25. var lockFlagList = new ValueList();
  26. lockFlagList.ValueListItems.Add("0", "未锁定");
  27. lockFlagList.ValueListItems.Add("1", "已锁定");
  28. ultraGrid1.DisplayLayout.Bands[0].Columns["lockFlag"].ValueList = lockFlagList;
  29. }
  30. private string _judgeStoveNo = "";
  31. private string _orderMngNo = "";
  32. public void Query(string judgeStoveNo, string orderMngNo)
  33. {
  34. try
  35. {
  36. Cursor = Cursors.WaitCursor;
  37. _judgeStoveNo = judgeStoveNo;
  38. _orderMngNo = orderMngNo;
  39. var ccp = _d.Set("com.steering.pss.judge.Bll.BllQcmJudgeLock.query", judgeStoveNo,
  40. orderMngNo);
  41. if (ccp.ReturnInfo.ToString2() != "")
  42. {
  43. MessageUtil.ShowError(ccp.ReturnInfo.ToString2());
  44. return;
  45. }
  46. var dt = JsonHelper.toTable(ccp.ReturnObject.ToString2());
  47. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  48. foreach (var row in ultraGrid1.Rows)
  49. {
  50. row.Cells["lgLock"].Value = false;
  51. row.Cells["zgLock"].Value = false;
  52. row.Cells["dbkLock"].Value = false;
  53. row.Cells["rclLock"].Value = false;
  54. row.Cells["jgxLock"].Value = false;
  55. row.Cells["jgLock"].Value = false;
  56. row.Cells["zcLock"].Value = false;
  57. //在途工序之前的工序不能选择
  58. if (row.GetValue("processCode") == "D")
  59. {
  60. row.Cells["lgLock"].Value = DBNull.Value;
  61. row.Cells["lgLock"].Activation = Activation.ActivateOnly;
  62. }
  63. else if (row.GetValue("processCode") == "E")
  64. {
  65. row.Cells["lgLock"].Value = DBNull.Value;
  66. row.Cells["lgLock"].Activation = Activation.ActivateOnly;
  67. row.Cells["zgLock"].Value = DBNull.Value;
  68. row.Cells["zgLock"].Activation = Activation.ActivateOnly;
  69. }
  70. else if (row.GetValue("processCode") == "F")
  71. {
  72. row.Cells["lgLock"].Value = DBNull.Value;
  73. row.Cells["lgLock"].Activation = Activation.ActivateOnly;
  74. row.Cells["zgLock"].Value = DBNull.Value;
  75. row.Cells["zgLock"].Activation = Activation.ActivateOnly;
  76. row.Cells["dbkLock"].Value = DBNull.Value;
  77. row.Cells["dbkLock"].Activation = Activation.ActivateOnly;
  78. }
  79. else if (row.GetValue("processCode") == "G")
  80. {
  81. row.Cells["lgLock"].Value = DBNull.Value;
  82. row.Cells["lgLock"].Activation = Activation.ActivateOnly;
  83. row.Cells["zgLock"].Value = DBNull.Value;
  84. row.Cells["zgLock"].Activation = Activation.ActivateOnly;
  85. row.Cells["dbkLock"].Value = DBNull.Value;
  86. row.Cells["dbkLock"].Activation = Activation.ActivateOnly;
  87. row.Cells["rclLock"].Value = DBNull.Value;
  88. row.Cells["rclLock"].Activation = Activation.ActivateOnly;
  89. }
  90. else if (row.GetValue("processCode") == "H")
  91. {
  92. row.Cells["lgLock"].Value = DBNull.Value;
  93. row.Cells["lgLock"].Activation = Activation.ActivateOnly;
  94. row.Cells["zgLock"].Value = DBNull.Value;
  95. row.Cells["zgLock"].Activation = Activation.ActivateOnly;
  96. row.Cells["dbkLock"].Value = DBNull.Value;
  97. row.Cells["dbkLock"].Activation = Activation.ActivateOnly;
  98. row.Cells["rclLock"].Value = DBNull.Value;
  99. row.Cells["rclLock"].Activation = Activation.ActivateOnly;
  100. row.Cells["jgxLock"].Value = DBNull.Value;
  101. row.Cells["jgxLock"].Activation = Activation.ActivateOnly;
  102. }
  103. else if (row.GetValue("processCode") == "ZC")
  104. {
  105. row.Cells["lgLock"].Value = DBNull.Value;
  106. row.Cells["lgLock"].Activation = Activation.ActivateOnly;
  107. row.Cells["zgLock"].Value = DBNull.Value;
  108. row.Cells["zgLock"].Activation = Activation.ActivateOnly;
  109. row.Cells["dbkLock"].Value = DBNull.Value;
  110. row.Cells["dbkLock"].Activation = Activation.ActivateOnly;
  111. row.Cells["rclLock"].Value = DBNull.Value;
  112. row.Cells["rclLock"].Activation = Activation.ActivateOnly;
  113. row.Cells["jgxLock"].Value = DBNull.Value;
  114. row.Cells["jgxLock"].Activation = Activation.ActivateOnly;
  115. row.Cells["jgLock"].Value = DBNull.Value;
  116. row.Cells["jgLock"].Activation = Activation.ActivateOnly;
  117. }
  118. if (row.Cells["lockProcessCode"].Value.ToString() == "A")
  119. row.Cells["lgLock"].Value = true;
  120. else if (row.Cells["lockProcessCode"].Value.ToString() == "D")
  121. row.Cells["zgLock"].Value = true;
  122. else if (row.Cells["lockProcessCode"].Value.ToString() == "E")
  123. row.Cells["dbkLock"].Value = true;
  124. else if (row.Cells["lockProcessCode"].Value.ToString() == "F")
  125. row.Cells["rclLock"].Value = true;
  126. else if (row.Cells["lockProcessCode"].Value.ToString() == "G")
  127. row.Cells["jgxLock"].Value = true;
  128. else if (row.Cells["lockProcessCode"].Value.ToString() == "H")
  129. row.Cells["jgLock"].Value = true;
  130. else if (row.Cells["lockProcessCode"].Value.ToString() == "ZC") row.Cells["zcLock"].Value = true;
  131. row.Update();
  132. }
  133. GridHelper.RefreshAndAutoSize(ultraGrid1);
  134. }
  135. finally
  136. {
  137. Cursor = Cursors.Default;
  138. }
  139. }
  140. public void Lock()
  141. {
  142. var chkRows = ultraGrid1.Rows.Where(a => a.GetValue("chk") == "True");
  143. var ultraGridRows = chkRows.ToList();
  144. if (!ultraGridRows.Any())
  145. {
  146. MessageUtil.ShowWarning("请选择一行记录!");
  147. return;
  148. }
  149. var popup = new PopupSubmit("锁定原因", true, "请输入锁定原因");
  150. string lockReason;
  151. if (popup.ShowDialog() == DialogResult.Yes)
  152. {
  153. lockReason = popup.TxtAudit.Text.Trim();
  154. if (lockReason == "")
  155. {
  156. MessageUtil.ShowWarning("请选择一行记录!");
  157. return;
  158. }
  159. }
  160. else
  161. {
  162. return;
  163. }
  164. var jsons = new List<string>();
  165. var lockId = ultraGrid1.ActiveRow.GetValue("lockId");
  166. foreach (var row in ultraGridRows)
  167. {
  168. SetLockProcess(row);
  169. jsons.Add(JsonHelper.ToJson(row));
  170. }
  171. var ccp = _d.Set("com.steering.pss.judge.Bll.BllQcmJudgeLock.lock", jsons, lockReason, _userId);
  172. if (ccp.ReturnInfo.ToString2() != "")
  173. {
  174. MessageUtil.ShowWarning(ccp.ReturnInfo.ToString2());
  175. }
  176. else
  177. {
  178. MessageUtil.ShowTips("操作成功!");
  179. Relocate(lockId);
  180. }
  181. }
  182. private void Relocate(string lockId)
  183. {
  184. Query(_judgeStoveNo, _orderMngNo);
  185. var row = ultraGrid1.Rows.FirstOrDefault(a => a.GetValue("lockId") == lockId);
  186. if (row != null) row.Activate();
  187. }
  188. private void SetLockProcess(UltraGridRow row)
  189. {
  190. if (row.GetValue("lgLock") != "True" && row.GetValue("zgLock") != "True" &&
  191. row.GetValue("dbkLock") != "True"
  192. && row.GetValue("rclLock") != "True" && row.GetValue("jgxLock") != "True" &&
  193. row.GetValue("jgLock") != "True"
  194. && row.GetValue("zcLock") != "True")
  195. row.SetValue("lockProcessCode", row.GetValue("processCode"));
  196. else if (row.GetValue("lgLock") == "True")
  197. row.SetValue("lockProcessCode", "A");
  198. else if (row.GetValue("zgLock") == "True")
  199. row.SetValue("lockProcessCode", "D");
  200. else if (row.GetValue("dbkLock") == "True")
  201. row.SetValue("lockProcessCode", "E");
  202. else if (row.GetValue("rclLock") == "True")
  203. row.SetValue("lockProcessCode", "F");
  204. else if (row.GetValue("jgxLock") == "True")
  205. row.SetValue("lockProcessCode", "G");
  206. else if (row.GetValue("jgLock") == "True")
  207. row.SetValue("lockProcessCode", "H");
  208. else if (row.GetValue("zcLock") == "True") row.SetValue("lockProcessCode", "ZC");
  209. }
  210. public void Unlock()
  211. {
  212. var chkRows = ultraGrid1.Rows.Where(a => a.GetValue("chk") == "True");
  213. var ultraGridRows = chkRows.ToList();
  214. if (!ultraGridRows.Any())
  215. {
  216. MessageUtil.ShowWarning("请选择一行记录!");
  217. return;
  218. }
  219. if (MessageUtil.ShowYesNoAndQuestion("是否确认解锁?") == DialogResult.No) return;
  220. var jsons = new List<string>();
  221. var lockId = ultraGrid1.ActiveRow.GetValue("lockId");
  222. foreach (var row in ultraGridRows) jsons.Add(JsonHelper.ToJson(row));
  223. var ccp = _d.Set("com.steering.pss.judge.Bll.BllQcmJudgeLock.unlock", jsons, _userId);
  224. if (ccp.ReturnInfo.ToString2() != "")
  225. {
  226. MessageUtil.ShowWarning(ccp.ReturnInfo.ToString2());
  227. }
  228. else
  229. {
  230. MessageUtil.ShowTips("操作成功!");
  231. Relocate(lockId);
  232. }
  233. }
  234. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  235. {
  236. e.Cell.Row.Update();
  237. //string[] locks = new string[] { "lgLock", "zgLock", "dbkLock", "rclLock", "jgxLock", "jgLock", "zcLock" };
  238. //foreach (string strLock in locks)
  239. //{
  240. // if (strLock == e.Cell.Column.Key)
  241. // {
  242. // e.Cell.Row.Cells[strLock].Value = true;
  243. // }
  244. // else
  245. // {
  246. // e.Cell.Row.Cells[strLock].Value = false;
  247. // }
  248. //}
  249. }
  250. private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
  251. {
  252. }
  253. private void ultraGrid1_AfterCellUpdate(object sender, CellEventArgs e)
  254. {
  255. if (e.Cell.Column.Key.EndsWith("Lock") && e.Cell.Value.ToString2() == "True")
  256. {
  257. string[] locks = { "lgLock", "zgLock", "dbkLock", "rclLock", "jgxLock", "jgLock", "zcLock" };
  258. foreach (var strLock in locks)
  259. {
  260. if (strLock == e.Cell.Column.Key || e.Cell.Row.Cells[strLock].Value.ToString2() != "True") continue;
  261. e.Cell.Row.Cells[strLock].Value = false;
  262. }
  263. }
  264. e.Cell.Row.Update();
  265. }
  266. private void ultraGrid1_AfterHeaderCheckStateChanged(object sender,
  267. AfterHeaderCheckStateChangedEventArgs e)
  268. {
  269. _headerCheck = false;
  270. }
  271. private void ultraGrid1_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e)
  272. {
  273. if (_headerCheck && e.Cell.Value == DBNull.Value) e.Cancel = true;
  274. }
  275. private bool _headerCheck;
  276. private void ultraGrid1_BeforeHeaderCheckStateChanged(object sender, BeforeHeaderCheckStateChangedEventArgs e)
  277. {
  278. _headerCheck = true;
  279. }
  280. }
  281. }