Query_ExeProgress.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. {
  103. //判断之前有没有添加过黑色
  104. if (PaintColor.Contains(Brushes.Black))
  105. {
  106. //移除之前的,
  107. int index = PaintColor.IndexOf(Brushes.Black);
  108. PaintColor.RemoveAt(PaintColor.IndexOf(Brushes.Black));
  109. PaintColor.Insert(index, Brushes.Green);
  110. }
  111. PaintColor.Add(Brushes.Black);
  112. }
  113. }
  114. }
  115. //不包含说明是线外工序
  116. else
  117. {
  118. PaintColor.Add(Brushes.White);
  119. }
  120. }
  121. //完工添加绿色,未完工添加红色
  122. if (dh.CheckExist("Makeserial", "ms_sncode='" + sn_code.Text + "' and ms_status=2"))
  123. PaintColor.Add(Brushes.Green);
  124. else
  125. PaintColor.Add(Brushes.White);
  126. Refresh();
  127. SerialPanel.Refresh();
  128. sql.Clear();
  129. sql.Append("select mp_makecode,ma_prodcode,ma_linecode,ma_craftcode,mp_sourcecode,mp_sncode,mp_indate ");
  130. sql.Append("from makeprocess left join make on mp_makecode=ma_code where mp_sncode='" + sn_code.Text + "'");
  131. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  132. BaseUtil.FillDgvWithDataTable(CraftInfDgv, dt);
  133. }
  134. else MessageBox.Show("序列号" + sn_code.Text + "不存在");
  135. }
  136. }
  137. private void SerialPanel_Paint(object sender, PaintEventArgs e)
  138. {
  139. if (Step != null)
  140. {
  141. //设置一行五个展示数量
  142. int RectangleCountEachRow = 5;
  143. int x = 40;
  144. int y = SerialPanel.Height / 10;
  145. int CurrentIndex = 0;
  146. //根据记录的数量判断行数
  147. int RowCount = (Step.Count % RectangleCountEachRow) == 0 ? (Step.Count / RectangleCountEachRow) : (Step.Count / RectangleCountEachRow) + 1;
  148. //每行的循环
  149. for (int i = 1; i <= RowCount; i++)
  150. {
  151. for (int j = CurrentIndex; j < RectangleCountEachRow * i; j++)
  152. {
  153. //创建画板
  154. Graphics g = e.Graphics;
  155. //途程节点的矩形
  156. Rectangle r;
  157. if (Step[j].Contains("开始") || Step[j].Contains("结束"))
  158. {
  159. r = new Rectangle(0, 0, 40, 40);
  160. }
  161. else
  162. r = new Rectangle();
  163. r.Width = SerialPanel.Width / 10;
  164. r.Height = SerialPanel.Height / 8;
  165. //画箭头的Pen
  166. Pen p = new Pen(Color.CadetBlue, 15);
  167. p.StartCap = LineCap.Round;
  168. p.EndCap = LineCap.ArrowAnchor;
  169. //方块内的信息
  170. Label Param = new Label();
  171. Param.Text = j + " " + Step[j];
  172. Param.Name = j + Step[j] + "_label";
  173. Param.AutoSize = true;
  174. Param.Anchor = AnchorStyles.Left;
  175. Param.Anchor = AnchorStyles.Top;
  176. Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4);
  177. //如果在奇数行
  178. if (i % 2 != 0)
  179. {
  180. r.Location = new Point(x, y);
  181. g.FillRectangle(PaintColor[j], r);
  182. //填充方块内的信息
  183. if (SerialPanel.Controls[Param.Name] == null)
  184. SerialPanel.Controls.Add(Param);
  185. if (j + 1 == Step.Count)
  186. break;
  187. //画箭头
  188. //如果是一行中的箭头
  189. if (j + 1 < RectangleCountEachRow * i)
  190. {
  191. g.DrawLine(p, x + r.Width + 10, y + r.Height / 2, x + ScreenWidth / (RectangleCountEachRow), y + r.Height / 2);
  192. x += ScreenWidth / RectangleCountEachRow;
  193. }
  194. //如果是行的最后一个的箭头
  195. else if (j + 1 == RectangleCountEachRow * i)
  196. {
  197. g.DrawLine(p, x + r.Width / 2, y + r.Height + 10, x + r.Width / 2, y + r.Height + r.Height);
  198. y = y + r.Height + r.Height;
  199. }
  200. }
  201. //如果在偶数行
  202. else
  203. {
  204. r.Location = new Point(x, y);
  205. g.FillRectangle(PaintColor[j], r);
  206. //填充文字信息
  207. //存在这个名称的则不进行添加
  208. if (SerialPanel.Controls[Param.Name] == null)
  209. {
  210. SerialPanel.Controls.Add(Param);
  211. }
  212. //如果最后一个的画则直接Break,不用画箭头了
  213. if (j + 1 == Step.Count)
  214. {
  215. break;
  216. }
  217. //如果不是本行的最后一个画横向的箭头
  218. if (j + 1 < RectangleCountEachRow * i)
  219. {
  220. g.DrawLine(p, (x - 10), (y + r.Height / 2), (x - ScreenWidth / RectangleCountEachRow + r.Width), (y + r.Height / 2));
  221. x -= ScreenWidth / RectangleCountEachRow;
  222. }
  223. //如果是最后一个画纵向的箭头
  224. else if (j + 1 == RectangleCountEachRow * i)
  225. {
  226. g.DrawLine(p, (x + r.Width / 2), (y + r.Height + 10), (x + r.Width / 2), (y + r.Height + r.Height));
  227. y = y + r.Height + r.Height;
  228. }
  229. }
  230. CurrentIndex = CurrentIndex + 1;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. }