Query_ExeProgress.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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,NVL(ms_ifrework, 0) ms_ifrework,NVL(ms_reworkstatus, 0) ms_reworkstatus 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. string ifRework = dt.Rows[0]["ms_ifrework"].ToString();
  58. //执行过的步骤
  59. PastStep = dt.Rows[0]["ms_paststep"].ToString();
  60. //如果为不良的时候
  61. string BadStep = "";
  62. string RejectStep = "";
  63. string reworkStep ="";
  64. //先判断是否是返工的
  65. if (ifRework!= "0")
  66. {
  67. //是返工的
  68. if (dt.Rows[0]["ms_reworkstatus"].ToString() == "3")
  69. {
  70. BadStep = dt.Rows[0]["ms_stepcode"].ToString();
  71. }
  72. else if (dt.Rows[0]["ms_reworkstatus"].ToString() == "4")
  73. {
  74. RejectStep = dt.Rows[0]["ms_stepcode"].ToString();
  75. }
  76. reworkStep = dt.Rows[0]["ms_stepcode"].ToString();
  77. }
  78. else
  79. {
  80. //不是返工的
  81. if (dt.Rows[0]["ms_status"].ToString() == "3")
  82. {
  83. BadStep = dt.Rows[0]["ms_stepcode"].ToString();
  84. }
  85. else if (dt.Rows[0]["ms_status"].ToString() == "4")
  86. {
  87. RejectStep = dt.Rows[0]["ms_stepcode"].ToString();
  88. }
  89. }
  90. //查询执行过的步骤
  91. sql.Clear();
  92. sql.Append("select CD_DETNO,CD_STEPCODE from craft left join craftdetail on cd_crid = cr_id left join makeserial ");
  93. sql.Append("on ms_craftcode=cr_code and ms_prodcode=cr_prodcode where ms_sncode='" + sn_code.Text + "' order by cd_detno");
  94. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  95. Step = new Dictionary<int, string>();
  96. for (int i = 0; i < dt.Rows.Count + 2; i++)
  97. {
  98. if (i == 0)
  99. Step.Add(i, "开始");
  100. else if (i == dt.Rows.Count + 1)
  101. Step.Add(i, "结束");
  102. else
  103. Step.Add(i, dt.Rows[i - 1]["CD_STEPCODE"].ToString());
  104. }
  105. //添加开始节点绿色
  106. PaintColor.Add(Brushes.Green);
  107. //添加中间节点
  108. bool passed = true;
  109. for (int i = 0; i < dt.Rows.Count; i++)
  110. {
  111. //如果是返工的,根据工序里的步骤判断,如果cd_detno大于当前步骤的cd_detno时候就显示白色
  112. if (ifRework != "0")
  113. {
  114. //还未开始返工
  115. if (reworkStep=="") {
  116. passed = false;
  117. }
  118. //passed==true;说明经过了这一步
  119. if (passed)
  120. {
  121. if (BadStep == dt.Rows[i]["CD_STEPCODE"].ToString())
  122. {
  123. PaintColor.Add(Brushes.Red);
  124. }
  125. else
  126. {
  127. if (!PastStep.Contains(dt.Rows[i]["CD_STEPCODE"].ToString() + "," + RejectStep) || RejectStep == "")
  128. PaintColor.Add(Brushes.Green);
  129. else
  130. {
  131. //判断之前有没有添加过黑色
  132. if (PaintColor.Contains(Brushes.Black))
  133. {
  134. //移除之前的,
  135. int index = PaintColor.IndexOf(Brushes.Black);
  136. PaintColor.RemoveAt(PaintColor.IndexOf(Brushes.Black));
  137. PaintColor.Insert(index, Brushes.Green);
  138. }
  139. PaintColor.Add(Brushes.Black);
  140. }
  141. }
  142. }
  143. //还没经过
  144. else {
  145. PaintColor.Add(Brushes.White);
  146. }
  147. //如果返工执行到了当前步
  148. if (reworkStep == dt.Rows[i]["CD_STEPCODE"].ToString())
  149. {
  150. passed = false;
  151. }
  152. }
  153. else
  154. //非返工,是正常
  155. {
  156. //包含说明是线内工序
  157. if (PastStep.Contains(dt.Rows[i]["CD_STEPCODE"].ToString()))
  158. {
  159. if (BadStep == dt.Rows[i]["CD_STEPCODE"].ToString())
  160. {
  161. PaintColor.Add(Brushes.Red);
  162. }
  163. else
  164. {
  165. if (!PastStep.Contains(dt.Rows[i]["CD_STEPCODE"].ToString() + "," + RejectStep) || RejectStep == "")
  166. PaintColor.Add(Brushes.Green);
  167. else
  168. {
  169. //判断之前有没有添加过黑色
  170. if (PaintColor.Contains(Brushes.Black))
  171. {
  172. //移除之前的,
  173. int index = PaintColor.IndexOf(Brushes.Black);
  174. PaintColor.RemoveAt(PaintColor.IndexOf(Brushes.Black));
  175. PaintColor.Insert(index, Brushes.Green);
  176. }
  177. PaintColor.Add(Brushes.Black);
  178. }
  179. }
  180. }
  181. //不包含说明是线外工序
  182. else
  183. {
  184. PaintColor.Add(Brushes.White);
  185. }
  186. }
  187. }
  188. if (ifRework != "0") {
  189. //完工添加绿色,未完工添加红色
  190. if (dh.CheckExist("Makeserial", "ms_sncode='" + sn_code.Text + "' and ms_reworkstatus='2'"))
  191. PaintColor.Add(Brushes.Green);
  192. else
  193. PaintColor.Add(Brushes.White);
  194. }
  195. else
  196. {
  197. //完工添加绿色,未完工添加红色
  198. if (dh.CheckExist("Makeserial", "ms_sncode='" + sn_code.Text + "' and ms_status='2'"))
  199. PaintColor.Add(Brushes.Green);
  200. else
  201. PaintColor.Add(Brushes.White);
  202. }
  203. Refresh();
  204. SerialPanel.Refresh();
  205. sql.Clear();
  206. sql.Append("select mp_makecode,ma_prodcode,sc_linecode,ma_craftcode,mp_sourcecode,mp_sncode,");
  207. sql.Append("mp_indate from makeprocess left join make on mp_makecode=ma_code left join source on ");
  208. sql.Append("mp_sourcecode=sc_code where mp_sncode='" + sn_code.Text + "'");
  209. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  210. BaseUtil.FillDgvWithDataTable(CraftInfDgv, dt);
  211. }
  212. else MessageBox.Show("序列号" + sn_code.Text + "不存在");
  213. }
  214. }
  215. private void SerialPanel_Paint(object sender, PaintEventArgs e)
  216. {
  217. if (Step != null)
  218. {
  219. //设置一行五个展示数量
  220. int RectangleCountEachRow = 5;
  221. int x = 40;
  222. int y = SerialPanel.Height / 10;
  223. int CurrentIndex = 0;
  224. //根据记录的数量判断行数
  225. int RowCount = (Step.Count % RectangleCountEachRow) == 0 ? (Step.Count / RectangleCountEachRow) : (Step.Count / RectangleCountEachRow) + 1;
  226. //每行的循环
  227. for (int i = 1; i <= RowCount; i++)
  228. {
  229. for (int j = CurrentIndex; j < RectangleCountEachRow * i; j++)
  230. {
  231. //创建画板
  232. Graphics g = e.Graphics;
  233. //途程节点的矩形
  234. Rectangle r;
  235. if (Step[j].Contains("开始") || Step[j].Contains("结束"))
  236. {
  237. r = new Rectangle(0, 0, 40, 40);
  238. }
  239. else
  240. r = new Rectangle();
  241. r.Width = SerialPanel.Width / 10;
  242. r.Height = SerialPanel.Height / 8;
  243. //画箭头的Pen
  244. Pen p = new Pen(Color.CadetBlue, 15);
  245. p.StartCap = LineCap.Round;
  246. p.EndCap = LineCap.ArrowAnchor;
  247. //方块内的信息
  248. Label Param = new Label();
  249. Param.Text = j + " " + Step[j];
  250. Param.Name = j + Step[j] + "_label";
  251. Param.AutoSize = true;
  252. Param.Margin = new Padding(0,0,0,0);
  253. Param.Anchor = AnchorStyles.Left;
  254. Param.Anchor = AnchorStyles.Top;
  255. //获取param的宽度和高度
  256. Graphics graphics = Graphics.FromHwnd(Param.Handle);
  257. SizeF size = graphics.MeasureString(Param.Text,Param.Font);
  258. //设定param文本框的位置
  259. //Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4);
  260. Param.Location = new Point(x+(int)(r.Width-size.Width)/2,y+(int)(r.Height-size.Height)/2);
  261. graphics.Dispose();
  262. //如果在奇数行
  263. if (i % 2 != 0)
  264. {
  265. r.Location = new Point(x, y);
  266. g.FillRectangle(PaintColor[j], r);
  267. //填充方块内的信息
  268. if (SerialPanel.Controls[Param.Name] == null)
  269. SerialPanel.Controls.Add(Param);
  270. if (j + 1 == Step.Count)
  271. break;
  272. //画箭头
  273. //如果是一行中的箭头
  274. if (j + 1 < RectangleCountEachRow * i)
  275. {
  276. g.DrawLine(p, x + r.Width + 10, y + r.Height / 2, x + ScreenWidth / (RectangleCountEachRow), y + r.Height / 2);
  277. x += ScreenWidth / RectangleCountEachRow;
  278. }
  279. //如果是行的最后一个的箭头
  280. else if (j + 1 == RectangleCountEachRow * i)
  281. {
  282. g.DrawLine(p, x + r.Width / 2, y + r.Height + 10, x + r.Width / 2, y + r.Height + r.Height);
  283. y = y + r.Height + r.Height;
  284. }
  285. }
  286. //如果在偶数行
  287. else
  288. {
  289. r.Location = new Point(x, y);
  290. g.FillRectangle(PaintColor[j], r);
  291. //填充文字信息
  292. //存在这个名称的则不进行添加
  293. if (SerialPanel.Controls[Param.Name] == null)
  294. {
  295. SerialPanel.Controls.Add(Param);
  296. }
  297. //如果最后一个的画则直接Break,不用画箭头了
  298. if (j + 1 == Step.Count)
  299. {
  300. break;
  301. }
  302. //如果不是本行的最后一个画横向的箭头
  303. if (j + 1 < RectangleCountEachRow * i)
  304. {
  305. g.DrawLine(p, (x - 10), (y + r.Height / 2), (x - ScreenWidth / RectangleCountEachRow + r.Width), (y + r.Height / 2));
  306. x -= ScreenWidth / RectangleCountEachRow;
  307. }
  308. //如果是最后一个画纵向的箭头
  309. else if (j + 1 == RectangleCountEachRow * i)
  310. {
  311. g.DrawLine(p, (x + r.Width / 2), (y + r.Height + 10), (x + r.Width / 2), (y + r.Height + r.Height));
  312. y = y + r.Height + r.Height;
  313. }
  314. }
  315. CurrentIndex = CurrentIndex + 1;
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }