Query_ExeProgress.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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.Margin = new Padding(0,0,0,0);
  175. Param.Anchor = AnchorStyles.Left;
  176. Param.Anchor = AnchorStyles.Top;
  177. //获取param的宽度和高度
  178. Graphics graphics = Graphics.FromHwnd(Param.Handle);
  179. SizeF size = graphics.MeasureString(Param.Text,Param.Font);
  180. //设定param文本框的位置
  181. //Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4);
  182. Param.Location = new Point(x+(int)(r.Width-size.Width)/2,y+(int)(r.Height-size.Height)/2);
  183. graphics.Dispose();
  184. //如果在奇数行
  185. if (i % 2 != 0)
  186. {
  187. r.Location = new Point(x, y);
  188. g.FillRectangle(PaintColor[j], r);
  189. //填充方块内的信息
  190. if (SerialPanel.Controls[Param.Name] == null)
  191. SerialPanel.Controls.Add(Param);
  192. if (j + 1 == Step.Count)
  193. break;
  194. //画箭头
  195. //如果是一行中的箭头
  196. if (j + 1 < RectangleCountEachRow * i)
  197. {
  198. g.DrawLine(p, x + r.Width + 10, y + r.Height / 2, x + ScreenWidth / (RectangleCountEachRow), 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. //如果在偶数行
  209. else
  210. {
  211. r.Location = new Point(x, y);
  212. g.FillRectangle(PaintColor[j], r);
  213. //填充文字信息
  214. //存在这个名称的则不进行添加
  215. if (SerialPanel.Controls[Param.Name] == null)
  216. {
  217. SerialPanel.Controls.Add(Param);
  218. }
  219. //如果最后一个的画则直接Break,不用画箭头了
  220. if (j + 1 == Step.Count)
  221. {
  222. break;
  223. }
  224. //如果不是本行的最后一个画横向的箭头
  225. if (j + 1 < RectangleCountEachRow * i)
  226. {
  227. g.DrawLine(p, (x - 10), (y + r.Height / 2), (x - ScreenWidth / RectangleCountEachRow + r.Width), (y + r.Height / 2));
  228. x -= ScreenWidth / RectangleCountEachRow;
  229. }
  230. //如果是最后一个画纵向的箭头
  231. else if (j + 1 == RectangleCountEachRow * i)
  232. {
  233. g.DrawLine(p, (x + r.Width / 2), (y + r.Height + 10), (x + r.Width / 2), (y + r.Height + r.Height));
  234. y = y + r.Height + r.Height;
  235. }
  236. }
  237. CurrentIndex = CurrentIndex + 1;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. }