Query_ExeProgress.cs 10 KB

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