PortMchBatchControl.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. using CCore.StlMes.Client.Mcp.Control;
  7. using Core.Mes.Client.Comm.Format;
  8. using Core.Mes.Client.Comm.Server;
  9. using Core.Mes.Client.Comm.Tool;
  10. using Core.StlMes.Client.Mcp.Control.Entity;
  11. using CoreFS.CA06;
  12. using Infragistics.Win;
  13. using Infragistics.Win.UltraWinGrid;
  14. using ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle;
  15. using ColumnStyle = Infragistics.Win.UltraWinGrid.ColumnStyle;
  16. using Core.Mes.Client.Comm.Control;
  17. using System.Collections;
  18. namespace Core.StlMes.Client.Mcp.Control.Common
  19. {
  20. public delegate void MchWasteChange();
  21. public partial class PortMchBatchControl : UserControl
  22. {
  23. public PortMchBatchControl()
  24. {
  25. InitializeComponent();
  26. EntityHelper.ShowGridCaption<PortMchBatchSampleResultEntity>(ultraGrid3.DisplayLayout.Bands[0]);
  27. commHelper.RefreshAndAutoSize(ultraGrid3);
  28. ShowTop = true;
  29. ShowSeq = false;
  30. }
  31. public MchWasteChange MchWasteChange = null;
  32. public void DisableFiltering()
  33. {
  34. //ultraGrid3.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
  35. ultraGrid3.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
  36. }
  37. public bool ShowTop
  38. {
  39. get { return ultraPanel9.Visible; }
  40. set { ultraPanel9.Visible = value; }
  41. }
  42. private bool _showSeq = false;
  43. public bool ShowSeq
  44. {
  45. get { return _showSeq; }
  46. set { _showSeq = value;
  47. ultraPanel3.Visible = _showSeq;
  48. ultraGrid3.DisplayLayout.Bands[0].Columns["BarCode"].CellActivation= _showSeq? Activation.AllowEdit : Activation.ActivateOnly;
  49. }
  50. }
  51. /// <summary>
  52. ///
  53. /// </summary>
  54. public bool GetAllRtdPort { get; set; }
  55. public bool CanFail
  56. {
  57. get
  58. {
  59. return !ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].Hidden;
  60. }
  61. set
  62. {
  63. ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].Hidden = !value;
  64. }
  65. }
  66. public void SetDeleteReason(string failCode)
  67. {
  68. var dt3 = ServerHelper.GetData("com.steering.mes.mcp.collarMaterial.ComBaseInfo.getBaseInfo",
  69. new object[] { failCode }, ob);
  70. reason.DataSource = dt3;
  71. reason.DisplayMember = "BASENAME";
  72. reason.ValueMember = "BASECODE";
  73. YdmBaseClass.SetComboItemHeight(reason);
  74. ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].EditorComponent = reason;
  75. ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].ButtonDisplayStyle = ButtonDisplayStyle.Always;
  76. ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].Style = ColumnStyle.DropDownList;
  77. ultraGrid3.DisplayLayout.Bands[0].Columns["MatStatus"].ButtonDisplayStyle = ButtonDisplayStyle.Always;
  78. }
  79. public bool ShowDelete { get; set; }
  80. public OpeBase ob { get; set; }
  81. private string heatPlanNo = "";
  82. private string batchNo = "";
  83. private string gx = "";
  84. public string userName {
  85. get;
  86. set; }
  87. public string Group { get; set; }
  88. public string Shift { get; set; }
  89. public List<PortMchBatchSampleResultEntity> Data
  90. {
  91. get
  92. {
  93. return portMchBatchSampleResultEntityBindingSource.DataSource as List<PortMchBatchSampleResultEntity>;
  94. }
  95. }
  96. private void Query()
  97. {
  98. Query(heatPlanNo, batchNo,gx);
  99. }
  100. public void Query(string HeatPlanNo, string BatchNo,string Gx,bool isD = false)
  101. {
  102. heatPlanNo = HeatPlanNo;
  103. batchNo = BatchNo;
  104. gx = Gx;
  105. List<PortMchBatchSampleResultEntity> list;
  106. if (GetAllRtdPort && !isD)
  107. {
  108. list = EntityHelper.GetData<PortMchBatchSampleResultEntity>(
  109. "com.steering.mes.mcp.common.PlanService.getQueryJGPortVrphotAll",
  110. new object[] {HeatPlanNo, BatchNo, ShowSeq}, ob);
  111. }
  112. else
  113. {
  114. if (HeatPlanNo.StartsWith("D")|| HeatPlanNo.StartsWith("E"))//镦拔扩查询
  115. {
  116. list = EntityHelper.GetData<PortMchBatchSampleResultEntity>(
  117. "com.steering.mes.mcp.common.PlanService.getQueryDBPortVrphot",
  118. new object[] { HeatPlanNo, BatchNo, ShowSeq }, ob);
  119. }
  120. else
  121. {
  122. list = EntityHelper.GetData<PortMchBatchSampleResultEntity>(
  123. "com.steering.mes.mcp.common.PlanService.getQueryJGPortVrphot",
  124. new object[] { HeatPlanNo, BatchNo, ShowSeq }, ob);
  125. }
  126. }
  127. portMchBatchSampleResultEntityBindingSource.DataSource = list;
  128. string info = String.Format("作业 {0} 支 ", list.Count );
  129. var Instore =
  130. list.Where(p => p.InstoreFlag == "1" || p.InstoreFlag == "已入库").ToList();
  131. if (Instore.Any())
  132. {
  133. info = info + String.Format(" 已入库 {0} 支 ", Instore.Count);
  134. }
  135. var Fail =
  136. list.Where(p => p.MatStatus == "10" || p.MatStatus == "40" || p.MatStatus == "剔除" || p.MatStatus == "委外废品").ToList();
  137. if (Fail.Any())
  138. {
  139. info = info + String.Format(" 废品 {0} 支 ", Fail.Count);
  140. }
  141. var Offline =
  142. list.Where(p => p.MatStatus == "20" || p.MatStatus == "待处理").ToList();
  143. if (Offline.Any())
  144. {
  145. info = info + String.Format(" 离线 {0} 支 ", Offline.Count);
  146. }
  147. var Other =
  148. list.Where(p => p.MatStatus == "30" || p.MatStatus == "另组炉").ToList();
  149. if (Other.Any())
  150. {
  151. info = info + String.Format(" 另组炉 {0} 支 ", Other.Count);
  152. }
  153. ultraGrid3.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = info;
  154. commHelper.RefreshAndAutoSize(ultraGrid3);
  155. ShowMsg();
  156. }
  157. private void officeNum_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  158. {
  159. FrmScrapMchNum FrmScrapMchNum = new FrmScrapMchNum(ob,heatPlanNo,batchNo,gx,userName,Shift,Group);
  160. FrmScrapMchNum.ShowDialog();
  161. if (FrmScrapMchNum.DialogResult == DialogResult.OK)
  162. Query();
  163. }
  164. private void ultraGrid3_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
  165. {
  166. PortMchBatchSampleResultEntity row = e.Row.ListObject as PortMchBatchSampleResultEntity;
  167. if (e.Row.Cells["MatStatus"].Text.Equals("剔除") || e.Row.Cells["MatStatus"].Text.Equals("委外废品"))
  168. e.Row.Cells["MatStatus"].Appearance.ForeColor = Color.Red;
  169. if (ShowSeq && row != null && row.TrFlag =="1")
  170. {
  171. e.Row.Appearance.BackColor = Color.LightGreen;
  172. }
  173. if (CanFail)
  174. {
  175. if (e.Row.Cells["MatStatus"].Text.Equals("合格") )
  176. {
  177. e.Row.Cells["MatStatus"].EditorComponent = utDelete;
  178. e.Row.Cells["MatStatus"].IgnoreRowColActivation = true;
  179. ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].CellActivation = Activation.AllowEdit;
  180. }
  181. if (e.Row.Cells["MatStatus"].Text.Equals("剔除") && gx ==(e.Row.Cells["OpProcessCode"].Value.ToString2()))
  182. {
  183. e.Row.Cells["MatStatus"].EditorComponent = utCancelDelete;
  184. e.Row.Cells["MatStatus"].IgnoreRowColActivation = true;
  185. }
  186. }
  187. }
  188. private void btnUp_Click(object sender, EventArgs e)
  189. {
  190. if (ultraGrid3.Selected.Rows.Count <= 0)
  191. {
  192. tipMessage.Show("请选择需要往上移动的数据", btnUp );
  193. return;
  194. }
  195. List<UltraGridRow> rows = ultraGrid3.Selected.Rows.OfType<UltraGridRow>()
  196. .OrderBy(p => p.Index).ToList();
  197. int Index = rows[0].Index;
  198. if (rows[0].Index <= Data.Count(p => p.TrFlag == "1"))
  199. {
  200. tipMessage.Show("无法再向上移动", btnUp);
  201. return;
  202. }
  203. List<PortMchBatchSampleResultEntity> data = rows
  204. .Select(p => p.ListObject as PortMchBatchSampleResultEntity).ToList();
  205. if (data.Any(p => p.TrFlag == "1"))
  206. {
  207. tipMessage.Show("无法移动已匹配的管号", btnUp);
  208. return;
  209. }
  210. if (data.Any(p => p.MatStatus == "10" || p.MatStatus == "40" || p.MatStatus == "剔除" || p.MatStatus == "委外废品"))
  211. {
  212. tipMessage.Show("无法移动标废的管号", btnUp);
  213. return;
  214. }
  215. for (int i = 0; i < rows.Count; i++)
  216. {
  217. ultraGrid3.Rows.Move(rows[i], Index-1 + i);
  218. }
  219. }
  220. private void btnDown_Click(object sender, EventArgs e)
  221. {
  222. if (ultraGrid3.Selected.Rows.Count <= 0)
  223. {
  224. tipMessage.Show("请选择需要往上移动的数据", btnDown);
  225. return;
  226. }
  227. List<UltraGridRow> rows = ultraGrid3.Selected.Rows.OfType<UltraGridRow>()
  228. .OrderBy(p => p.Index).ToList();
  229. int Index = rows[rows.Count-1].Index;
  230. if (rows[0].Index >= Data.Count-1)
  231. {
  232. tipMessage.Show("无法再向下移动", btnDown);
  233. return;
  234. }
  235. List<PortMchBatchSampleResultEntity> data = rows
  236. .Select(p => p.ListObject as PortMchBatchSampleResultEntity).ToList();
  237. if (data.Any(p => p.TrFlag == "1"))
  238. {
  239. tipMessage.Show("无法移动已匹配的管号", btnDown);
  240. return;
  241. }
  242. for (int i = 0; i < rows.Count; i++)
  243. {
  244. ultraGrid3.Rows.Move(rows[i], Index +1);
  245. }
  246. }
  247. private void ultraGrid3_MouseDown(object sender, MouseEventArgs e)
  248. {
  249. if (e.Button == MouseButtons.Right)
  250. {
  251. List<UltraGridRow> rows = ultraGrid3.Selected.Rows.OfType<UltraGridRow>()
  252. .OrderBy(p => p.Index).ToList();
  253. //移动行
  254. if (rows.Count <= 0)
  255. {
  256. return;
  257. }
  258. //定位行
  259. UIElement myUIElement = ultraGrid3.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));
  260. if(myUIElement==null) return;
  261. UltraGridCell myCell = (UltraGridCell)myUIElement.GetContext(typeof(UltraGridCell));
  262. if (myCell == null) return;
  263. UltraGridRow ugr = myCell.Row;
  264. if (ugr == null) { return; }
  265. int Index = ugr.Index;
  266. int cout = 0;
  267. for (int i = 0; i < rows.Count; i++)
  268. {
  269. int moveIndex = Index;
  270. if (Index < rows[i].Index) moveIndex = Index + cout++;
  271. ultraGrid3.Rows.Move(rows[i], moveIndex);
  272. }
  273. }
  274. }
  275. private void utDelete_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  276. {
  277. try
  278. {
  279. if (ultraGrid3.ActiveRow.Cells["DeleteReason"].Value.ToString2()== "")
  280. {
  281. MessageBox.Show("请选择废品原因");
  282. return;
  283. }
  284. ServerHelper.SetData("com.steering.mes.mcp.Mch.FrmMchBugD.AddMchWaste",
  285. new object[]
  286. {
  287. heatPlanNo,
  288. gx,
  289. ultraGrid3.ActiveRow.Cells["PlineCode"].Text.ToString2(),
  290. userName,
  291. ultraGrid3.ActiveRow.Cells["MatNo"].Text.ToString2(),
  292. new List<MchBugDEntity>(){new MchBugDEntity()
  293. {
  294. MatNo = ultraGrid3.ActiveRow.Cells["MatNo"].Text.ToString2(),
  295. BatchNo = ultraGrid3.ActiveRow.Cells["PhyBatchNo"].Text,
  296. FailTypeCode = ultraGrid3.ActiveRow.Cells["DeleteReason"].Value.ToString2(),
  297. FailNum = 1,
  298. FailTypeName = ultraGrid3.ActiveRow.Cells["DeleteReason"].Text.ToString2(),
  299. FailWt = decimal.Parse(ultraGrid3.ActiveRow.Cells["ActWeight"].Value.ToString3())
  300. }}.Select(JSONFormat.Format).ToList()
  301. },
  302. ob);
  303. MessageBox.Show("剔除成功");
  304. var handler = MchWasteChange;
  305. if (handler != null) handler();
  306. }
  307. catch (Exception)
  308. {
  309. }
  310. }
  311. private void utCancelDelete_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  312. {
  313. try
  314. {
  315. ServerHelper.SetData("com.steering.mes.mcp.Mch.FrmMchBugD.DeleteMchWaste",
  316. new object[]
  317. {
  318. heatPlanNo,
  319. ultraGrid3.ActiveRow.Cells["MatNo"].Text.ToString2(),
  320. gx,
  321. ultraGrid3.ActiveRow.Cells["PlineCode"].Text.ToString2(),
  322. },
  323. ob);
  324. MessageBox.Show("撤销成功");
  325. var handler = MchWasteChange;
  326. if (handler != null) handler();
  327. }
  328. catch (Exception)
  329. {
  330. }
  331. }
  332. private void btnSave_Click(object sender, EventArgs e)
  333. {
  334. ultraGrid3.UpdateData();
  335. var check = Data.Where(p => !string.IsNullOrWhiteSpace(p.BarCode)).GroupBy(p => p.BarCode).ToList();
  336. if (check.Any(p => p.Count() > 1))
  337. {
  338. string barcode = check.Where(p => p.Count() > 1).Select(p=>p.Key).Aggregate((a, b) => a + " " + b);
  339. MessageBox.Show("逐支跟踪号 " + barcode + "重复");
  340. return;
  341. }
  342. var Re = ServerHelper.SetDataReturnObj("com.steering.mes.mcp.common.PlanService.SaveBarcode",
  343. new object[] {Data.Select(JSONFormat.Format).ToList()}, ob);
  344. if (Re.ToString2() == "修改成功!")
  345. {
  346. MessageBox.Show("保存成功");
  347. Query();
  348. }
  349. }
  350. private void ultraGrid3_CellChange(object sender, CellEventArgs e)
  351. {
  352. if (e.Cell.Column.Key == "BarCode")
  353. {
  354. var check =
  355. ultraGrid3.Rows.Where(
  356. p =>
  357. p.Cells["MatNo"].Text != e.Cell.Row.Cells["MatNo"].Value.ToString2() &&
  358. !string.IsNullOrEmpty(p.Cells["BarCode"].Text) &&
  359. !string.IsNullOrEmpty(e.Cell.Text) &&
  360. p.Cells["BarCode"].Text == e.Cell.Text
  361. ).ToList();
  362. if (check.Any())
  363. {
  364. e.Cell.Appearance.BackColor = Color.Red;
  365. /* tipMessage.Show(
  366. @"
  367. 管号重复
  368. ", ultraGrid3);*/
  369. // e.Cell.EditorComponent = uteBarcode;
  370. }
  371. else
  372. {
  373. e.Cell.Appearance.ResetBackColor();
  374. e.Cell.EditorComponent = null;
  375. tipMessage.RemoveAll();
  376. }
  377. ShowMsg();
  378. }
  379. }
  380. private void ShowMsg()
  381. {
  382. try
  383. {
  384. var list = ultraGrid3.Rows.Where(p =>
  385. {
  386. int num = 0;
  387. return int.TryParse(p.Cells["BarCode"].Text.ToString(), out num);
  388. }).Select(p => int.Parse(p.Cells["BarCode"].Text.ToString())).ToList();
  389. if (list.Any())
  390. {
  391. var list2 = Enumerable.Range(list.Min(), list.Max()).ToList().Except(list
  392. ).ToList();
  393. lblMsg.Text = "(" + list.Min() + "-" + list.Max() + " )未录入:" + string.Join(",", list2.ToArray());
  394. }
  395. else
  396. {
  397. lblMsg.Text = "";
  398. }
  399. }
  400. catch (Exception)
  401. {
  402. lblMsg.Text = "";
  403. }
  404. }
  405. private void btnExport_Click(object sender, EventArgs e)
  406. {
  407. GridHelper.ulGridToExcel(ultraGrid3, "管号队列");
  408. }
  409. private void button1_Click(object sender, EventArgs e)
  410. {
  411. IQueryable<UltraGridRow> checkRows = this.ultraGrid3.Rows.AsQueryable().Where(" CHK = 'True'");
  412. if (checkRows.Count() == 0)
  413. {
  414. MessageUtil.ShowTips("请勾选要保存的数据");
  415. return;
  416. }
  417. string remark = remarkTxt.Value.ToString2();
  418. ArrayList parmList = new ArrayList();
  419. foreach (UltraGridRow row in checkRows)
  420. {
  421. PortMchBatchSampleResultEntity entity = (PortMchBatchSampleResultEntity)row.ListObject;
  422. if (entity.InstoreFlag.Equals("已入库"))
  423. {
  424. MessageUtil.ShowTips("已入库,无法保存备注!");
  425. return;
  426. }
  427. string matEntity = JSONFormat.Format(entity);
  428. parmList.Add(matEntity);
  429. }
  430. var Re = ServerHelper.SetDataReturnObj("com.steering.mes.mcp.common.PlanService.SaveRemark",
  431. new object[] { parmList, remark }, ob);
  432. if (Re.ToString2() == "修改成功!")
  433. {
  434. MessageBox.Show("保存成功");
  435. Query();
  436. }
  437. }
  438. }
  439. }