Query_ExeProgress.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using UAS_MES.DataOperate;
  11. using UAS_MES.PublicMethod;
  12. namespace UAS_MES.Query
  13. {
  14. public partial class Query_ExeProgress : Form
  15. {
  16. DataHelper dh;
  17. LogStringBuilder sql = new LogStringBuilder();
  18. //经过的步骤
  19. string PastStep = "";
  20. //拆分后的经过的步骤
  21. Dictionary<int, string> Step;
  22. //屏幕高度
  23. int ScreenWidth;
  24. //屏幕宽度
  25. int ScreenHeight;
  26. DataTable dt;
  27. public Query_ExeProgress()
  28. {
  29. InitializeComponent();
  30. }
  31. private void 工单执行进度_Load(object sender, EventArgs e)
  32. {
  33. dh = new DataHelper();
  34. ScreenWidth = this.Width;
  35. ScreenHeight = this.Height;
  36. }
  37. private void 工单执行进度_SizeChanged(object sender, EventArgs e)
  38. {
  39. }
  40. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  41. {
  42. if (e.KeyCode == Keys.Enter)
  43. {
  44. if (Step != null && Step.Count > 0)
  45. {
  46. for (int i = 0; i < Step.Count; i++)
  47. {
  48. Controls.Remove(Controls[i + Step[i] + "_label"]);
  49. }
  50. }
  51. //查询执行过的步骤
  52. sql.Clear();
  53. sql.Append("select CD_DETNO, CD_STEPCODE from craft left join craftdetail on cd_crid = cr_id where ");
  54. sql.Append("cr_code=(select ms_craftcode from makeserial where ms_sncode='" + sn_code.Text + "') order by cd_detno");
  55. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  56. Step = new Dictionary<int, string>();
  57. PastStep = dh.getFieldDataByCondition("makeserial", "ms_paststep", "ms_sncode='" + sn_code.Text + "'").ToString();
  58. for (int i = 0; i < dt.Rows.Count + 2; i++)
  59. {
  60. if (i == 0)
  61. Step.Add(i, "开始");
  62. else if (i == dt.Rows.Count + 1)
  63. Step.Add(i, "结束");
  64. else
  65. Step.Add(i, dt.Rows[i - 1]["CD_STEPCODE"].ToString());
  66. }
  67. Refresh();
  68. }
  69. }
  70. private void SerialPanel_Paint(object sender, PaintEventArgs e)
  71. {
  72. if (Step != null)
  73. {
  74. //设置一行五个展示数量
  75. int RectangleCountEachRow = 5;
  76. int x = 40;
  77. int y = SerialPanel.Height / 10;
  78. int CurrentIndex = 0;
  79. //根据记录的数量判断行数
  80. int RowCount = (Step.Count % RectangleCountEachRow) == 0 ? (Step.Count / RectangleCountEachRow) : (Step.Count / RectangleCountEachRow) + 1;
  81. //每行的循环
  82. for (int i = 1; i <= RowCount; i++)
  83. {
  84. for (int j = CurrentIndex; j < RectangleCountEachRow * i; j++)
  85. {
  86. //创建画板
  87. Graphics g = e.Graphics;
  88. //途程节点的矩形
  89. Rectangle r;
  90. if (Step[j].Contains("开始") || Step[j].Contains("结束"))
  91. r = new Rectangle(0, 0, 40, 40);
  92. else
  93. r = new Rectangle();
  94. r.Width = SerialPanel.Width / 10;
  95. r.Height = SerialPanel.Height / 8;
  96. //画箭头的Pen
  97. Pen p = new Pen(Color.CadetBlue, 15);
  98. p.StartCap = LineCap.Round;
  99. p.EndCap = LineCap.ArrowAnchor;
  100. //方块内的信息
  101. Label Param = new Label();
  102. Param.Text = j + " " + Step[j];
  103. Param.Name = j + Step[j] + "_label";
  104. Param.AutoSize = true;
  105. Param.Anchor = AnchorStyles.Left;
  106. Param.Anchor = AnchorStyles.Top;
  107. Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4);
  108. //如果在奇数行
  109. if (i % 2 != 0)
  110. {
  111. r.Location = new Point(x, y);
  112. if (PastStep.Contains(Step[j]))
  113. {
  114. g.FillRectangle(Brushes.Green, r);
  115. }
  116. else
  117. {
  118. if (Step[j].Contains("开始") || Step[j].Contains("结束"))
  119. g.FillEllipse(Brushes.Green, r);
  120. else
  121. g.FillRectangle(Brushes.White, r);
  122. }
  123. //填充方块内的信息
  124. if (Controls[Param.Name] == null)
  125. SerialPanel.Controls.Add(Param);
  126. if (j + 1 == Step.Count)
  127. break;
  128. //画箭头
  129. //如果是一行中的箭头
  130. if (j + 1 < RectangleCountEachRow * i)
  131. {
  132. g.DrawLine(p, x + r.Width + 10, y + r.Height / 2, x + ScreenWidth / (RectangleCountEachRow), y + r.Height / 2);
  133. x += ScreenWidth / RectangleCountEachRow;
  134. }
  135. //如果是行的最后一个的箭头
  136. else if (j + 1 == RectangleCountEachRow * i)
  137. {
  138. g.DrawLine(p, x + r.Width / 2, y + r.Height + 10, x + r.Width / 2, y + r.Height + r.Height);
  139. y = y + r.Height + r.Height;
  140. }
  141. }
  142. //如果在偶数行
  143. else
  144. {
  145. r.Location = new Point(x, y);
  146. if (PastStep.Contains(Step[j]))
  147. {
  148. g.FillRectangle(Brushes.Green, r);
  149. }
  150. else
  151. {
  152. if (Step[j].Contains("开始") || Step[j].Contains("结束"))
  153. {
  154. g.FillEllipse(Brushes.Green, r);
  155. }
  156. else
  157. {
  158. g.FillRectangle(Brushes.White, r);
  159. }
  160. }
  161. //填充文字信息
  162. //存在这个名称的则不进行添加
  163. if (Controls[Param.Name] == null)
  164. {
  165. SerialPanel.Controls.Add(Param);
  166. }
  167. //如果最后一个的画则直接Break,不用画箭头了
  168. if (j + 1 == Step.Count)
  169. {
  170. break;
  171. }
  172. //如果不是本行的最后一个画横向的箭头
  173. if (j + 1 < RectangleCountEachRow * i)
  174. {
  175. g.DrawLine(p, (x - 10), (y + r.Height / 2), (x - ScreenWidth / RectangleCountEachRow + r.Width), (y + r.Height / 2));
  176. x -= ScreenWidth / RectangleCountEachRow;
  177. }
  178. //如果是最后一个画纵向的箭头
  179. else if (j + 1 == RectangleCountEachRow * i)
  180. {
  181. g.DrawLine(p, (x + r.Width / 2), (y + r.Height + 10), (x + r.Width / 2), (y + r.Height + r.Height));
  182. y = y + r.Height + r.Height;
  183. }
  184. }
  185. CurrentIndex = CurrentIndex + 1;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }