Query_ExeProgress.cs 9.0 KB

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