ResultViewPreview.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. using Resources;
  2. using SmartCoalApplication.Core;
  3. using SmartCoalApplication.Resources;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9. using System.Windows.Forms;
  10. namespace SmartCoalApplication.AutomaticMeasurement
  11. {
  12. public partial class ResultViewPreview : PdnBaseForm
  13. {
  14. private ResultsView resultsView;
  15. public const int WM_NCLBUTTONDBLCLK = 0xA3;
  16. private const int WM_NCLBUTTONDOWN = 0x00A1;
  17. private const int HTCAPTION = 2;
  18. private MeasureInfoExportModel measureInfoExportModel;
  19. private int rowLine = 5;
  20. protected override void WndProc(ref Message m)
  21. {
  22. if (m.Msg == WM_NCLBUTTONDOWN && m.WParam.ToInt32() == HTCAPTION)
  23. return;
  24. if (m.Msg == WM_NCLBUTTONDBLCLK)
  25. return;
  26. base.WndProc(ref m);
  27. }
  28. public ResultViewPreview(ResultsView resultsView, string titleName, int rowLines, MeasureInfoExportModel measureInfoExportModel)
  29. {
  30. InitializeComponent();
  31. this.resultsView = resultsView;
  32. this.Text = $"切片检验报告-{titleName}";
  33. this.Icon = PdnInfo.AppIcon;
  34. this.measureInfoExportModel = measureInfoExportModel;
  35. if (rowLines > 5)
  36. {
  37. this.rowLine = rowLines;
  38. }
  39. #region[左边相同的部分]
  40. // 表头
  41. int height = 38;
  42. int width = (this.Size.Width + 280) / 10;
  43. int dataWidth = (this.Size.Width - width * 5) / 5 + 5;
  44. string[] titles = { PdnResources.GetString("NewHoleTypeName"), PdnResources.GetString("NewTestItemsName"), PdnResources.GetString("NewSpecificationName"), PdnResources.GetString("NewMeasuringPositionName") };
  45. string[] titleNames = { "kongxing", "jianyanxiangmu", "guige", "celiangweizhi" };
  46. List<Label> positions = new List<Label>();
  47. List<Label> specifications = new List<Label>();
  48. List<Label> testItems = new List<Label>();
  49. List<Label> holeTypes = new List<Label>();
  50. List<Label> datas = new List<Label>();
  51. List<Label> judges = new List<Label>();
  52. List<Label> judgeFalses = new List<Label>();
  53. List<bool> judgeList = new List<bool>();
  54. int groupsNum = this.measureInfoExportModel.measureInfoExportDataModelList.Count / this.rowLine; // 共输出几组数据
  55. int i, k, judgeSame;
  56. for (i = 0; i < 4; i++)
  57. {
  58. Label title = new Label();
  59. title.AutoSize = false;
  60. title.TextAlign = ContentAlignment.MiddleCenter;
  61. title.BorderStyle = BorderStyle.FixedSingle;
  62. title.Location = new System.Drawing.Point(3 + (width - 1) * i, 3);
  63. title.Name = titleNames[i];
  64. title.Size = new System.Drawing.Size(width, height);
  65. title.TabIndex = 2;
  66. title.Text = titles[i];
  67. panelResultViewPreview.Controls.Add(title);
  68. }
  69. // 表头
  70. for (int c = 0; c < rowLine; c++)
  71. {
  72. Label num = new Label();
  73. num.AutoSize = false;
  74. num.TextAlign = ContentAlignment.MiddleCenter;
  75. num.BorderStyle = BorderStyle.FixedSingle;
  76. if (testItems.Count == 0)
  77. num.Location = new System.Drawing.Point((width - 1) * 4, 3);
  78. else
  79. num.Location = new System.Drawing.Point((width - 1) * 4 + c * dataWidth, 3);
  80. num.Name = c.ToString();
  81. num.Size = new System.Drawing.Size(dataWidth + 1, height);
  82. num.TabIndex = 2;
  83. num.Text = (c + 1).ToString();
  84. panelResultViewPreview.Controls.Add(num);
  85. testItems.Add(num);
  86. }
  87. #region[右边判断]
  88. // 判断栏表头
  89. for (int c = 0; c < 3; c++)
  90. {
  91. Label judge = new Label();
  92. judge.AutoSize = false;
  93. judge.TextAlign = ContentAlignment.MiddleCenter;
  94. judge.BorderStyle = BorderStyle.FixedSingle;
  95. switch (c)
  96. {
  97. // 判断
  98. case 0:
  99. judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, 3);
  100. judge.Size = new System.Drawing.Size(dataWidth + 1, height / 2);
  101. judge.Text = PdnResources.GetString("judge");
  102. break;
  103. // OK
  104. case 1:
  105. judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, height / 2 - 1);
  106. judge.Size = new System.Drawing.Size(dataWidth / 2 + 4, height / 2 + 4);
  107. judge.Text = "OK";
  108. break;
  109. // NG
  110. case 2:
  111. judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width + dataWidth / 2, height / 2 - 1);
  112. judge.Size = new System.Drawing.Size(dataWidth / 2 + 2, height / 2 + 4);
  113. judge.Text = "NG";
  114. break;
  115. default: break;
  116. }
  117. //data.Name = item2.Key + "1";
  118. judge.TabIndex = 2;
  119. if (c == 0)
  120. {
  121. judge.Text = PdnResources.GetString("judge");
  122. }
  123. panelResultViewPreview.Controls.Add(judge);
  124. judges.Add(judge);
  125. }
  126. #endregion
  127. var list1 = this.measureInfoExportModel.measureInfoExportDataModelList;
  128. int s = 0;
  129. int index = 0;
  130. List<int> same = new List<int>();
  131. int n = 0;
  132. foreach (var item in list1)
  133. {
  134. int rowInt = 0;
  135. foreach (var item2 in item.itemTypeList)
  136. {
  137. k = 0;
  138. int p = -1;
  139. foreach (var item3 in item2.LineDataList)
  140. {
  141. #region [測量位置]
  142. Label position = new Label();
  143. position.AutoSize = false;
  144. position.TextAlign = ContentAlignment.MiddleCenter;
  145. position.BorderStyle = BorderStyle.FixedSingle;
  146. if (positions.Count == 0)
  147. position.Location = new System.Drawing.Point(3 + (width - 1) * 3, height);
  148. else
  149. position.Location = new System.Drawing.Point(3 + (width - 1) * 3, positions[positions.Count - 1].Location.Y + height);
  150. position.Name = item3.name;
  151. position.Size = new System.Drawing.Size(width, height + 1);
  152. position.TabIndex = 2;
  153. position.Text = item3.name;
  154. panelResultViewPreview.Controls.Add(position);
  155. positions.Add(position);
  156. #endregion [測量位置]
  157. #region [填充数据]
  158. if (!item3.isMaxOrMin)
  159. {
  160. int colCount = 0;
  161. foreach (var item4 in item3.value)
  162. {
  163. Label data = new Label();
  164. data.AutoSize = false;
  165. data.TextAlign = ContentAlignment.MiddleCenter;
  166. data.BorderStyle = BorderStyle.FixedSingle;
  167. if (datas.Count == 0)
  168. {
  169. data.Location = new System.Drawing.Point((width - 1) * 4, position.Location.Y);
  170. }
  171. else
  172. {
  173. data.Location = new System.Drawing.Point((width - 1) * 4 + colCount * dataWidth, position.Location.Y);
  174. }
  175. //data.Name = item2.Key + "1";
  176. data.Size = new System.Drawing.Size(dataWidth + 1, height + 1);
  177. data.TabIndex = 2;
  178. data.Text = item4.ToString();
  179. if (item3.NgValue.Contains(item4))
  180. {
  181. data.ForeColor = Color.Red;
  182. }
  183. data.DoubleClick += ReturnView;
  184. if (!item3.isMaxOrMin)
  185. {
  186. data.Tag = item3.matIndex[colCount];
  187. }
  188. panelResultViewPreview.Controls.Add(data);
  189. datas.Add(data);
  190. colCount++;
  191. }
  192. if (item3.value.Count < this.rowLine)
  193. {
  194. for (int o = colCount; o < this.rowLine && o >= colCount; o++)
  195. {
  196. Label data = new Label();
  197. data.AutoSize = false;
  198. data.TextAlign = ContentAlignment.MiddleCenter;
  199. data.BorderStyle = BorderStyle.FixedSingle;
  200. if (datas.Count == 0)
  201. {
  202. data.Location = new System.Drawing.Point((width - 1) * 4, position.Location.Y);
  203. }
  204. else
  205. {
  206. data.Location = new System.Drawing.Point((width - 1) * 4 + o * dataWidth, position.Location.Y);
  207. }
  208. //data.Name = item2.Key + "1";
  209. data.Size = new System.Drawing.Size(dataWidth + 1, height + 1);
  210. data.TabIndex = 2;
  211. data.Text = "-";
  212. panelResultViewPreview.Controls.Add(data);
  213. datas.Add(data);
  214. }
  215. }
  216. }
  217. else
  218. {
  219. Label data = new Label();
  220. data.AutoSize = false;
  221. data.TextAlign = ContentAlignment.MiddleCenter;
  222. data.BorderStyle = BorderStyle.FixedSingle;
  223. data.Location = new System.Drawing.Point((width - 1) * 4, position.Location.Y);
  224. //data.Name = item2.Key + "1";
  225. data.Size = new System.Drawing.Size((dataWidth) * this.rowLine + 1, height + 1);
  226. data.TabIndex = 2;
  227. if (item3.NgValue.Contains(Math.Round(item3.value.Max())))
  228. {
  229. data.ForeColor = Color.Red;
  230. }
  231. if(item3.value != null && item3.value.Count != 0)
  232. {
  233. switch (item3.typeCase)
  234. {
  235. case 1:
  236. data.Text = Math.Round(item3.value.Max(), Program.instance.decimalPlaces).ToString();
  237. break;
  238. case 2:
  239. data.Text = Math.Round(item3.value.Min(), Program.instance.decimalPlaces).ToString();
  240. break;
  241. case 3:
  242. data.Text = Math.Round(item3.value.Average(), Program.instance.decimalPlaces).ToString();
  243. break;
  244. default:
  245. data.Text = "0";
  246. break;
  247. }
  248. }
  249. else
  250. {
  251. data.Text = "-";
  252. }
  253. panelResultViewPreview.Controls.Add(data);
  254. datas.Add(data);
  255. }
  256. #endregion
  257. k++;
  258. rowInt++;
  259. n++;
  260. }
  261. #region [規格]
  262. Label specification = new Label();
  263. specification.AutoSize = false;
  264. specification.TextAlign = ContentAlignment.MiddleCenter;
  265. specification.BorderStyle = BorderStyle.FixedSingle;
  266. if (specifications.Count == 0)
  267. specification.Location = new System.Drawing.Point(3 + (width - 1) * 2, positions[positions.Count - k].Location.Y);
  268. else
  269. specification.Location = new System.Drawing.Point(3 + (width - 1) * 2, positions[positions.Count - k].Location.Y);
  270. specification.Name = item2.Specification;
  271. specification.Size = new System.Drawing.Size(width, height * k + 1);
  272. specification.TabIndex = 2;
  273. item2.Specification = item2.Specification.Replace("LQ", "<=");
  274. item2.Specification = item2.Specification.Replace("L", "<");
  275. // 替換為與excel相同的字符
  276. string pattern = @"<=?X<=?";
  277. item2.Specification = Regex.Replace(item2.Specification, pattern, "~");
  278. item2.Specification = item2.Specification.Replace("X", "");
  279. specification.Text = item2.Specification;
  280. panelResultViewPreview.Controls.Add(specification);
  281. specifications.Add(specification);
  282. bool haveData = true;
  283. foreach (var item3 in item2.LineDataList)
  284. {
  285. if(item3.value.Count == 0)
  286. {
  287. haveData = false;
  288. }
  289. }
  290. if (!string.IsNullOrEmpty(item2.Specification) && !item2.Specification.Equals("-") && haveData)
  291. {
  292. Label judge = new Label();
  293. judge.AutoSize = false;
  294. judge.TextAlign = ContentAlignment.MiddleCenter;
  295. judge.BorderStyle = BorderStyle.FixedSingle;
  296. if (judges.Count == 0)
  297. {
  298. judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, specification.Location.Y);
  299. judge.Size = new System.Drawing.Size(dataWidth / 2 + 4, specification.Height);
  300. }
  301. else
  302. {
  303. judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, specification.Location.Y);
  304. judge.Size = new System.Drawing.Size(dataWidth / 2 + 4, specification.Height);
  305. }
  306. judge.TabIndex = 2;
  307. if (item2.isOk)
  308. {
  309. judge.Text = "V";
  310. }
  311. panelResultViewPreview.Controls.Add(judge);
  312. judges.Add(judge);
  313. Label judgeFalse = new Label();
  314. judgeFalse.AutoSize = false;
  315. judgeFalse.TextAlign = ContentAlignment.MiddleCenter;
  316. judgeFalse.BorderStyle = BorderStyle.FixedSingle;
  317. if (judgeFalses.Count == 0)
  318. {
  319. judgeFalse.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width + dataWidth / 2 - 1, specification.Location.Y);
  320. judgeFalse.Size = new System.Drawing.Size(dataWidth / 2 + 3, specification.Height);
  321. }
  322. else
  323. {
  324. judgeFalse.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width + dataWidth / 2 - 1, specification.Location.Y);
  325. judgeFalse.Size = new System.Drawing.Size(dataWidth / 2 + 3, specification.Height);
  326. }
  327. judgeFalse.TabIndex = 2;
  328. if (!item2.isOk)
  329. {
  330. judgeFalse.Text = "V";
  331. }
  332. panelResultViewPreview.Controls.Add(judgeFalse);
  333. judgeFalses.Add(judgeFalse);
  334. }
  335. else
  336. {
  337. Label judge = new Label();
  338. judge.AutoSize = false;
  339. judge.TextAlign = ContentAlignment.MiddleCenter;
  340. judge.BorderStyle = BorderStyle.FixedSingle;
  341. judge.Location = new System.Drawing.Point((dataWidth - 1) * rowLine + 4 * width, specification.Location.Y);
  342. judge.Size = new System.Drawing.Size(dataWidth + 1, height * k + 1);
  343. judge.TabIndex = 2;
  344. judge.Text = "N/A";
  345. panelResultViewPreview.Controls.Add(judge);
  346. judges.Add(judge);
  347. }
  348. #endregion
  349. #region [檢驗項目]
  350. Label testItem = new Label();
  351. testItem.AutoSize = false;
  352. testItem.TextAlign = ContentAlignment.MiddleCenter;
  353. testItem.BorderStyle = BorderStyle.FixedSingle;
  354. if (testItems.Count == 0)
  355. testItem.Location = new System.Drawing.Point(3 + (width - 1) * 1, height + 1 );
  356. else
  357. testItem.Location = new System.Drawing.Point(3 + (width - 1) * 1, positions[positions.Count - k].Location.Y);
  358. testItem.Name = item2.TestItems;
  359. testItem.Size = new System.Drawing.Size(width, height * k + 1);
  360. testItem.TabIndex = 2;
  361. testItem.Text = item2.TestItems;
  362. panelResultViewPreview.Controls.Add(testItem);
  363. testItems.Add(testItem);
  364. #endregion
  365. }
  366. #region [孔型]
  367. int itemNum = item.itemTypeList.Count;
  368. int sum = 0;
  369. foreach(var item4 in item.itemTypeList)
  370. {
  371. sum += item4.LineDataList.Count;
  372. }
  373. Label holeType = new Label();
  374. holeType.AutoSize = false;
  375. holeType.TextAlign = ContentAlignment.MiddleCenter;
  376. holeType.BorderStyle = BorderStyle.FixedSingle;
  377. if (holeTypes.Count == 0)
  378. holeType.Location = new System.Drawing.Point(3, height );
  379. else
  380. holeType.Location = new System.Drawing.Point(3, specifications[specifications.Count - itemNum].Location.Y);
  381. holeType.Name = item.HoleType;
  382. holeType.Size = new System.Drawing.Size(width, height * sum + 1);
  383. holeType.TabIndex = 2;
  384. holeType.Text = item.HoleType;
  385. panelResultViewPreview.Controls.Add(holeType);
  386. holeTypes.Add(holeType);
  387. #endregion
  388. }
  389. #endregion
  390. this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;//在窗体初始化后添加一句代码
  391. SetStyle(ControlStyles.UserPaint, true);
  392. SetStyle(ControlStyles.AllPaintingInWmPaint, true);//禁止擦除背景.
  393. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);//双缓冲
  394. this.UpdateStyles();
  395. }
  396. private void ReturnView(object sender, EventArgs e)
  397. {
  398. Label label = (Label)sender;
  399. if (label.Tag != null)
  400. {
  401. int index = Convert.ToInt32(label.Tag.ToString());
  402. this.Close();
  403. this.resultsView.returnMatView(index);
  404. }
  405. }
  406. }
  407. }