Query_ExeProgress.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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,sc_linecode,ma_craftcode,mp_sourcecode,mp_sncode,");
  130. sql.Append("mp_indate from makeprocess left join make on mp_makecode=ma_code left join source on ");
  131. sql.Append("mp_sourcecode=sc_code where mp_sncode='" + sn_code.Text + "'");
  132. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  133. BaseUtil.FillDgvWithDataTable(CraftInfDgv, dt);
  134. }
  135. else MessageBox.Show("序列号" + sn_code.Text + "不存在");
  136. }
  137. }
  138. private void SerialPanel_Paint(object sender, PaintEventArgs e)
  139. {
  140. if (Step != null)
  141. {
  142. //设置一行五个展示数量
  143. int RectangleCountEachRow = 5;
  144. int x = 40;
  145. int y = SerialPanel.Height / 10;
  146. int CurrentIndex = 0;
  147. //根据记录的数量判断行数
  148. int RowCount = (Step.Count % RectangleCountEachRow) == 0 ? (Step.Count / RectangleCountEachRow) : (Step.Count / RectangleCountEachRow) + 1;
  149. //每行的循环
  150. for (int i = 1; i <= RowCount; i++)
  151. {
  152. for (int j = CurrentIndex; j < RectangleCountEachRow * i; j++)
  153. {
  154. //创建画板
  155. Graphics g = e.Graphics;
  156. //途程节点的矩形
  157. Rectangle r;
  158. if (Step[j].Contains("开始") || Step[j].Contains("结束"))
  159. {
  160. r = new Rectangle(0, 0, 40, 40);
  161. }
  162. else
  163. r = new Rectangle();
  164. r.Width = SerialPanel.Width / 10;
  165. r.Height = SerialPanel.Height / 8;
  166. //画箭头的Pen
  167. Pen p = new Pen(Color.CadetBlue, 15);
  168. p.StartCap = LineCap.Round;
  169. p.EndCap = LineCap.ArrowAnchor;
  170. //方块内的信息
  171. Label Param = new Label();
  172. Param.Text = j + " " + Step[j];
  173. Param.Name = j + Step[j] + "_label";
  174. Param.AutoSize = true;
  175. Param.Margin = new Padding(0,0,0,0);
  176. Param.Anchor = AnchorStyles.Left;
  177. Param.Anchor = AnchorStyles.Top;
  178. //获取param的宽度和高度
  179. Graphics graphics = Graphics.FromHwnd(Param.Handle);
  180. SizeF size = graphics.MeasureString(Param.Text,Param.Font);
  181. //设定param文本框的位置
  182. //Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4);
  183. Param.Location = new Point(x+(int)(r.Width-size.Width)/2,y+(int)(r.Height-size.Height)/2);
  184. graphics.Dispose();
  185. //如果在奇数行
  186. if (i % 2 != 0)
  187. {
  188. r.Location = new Point(x, y);
  189. g.FillRectangle(PaintColor[j], r);
  190. //填充方块内的信息
  191. if (SerialPanel.Controls[Param.Name] == null)
  192. SerialPanel.Controls.Add(Param);
  193. if (j + 1 == Step.Count)
  194. break;
  195. //画箭头
  196. //如果是一行中的箭头
  197. if (j + 1 < RectangleCountEachRow * i)
  198. {
  199. g.DrawLine(p, x + r.Width + 10, y + r.Height / 2, x + ScreenWidth / (RectangleCountEachRow), y + r.Height / 2);
  200. x += ScreenWidth / RectangleCountEachRow;
  201. }
  202. //如果是行的最后一个的箭头
  203. else if (j + 1 == RectangleCountEachRow * i)
  204. {
  205. g.DrawLine(p, x + r.Width / 2, y + r.Height + 10, x + r.Width / 2, y + r.Height + r.Height);
  206. y = y + r.Height + r.Height;
  207. }
  208. }
  209. //如果在偶数行
  210. else
  211. {
  212. r.Location = new Point(x, y);
  213. g.FillRectangle(PaintColor[j], r);
  214. //填充文字信息
  215. //存在这个名称的则不进行添加
  216. if (SerialPanel.Controls[Param.Name] == null)
  217. {
  218. SerialPanel.Controls.Add(Param);
  219. }
  220. //如果最后一个的画则直接Break,不用画箭头了
  221. if (j + 1 == Step.Count)
  222. {
  223. break;
  224. }
  225. //如果不是本行的最后一个画横向的箭头
  226. if (j + 1 < RectangleCountEachRow * i)
  227. {
  228. g.DrawLine(p, (x - 10), (y + r.Height / 2), (x - ScreenWidth / RectangleCountEachRow + r.Width), (y + r.Height / 2));
  229. x -= ScreenWidth / RectangleCountEachRow;
  230. }
  231. //如果是最后一个画纵向的箭头
  232. else if (j + 1 == RectangleCountEachRow * i)
  233. {
  234. g.DrawLine(p, (x + r.Width / 2), (y + r.Height + 10), (x + r.Width / 2), (y + r.Height + r.Height));
  235. y = y + r.Height + r.Height;
  236. }
  237. }
  238. CurrentIndex = CurrentIndex + 1;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. }