Query_ExeProgress.cs 9.8 KB

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