FinalCheckControl.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Windows.Forms;
  7. using System.Windows.Input;
  8. using Core.Mes.Client.Comm.Server;
  9. using Core.Mes.Client.Comm.Tool;
  10. using Core.StlMes.Client.Mcp.Control.Common;
  11. using Core.StlMes.Client.Mcp.Control.Entity;
  12. using CoreFS.CA06;
  13. using Infragistics.Win;
  14. using Infragistics.Win.UltraWinGrid;
  15. namespace Core.StlMes.Client.Mcp.Control.Machining
  16. {
  17. public partial class FinalCheckControl : UserControl
  18. {
  19. protected List<HttSignatureEntity> Names = new List<HttSignatureEntity>();
  20. protected string _plineCode = "";
  21. private bool isMeasureData = false;
  22. public FinalCheckControl()
  23. {
  24. InitializeComponent();
  25. EntityHelper.ShowGridCaption<PortMchBatchSampleResultEntity>(ultraGrid2.DisplayLayout.Bands[0]);
  26. EntityHelper.ShowGridCaption<MchFinalCheckTotal>(ultraGrid1.DisplayLayout.Bands[0]);
  27. EntityHelper.ShowGridCaption<MchFinalCheckResultDEntity>(ultraGrid1.DisplayLayout.Bands[1]);
  28. commHelper.RefreshAndAutoSizeExceptColumns(ultraGrid2);
  29. //commHelper.RefreshAndAutoSizeExceptColumns(ultraGrid1, "UnPass");
  30. var list = new ValueList();
  31. list.ValueListItems.Add(new ValueListItem("0", "合格"));
  32. list.ValueListItems.Add(new ValueListItem("1", "不合"));
  33. list.ValueListItems.Add(new ValueListItem("2", "废品"));
  34. ultraGrid1.DisplayLayout.Bands[0].Columns["Station"].ValueList = list;
  35. }
  36. private OpeBase ob;
  37. private DataTable dt;
  38. private DataTable dtReason;
  39. private DataTable dtTreat;
  40. private string BatchNo = "";
  41. public void Init(OpeBase _ob)
  42. {
  43. ultraGrid1.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
  44. ultraGrid1.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
  45. ultraGrid2.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
  46. ultraGrid2.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
  47. ob = _ob;
  48. dt = ServerHelper.GetData("com.steering.mes.mcp.common.PlanService.getBaseInfoSingle",
  49. new object[] { "702101" }, ob);
  50. /* dtReason = ServerHelper.GetData("com.steering.mes.mcp.common.PlanService.getBaseInfo",
  51. new object[] { "702101" }, ob);*/
  52. dtTreat = ServerHelper.GetData("com.steering.mes.mcp.common.PlanService.getBaseInfo",
  53. new object[] { "702103" }, ob);
  54. var list = new ValueList();
  55. for (int i = 0; i < dtTreat.Rows.Count; i++)
  56. {
  57. list.ValueListItems.Add(new ValueListItem(dtTreat.Rows[i]["BASECODE"].ToString2(), dtTreat.Rows[i]["BASENAME"].ToString2()));
  58. }
  59. ultraGrid1.DisplayLayout.Bands[0].Columns["TreatmentCode"].ValueList = list;
  60. ultraGrid2.DisplayLayout.Bands[0].Columns["PrcTechnologyPath"].Header.Caption = "原管号";
  61. }
  62. private List<PortMchBatchSampleResultEntity> _portHttBatchSampleResultEntitys;
  63. public List<PortMchBatchSampleResultEntity> ProMchPort
  64. {
  65. get
  66. {
  67. return portMchBatchSampleResultEntityBindingSource.DataSource as List<PortMchBatchSampleResultEntity>;
  68. }
  69. }
  70. /// <summary>
  71. /// 废品
  72. /// </summary>
  73. public List<MchBugDEntity> ScrappedList { get; protected set; }
  74. public List<MchFinalCheckTotal> Detail { get; private set; }
  75. private MchFinalCheckResultEntity Data;
  76. public MchFinalCheckResultEntity GetData()
  77. {
  78. if(Data==null) Data=new MchFinalCheckResultEntity();
  79. Data.ProNum = ProMchPort.Count;
  80. Data.ProWt = ProMchPort.Sum(p => p.ActWeight);
  81. Data.CheckNum = Detail.Select(p=>p.MatNo).Distinct().Count();
  82. Data.CheckWt = ProMchPort.Where(p => Detail.Any(q=>q.MatNo==p.MatNo)).Sum(p => p.ActWeight);
  83. Data.ProShift = uceBc.Value.ToString2();
  84. Data.ProGroup = uceBz.Value.ToString2();
  85. Data.ProTime = udeProData.Value.ToString2();
  86. Data.ProUser = txtUserName.Text;
  87. Data.UnqualifiedNum = Detail.Where(p => p.Station == "1").Select(p => p.MatNo).Distinct().Count();
  88. Data.UnqualifiedWt = ProMchPort.Where(p => Detail.Any(q => q.MatNo == p.MatNo && q.Station == "1")).Sum(p => p.ActWeight);
  89. Data.FailNum = Detail.Where(p => p.Station == "2").Select(p => p.MatNo).Distinct().Count();
  90. Data.FailWt = ProMchPort.Where(p => Detail.Any(q => q.MatNo == p.MatNo && q.Station == "2")).Sum(p => p.ActWeight);
  91. Data.QualifiedNum = Data.CheckNum - Data.UnqualifiedNum;
  92. Data.QualifiedWt = Data.CheckWt - Data.UnqualifiedWt;
  93. Data.ResultType = "0";
  94. return Data;
  95. }
  96. public List<MchBugDEntity> GetFailList()
  97. {
  98. List<MchBugDEntity> fail = new List<MchBugDEntity>();
  99. Detail.Where(p => p.Station == "2").GroupBy(p=>p.MatNo).ToList().ForEach(p =>
  100. {
  101. fail.Add(new MchBugDEntity()
  102. {
  103. BatchNo = Data.BatchNo,
  104. FailNum = 1,
  105. FailWt = ProMchPort.First(q => q.MatNo==p.Key).ActWeight,
  106. FailSort = "10",
  107. FailTypeCode = p.First().UnPassData[0].UnpassCode,
  108. FailTypeName = p.First().UnPassData[0].UnpassName,
  109. MatNo = p.Key
  110. });
  111. });
  112. fail= fail.GroupBy(p=>new {p.BatchNo,p.FailSort, p.FailTypeCode, p.FailTypeName}).Select(p=>new MchBugDEntity()
  113. {
  114. BatchNo = p.Key.BatchNo,
  115. FailNum = p.Sum(q=>q.FailNum),
  116. FailWt = p.Sum(q=>q.FailWt),
  117. FailSort = p.Key.FailSort,
  118. FailTypeCode = p.Key.FailTypeCode,
  119. FailTypeName = p.Key.FailTypeName,
  120. MatNo = p.Select(q=>q.MatNo).Aggregate((a,b)=>(a==""?"": a + ",") + b )
  121. }).ToList();
  122. return fail;
  123. }
  124. public void SetValue(MchFinalCheckResultEntity value, List<PortMchBatchSampleResultEntity> port)
  125. {
  126. Data = value;
  127. isMeasureData = port.Any(p => p.MeasuringSeq != null);
  128. _portHttBatchSampleResultEntitys = isMeasureData ?
  129. port.Where(p => (p.MatStatus == "合格" || p.MatStatus == "待处理") && p.MeasuringSeq != null && (p.IsFinalcheck == "" || p.IsFinalcheck == "0")).OrderBy(p => p.MeasuringSeq).ToList() :
  130. port.Where(p => (p.MatStatus == "合格" || p.MatStatus == "待处理") && (p.IsFinalcheck == "" || p.IsFinalcheck == "0")).OrderBy(p => p.MatNo).ToList();
  131. Data.ProNum = _portHttBatchSampleResultEntitys.Count;
  132. if (isMeasureData)
  133. {
  134. ultraGrid2.DisplayLayout.Bands[0].Columns["MatNo"].Hidden = true;
  135. ultraGrid2.DisplayLayout.Bands[0].Columns["PrcTechnologyPath"].Hidden = false;
  136. ultraGrid2.DisplayLayout.Bands[0].Columns["MeasuringSeq"].Hidden = false;
  137. ultraGrid1.DisplayLayout.Bands[0].Columns["MatNo"].Hidden = true;
  138. ultraGrid1.DisplayLayout.Bands[0].Columns["MeasuringSeq"].Hidden = false;
  139. }
  140. else
  141. {
  142. ultraGrid2.DisplayLayout.Bands[0].Columns["MatNo"].Hidden = false;
  143. ultraGrid2.DisplayLayout.Bands[0].Columns["PrcTechnologyPath"].Hidden = true;
  144. ultraGrid2.DisplayLayout.Bands[0].Columns["MeasuringSeq"].Hidden = true;
  145. ultraGrid1.DisplayLayout.Bands[0].Columns["MatNo"].Hidden = false;
  146. ultraGrid1.DisplayLayout.Bands[0].Columns["MeasuringSeq"].Hidden = true;
  147. }
  148. udeProData.Value = DateTime.Now;
  149. portMchBatchSampleResultEntityBindingSource.DataSource = _portHttBatchSampleResultEntitys;
  150. txtProNum.MaxValue = _portHttBatchSampleResultEntitys.Count;
  151. txtProNum.Text = Data.ProNum.ToString3();
  152. txtUserName.Text = Data.ProUser;
  153. uceBc.Value = Data.ProShift;
  154. uceBz.Value = Data.ProGroup;
  155. // ultraGrid2.DisplayLayout.Bands[0].Columns["BarCode"].Hidden = port.All(p => p.BarCode == "");
  156. Detail = new List<MchFinalCheckTotal>();
  157. mchFinalCheckTotalBindingSource.DataSource = Detail;
  158. commHelper.RefreshAndAutoSizeExceptColumns(ultraGrid2);
  159. ultraGrid2.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + Data.ProNum + "支";
  160. ultraGrid1.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + Data.ProNum + "支 " + "抽检 0支";
  161. ultraGrid1.DisplayLayout.Bands[0].Summaries[1].DisplayFormat = "抽检率 0%";
  162. txtStart.Text =isMeasureData? port.Min(p => p.MeasuringSeq).ToString3():"1";
  163. txtEnd.Text = isMeasureData ? port.Max(p => p.MeasuringSeq).ToString3() : "1000";
  164. if (_plineCode != value.PlineCode)
  165. {
  166. Names = EntityHelper.GetData<HttSignatureEntity>(
  167. "com.steering.mes.mcp.heatTreatment.FrmHttCrackDetectResult.getHttSign",
  168. new object[] { value.PlineCode, "12" }, ob);
  169. txtUserName.DisplayMember = "UserName";
  170. txtUserName.ValueMember = "UserName";
  171. _plineCode = value.PlineCode;
  172. txtUserName.DataSource = Names;
  173. }
  174. }
  175. private void ultraGrid2_CellChange(object sender, CellEventArgs e)
  176. {
  177. PortMchBatchSampleResultEntity entity =
  178. ultraGrid2.ActiveRow.ListObject as PortMchBatchSampleResultEntity;
  179. if (e.Cell.Column.Key == "Check")
  180. {
  181. ultraGrid2.UpdateData();
  182. if ((bool) e.Cell.Value && dt != null)
  183. {
  184. foreach (DataRow t in dt.Rows)
  185. {
  186. Detail.Add(new MchFinalCheckTotal()
  187. {
  188. MatNo = entity.MatNo,
  189. BarCode = entity.BarCode,
  190. MeasuringSeq = entity.MeasuringSeq,
  191. PositionCode = t["BASECODE"].ToString2(),
  192. PositionName = t["BASENAME"].ToString2(),
  193. Station = "0",
  194. UnPassData = new List<MchFinalCheckResultDEntity>()
  195. });
  196. }
  197. }
  198. else
  199. {
  200. Detail.Where(p=>p.MatNo==entity.MatNo).ToList().ForEach(p=>Detail.Remove(p));
  201. }
  202. Detail = Detail.OrderBy(p => p.MeasuringSeq).ThenBy(p => p.MatNo).ThenBy(p => p.PositionCode).ToList();
  203. // commHelper.RefreshAndAutoSizeExceptColumns(ultraGrid1, "Unpass");
  204. }
  205. int C = Detail.Select(p => p.MatNo).Distinct().Count();
  206. int F = int.Parse(Data.ProNum.ToString3());
  207. mchFinalCheckTotalBindingSource.DataSource = Detail;
  208. ultraGrid1.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + F + "支 " + "抽检 " + C + "支";
  209. ultraGrid1.DisplayLayout.Bands[0].Summaries[1].DisplayFormat = "抽检率" + (C * 100d / F).ToString("0.00") + "%";
  210. }
  211. private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
  212. {
  213. if (e.Row.Cells["PositionCode"].Value.ToString2() != "")
  214. {
  215. /*var list = new ValueList();
  216. dtReason.AsEnumerable().Where(p => p["BASECODE"].ToString2().StartsWith(e.Row.Cells["PositionCode"].Value.ToString2())).ToList().ForEach(
  217. p=> { list.ValueListItems.Add(new ValueListItem(p["BASECODE"].ToString2(), p["BASENAME"].ToString2()));} );
  218. e.Row.Cells["UnpassCode"].ValueList = list;*/
  219. // ultraGrid1.DisplayLayout.Bands[0].Columns["UnpassName"].PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand);
  220. }
  221. /* if (e.Row.Cells["Station"].Value.ToString2() == "1")
  222. {
  223. e.Row.Cells["Station"].Appearance.BackColor= Color.Red;
  224. }
  225. else if (e.Row.Cells["Station"].Value.ToString2() == "2")
  226. {
  227. e.Row.Cells["Station"].Appearance.BackColor = Color.Red;
  228. }
  229. else
  230. {
  231. e.Row.Cells["Station"].Appearance.ResetBackColor();
  232. }*/
  233. }
  234. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  235. {
  236. /* if (e.Cell.Column.Key == "UnPass")
  237. {
  238. ultraGrid1.UpdateData();
  239. MchFinalCheckTotal entity = e.Cell.Row.ListObject as MchFinalCheckTotal;
  240. if (entity.UnPassData!=null && entity.UnPassData.Any())
  241. {
  242. e.Cell.Row.Cells["Station"].Value = entity.UnPassData.Any(p => p.TreatmentCode == "70210304")
  243. ? "2"
  244. : "1";
  245. }
  246. else
  247. {
  248. e.Cell.Row.Cells["Station"].Value = "0";
  249. }
  250. }*/
  251. if (e.Cell.Column.Key == "TreatmentCode")
  252. {
  253. ultraGrid1.UpdateData();
  254. if (e.Cell.Value.ToString2() != "")
  255. {
  256. e.Cell.Row.Cells["Station"].Value = "1";
  257. e.Cell.Row.Cells["TreatmentName"].Value = e.Cell.Text;
  258. }
  259. }
  260. if (e.Cell.Column.Key == "Station")
  261. {
  262. ultraGrid1.UpdateData();
  263. if (e.Cell.Value.ToString2() == "0")
  264. {
  265. e.Cell.Row.Cells["UnpassCode"].Value = "";
  266. e.Cell.Row.Cells["UnpassName"].Value = "";
  267. e.Cell.Row.Cells["TreatmentCode"].Value = "";
  268. e.Cell.Row.Cells["TreatmentName"].Value = "";
  269. e.Cell.Row.Cells["UnpassMemo"].Value = "";
  270. }
  271. }
  272. }
  273. private void uteUnpass_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  274. {
  275. MchFinalCheckTotal entity = ultraGrid1.ActiveRow.ListObject as MchFinalCheckTotal;
  276. string OldStation = entity.Station;
  277. var matfrm = new ReasonChoose(ob, entity.PositionCode, entity.UnPassData);
  278. matfrm.ShowDialog();
  279. if (matfrm.DialogResult == DialogResult.OK)
  280. {
  281. List<MchFinalCheckTotal> list = mchFinalCheckTotalBindingSource.DataSource as List<MchFinalCheckTotal>;
  282. entity.UnPass = matfrm.Name;
  283. entity.UnPassData = matfrm.ListData ?? new List<MchFinalCheckResultDEntity>();
  284. entity.Station = (entity.UnPassData == null || !entity.UnPassData.Any())
  285. ? "0"
  286. : entity.UnPassData.Any(p => p.TreatmentCode1 == "70210304") ? "2" : "1";
  287. if (entity.Station == "2")
  288. {
  289. entity.UnPassData = entity.UnPassData.Where(p => p.TreatmentCode1 == "70210304").Take(1).ToList();
  290. }
  291. entity.UnPassData.ForEach(p =>
  292. {
  293. p.Station =entity.UnPassData.Any(q=> q.TreatmentCode1 == "70210304")?"2": "1";
  294. p.PositionCode = entity.PositionCode;
  295. p.PositionName = entity.PositionName;
  296. p.MatNo = entity.MatNo;
  297. p.MeasuringSeq = entity.MeasuringSeq;
  298. p.BarCode = entity.BarCode;
  299. });
  300. if (entity.Station == "2" || OldStation == "2")
  301. {
  302. var MatNos = list.Where(p => p.MatNo == entity.MatNo && p.PositionCode != entity.PositionCode).ToList();
  303. MatNos.ForEach(p =>
  304. {
  305. p.Station = entity.Station == "2" ? "2" : "0";
  306. p.UnPassData = new List<MchFinalCheckResultDEntity>();
  307. p.UnPass = "";
  308. });
  309. }
  310. ultraGrid1.Rows.Where(p=>p.Cells["MatNo"].Value.ToString2()==entity.MatNo).ToList().ForEach(
  311. p =>
  312. {
  313. if (p.Cells["Station"].Value.ToString2() == "1")
  314. {
  315. p.Cells["Station"].Appearance.BackColor = Color.Red;
  316. }
  317. else if (p.Cells["Station"].Value.ToString2() == "2")
  318. {
  319. p.Cells["Station"].Appearance.BackColor = Color.Red;
  320. }
  321. else
  322. {
  323. p.Cells["Station"].Appearance.ResetBackColor();
  324. }
  325. }
  326. );
  327. // ultraGrid1_CellChange(ultraGrid1, new CellEventArgs(ultraGrid1.ActiveRow.Cells["Unpass"]));
  328. }
  329. // Value.DubiousNum = Value.DubiousNum ?? 0;
  330. ultraGrid1.PerformAction(UltraGridAction.ExitEditMode);
  331. // mchFinalCheckTotalBindingSource.DataSource = Detail;
  332. mchFinalCheckTotalBindingSource.ResetBindings(false);
  333. ultraGrid1.UpdateData();
  334. }
  335. private void ultraButton1_Click(object sender, EventArgs e)
  336. {
  337. var entitty =
  338. ultraGrid2.Rows.Where(p => p.Cells["MeasuringSeq"].Value.ToString2() == txtDir.Text).ToList();
  339. if (entitty.Count() != 1)
  340. {
  341. MessageBox.Show("找不到指定的管号");
  342. }
  343. else
  344. {
  345. if (!(bool)entitty[0].Cells["Check"].Value)
  346. {
  347. entitty[0].Cells["Check"].Value = true;
  348. entitty[0].Activated = true;
  349. ultraGrid2_CellChange(null, new CellEventArgs(entitty[0].Cells["Check"]));
  350. }
  351. }
  352. txtDir.SelectAll();
  353. }
  354. private void txtDir_KeyPress(object sender, KeyPressEventArgs e)
  355. {
  356. if (e.KeyChar ==13)
  357. {
  358. ultraButton1_Click(null, null);
  359. }
  360. }
  361. private void ultraButton2_Click(object sender, EventArgs e)
  362. {
  363. int frequency = (int) numF.Value;
  364. int num = (int) numN.Value;
  365. if ((int) numN.Value > (int) numF.Value)
  366. {
  367. num = frequency;
  368. }
  369. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  370. {
  371. bool NeedCheck = i%frequency < num;
  372. if ((bool)ultraGrid2.Rows[i].Cells["Check"].Value != NeedCheck)
  373. {
  374. ultraGrid2.Rows[i].Cells["Check"].Value = NeedCheck;
  375. ultraGrid2.Rows[i].Activated = true;
  376. ultraGrid2_CellChange(null, new CellEventArgs(ultraGrid2.Rows[i].Cells["Check"]));
  377. }
  378. }
  379. }
  380. private void txtProNum_ValueChanged(object sender, EventArgs e)
  381. {
  382. if (_portHttBatchSampleResultEntitys == null || txtProNum.Value.ToString3() == _portHttBatchSampleResultEntitys.Count.ToString3()) return;
  383. Data.ProNum =decimal.Parse(txtProNum.Value.ToString3());
  384. var List = _portHttBatchSampleResultEntitys.Take((int)Data.ProNum).ToList();
  385. portMchBatchSampleResultEntityBindingSource.DataSource = List;
  386. foreach (var ultraGrid2Row in ultraGrid2.Rows)
  387. {
  388. ultraGrid2Row.Cells["Check"].Value = false;
  389. }
  390. Detail = new List<MchFinalCheckTotal>();
  391. mchFinalCheckTotalBindingSource.DataSource = Detail;
  392. commHelper.RefreshAndAutoSizeExceptColumns(ultraGrid2);
  393. ultraGrid2.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + Data.ProNum + "支";
  394. ultraGrid1.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + Data.ProNum + "支 "+ "抽检 0支";
  395. ultraGrid1.DisplayLayout.Bands[0].Summaries[1].DisplayFormat = "抽检率 0%";
  396. }
  397. private void ultraGrid2_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e)
  398. {
  399. ultraGrid2.UpdateData();
  400. CheckState newCheckState = e.Column.GetHeaderCheckedState(e.Rows);
  401. switch (newCheckState)
  402. {
  403. case CheckState.Checked:
  404. PortMchBatchSampleResultEntity entity =
  405. ultraGrid2.ActiveRow.ListObject as PortMchBatchSampleResultEntity;
  406. ultraGrid2.UpdateData();
  407. List<PortMchBatchSampleResultEntity> list =
  408. portMchBatchSampleResultEntityBindingSource.DataSource as List<PortMchBatchSampleResultEntity>;
  409. list.ForEach(p =>
  410. {
  411. if (Detail.All(q => q.MatNo != p.MatNo)){
  412. foreach (DataRow t in dt.Rows)
  413. {
  414. Detail.Add(new MchFinalCheckTotal()
  415. {
  416. MatNo = p.MatNo,
  417. BarCode = p.BarCode,
  418. MeasuringSeq = p.MeasuringSeq,
  419. PositionCode = t["BASECODE"].ToString2(),
  420. PositionName = t["BASENAME"].ToString2(),
  421. Station = "0",
  422. UnPassData = new List<MchFinalCheckResultDEntity>()
  423. });
  424. }
  425. }
  426. } );
  427. Detail = Detail.OrderBy(p => p.MeasuringSeq).ThenBy(p => p.MatNo).ThenBy(p => p.PositionCode).ToList();
  428. int C = Detail.Select(p => p.MatNo).Distinct().Count();
  429. mchFinalCheckTotalBindingSource.DataSource = Detail;
  430. ultraGrid1.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + C + "支 " + "抽检 " + C + "支";
  431. ultraGrid1.DisplayLayout.Bands[0].Summaries[1].DisplayFormat = "抽检率100%";
  432. break;
  433. case CheckState.Unchecked:
  434. Detail = new List<MchFinalCheckTotal>();
  435. mchFinalCheckTotalBindingSource.DataSource = Detail;
  436. ultraGrid2.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + Data.ProNum + "支";
  437. ultraGrid1.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + Data.ProNum + "支 " + "抽检 0支";
  438. ultraGrid1.DisplayLayout.Bands[0].Summaries[1].DisplayFormat = "抽检率 0%";
  439. break;
  440. default:
  441. break;
  442. }
  443. }
  444. private void ultraGrid1_InitializeRowsCollection(object sender, InitializeRowsCollectionEventArgs e)
  445. {
  446. foreach (var ultraGridRow in e.Rows)
  447. {
  448. if (ultraGridRow.Cells["Station"].Value.ToString2() == "1")
  449. {
  450. ultraGridRow.Cells["Station"].Appearance.BackColor = Color.Red;
  451. }
  452. else if (ultraGridRow.Cells["Station"].Value.ToString2() == "2")
  453. {
  454. ultraGridRow.Cells["Station"].Appearance.BackColor = Color.Red;
  455. }
  456. else
  457. {
  458. ultraGridRow.Cells["Station"].Appearance.ResetBackColor();
  459. }
  460. }
  461. }
  462. private void btnCheck_Click(object sender, EventArgs e)
  463. {
  464. int Start = 0;
  465. int End = 0;
  466. int Frequency = 0;
  467. if (!int.TryParse(txtStart.Text, out Start) || Start<=0)
  468. {
  469. MessageBox.Show("请输入正确的起始管号");
  470. return;
  471. }
  472. if (!int.TryParse(txtEnd.Text, out End) || End <= 0)
  473. {
  474. MessageBox.Show("请输入正确的结束管号");
  475. return;
  476. }
  477. if (!int.TryParse(uceFrequency.Text, out Frequency) && Frequency <= 0)
  478. {
  479. MessageBox.Show("请输入正确的抽取频率");
  480. return;
  481. }
  482. mchFinalCheckTotalBindingSource.Clear();
  483. Detail = new List<MchFinalCheckTotal>();
  484. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  485. {
  486. var row = ultraGrid2.Rows[i];
  487. bool NeedCheck = false;
  488. if (isMeasureData)
  489. {
  490. NeedCheck = int.Parse(row.Cells["MeasuringSeq"].Value.ToString3()) >= Start &&
  491. int.Parse(row.Cells["MeasuringSeq"].Value.ToString3()) <= End &&
  492. (int.Parse(row.Cells["MeasuringSeq"].Value.ToString3()) - Start)%Frequency == 0;
  493. }
  494. else
  495. {
  496. NeedCheck = i+1 >= Start &&
  497. i + 1 <= End &&
  498. (i+1 - Start) % Frequency == 0;
  499. }
  500. row.Cells["Check"].Value = NeedCheck;
  501. if (NeedCheck)
  502. {
  503. foreach (DataRow t in dt.Rows)
  504. {
  505. if (isMeasureData)
  506. {
  507. Detail.Add(new MchFinalCheckTotal()
  508. {
  509. MatNo = row.Cells["MatNo"].Value.ToString2(),
  510. BarCode = row.Cells["BarCode"].Value.ToString2(),
  511. MeasuringSeq = decimal.Parse(row.Cells["MeasuringSeq"].Value.ToString3()),
  512. PositionCode = t["BASECODE"].ToString2(),
  513. PositionName = t["BASENAME"].ToString2(),
  514. Station = "0",
  515. UnPassData = new List<MchFinalCheckResultDEntity>()
  516. });
  517. }
  518. else
  519. {
  520. Detail.Add(new MchFinalCheckTotal()
  521. {
  522. MatNo = row.Cells["MatNo"].Value.ToString2(),
  523. BarCode = row.Cells["BarCode"].Value.ToString2(),
  524. MeasuringSeq = null,
  525. PositionCode = t["BASECODE"].ToString2(),
  526. PositionName = t["BASENAME"].ToString2(),
  527. Station = "0",
  528. UnPassData = new List<MchFinalCheckResultDEntity>()
  529. });
  530. }
  531. }
  532. }
  533. }
  534. Detail = Detail.OrderBy(p => p.MeasuringSeq).ThenBy(p => p.MatNo).ThenBy(p => p.PositionCode).ToList();
  535. int C = Detail.Select(p => p.MatNo).Distinct().Count();
  536. int F = int.Parse(Data.ProNum.ToString3());
  537. mchFinalCheckTotalBindingSource.DataSource = Detail;
  538. ultraGrid1.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = "送检 " + F + "支 " + "抽检 " + C + "支";
  539. ultraGrid1.DisplayLayout.Bands[0].Summaries[1].DisplayFormat = "抽检率" + (C * 100d / F).ToString("0.00") + "%";
  540. }
  541. private void cmsCopy_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  542. {
  543. UltraGrid ug = (sender as ContextMenuStrip).SourceControl as UltraGrid;
  544. if (ug == null || ug.ActiveRow == null)
  545. {
  546. return;
  547. }
  548. MchFinalCheckTotal entity;
  549. if (ug.ActiveRow.HasParent())
  550. {
  551. entity = ug.ActiveRow.ParentRow.ListObject as MchFinalCheckTotal;
  552. }
  553. else
  554. {
  555. entity = ug.ActiveRow.ListObject as MchFinalCheckTotal;
  556. }
  557. if (e.ClickedItem.Name == "tmsCopyToAll")
  558. {
  559. List<MchFinalCheckTotal> list = mchFinalCheckTotalBindingSource.DataSource as List<MchFinalCheckTotal>;
  560. list.Where(p=>p.PositionCode == entity.PositionCode && p.MatNo !=entity.PositionCode).ToList().ForEach(
  561. p =>
  562. {
  563. p.UnPass = entity.UnPass;
  564. p.UnPassData = entity.UnPassData.Select(q =>
  565. {
  566. MchFinalCheckResultDEntity data = q.Clone();
  567. data.MatNo = p.MatNo;
  568. data.MeasuringSeq = p.MeasuringSeq;
  569. return data;
  570. }).ToList();
  571. p.Station = entity.Station;
  572. });
  573. mchFinalCheckTotalBindingSource.ResetBindings(false);
  574. ultraGrid1.UpdateData();
  575. ultraGrid1.Rows.ToList().ForEach(
  576. p =>
  577. {
  578. if (p.Cells["Station"].Value.ToString2() == "1")
  579. {
  580. p.Cells["Station"].Appearance.BackColor = Color.Red;
  581. }
  582. else if (p.Cells["Station"].Value.ToString2() == "2")
  583. {
  584. p.Cells["Station"].Appearance.BackColor = Color.Red;
  585. }
  586. else
  587. {
  588. p.Cells["Station"].Appearance.ResetBackColor();
  589. }
  590. }
  591. );
  592. }
  593. }
  594. private void ultraGrid2_InitializeRow(object sender, InitializeRowEventArgs e)
  595. {
  596. if (e.Row.Cells["PrcTechnologyPath"].Value.ToString2() != "")
  597. {
  598. e.Row.Appearance.BackColor = Color.Yellow;
  599. }
  600. }
  601. private void ultraTextEditor1_ValueChanged(object sender, EventArgs e)
  602. {
  603. }
  604. }
  605. }