Query_ExeProgress.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 currentStep = "";
  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. }
  77. else
  78. {
  79. //不是返工的
  80. if (dt.Rows[0]["ms_status"].ToString() == "3")
  81. {
  82. BadStep = dt.Rows[0]["ms_stepcode"].ToString();
  83. }
  84. else if (dt.Rows[0]["ms_status"].ToString() == "4")
  85. {
  86. RejectStep = dt.Rows[0]["ms_stepcode"].ToString();
  87. }
  88. }
  89. currentStep= dt.Rows[0]["ms_stepcode"].ToString();
  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. //还未开始返工
  112. if (currentStep == "")
  113. {
  114. passed = false;
  115. }
  116. //passed==true;说明经过了这一步
  117. if (passed)
  118. {
  119. if (BadStep == dt.Rows[i]["CD_STEPCODE"].ToString())
  120. {
  121. PaintColor.Add(Brushes.Red);
  122. //是不良品,后面就不执行
  123. passed = false;
  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. passed = false;
  142. }
  143. }
  144. }
  145. //还没经过
  146. else
  147. {
  148. PaintColor.Add(Brushes.White);
  149. }
  150. //如果返工执行到了当前步
  151. if (currentStep==dt.Rows[i]["CD_STEPCODE"].ToString()) {
  152. passed = false;
  153. }
  154. }
  155. if (ifRework != "0") {
  156. //完工添加绿色,未完工添加红色
  157. if (dh.CheckExist("Makeserial", "ms_sncode='" + sn_code.Text + "' and ms_reworkstatus='2'"))
  158. PaintColor.Add(Brushes.Green);
  159. else
  160. PaintColor.Add(Brushes.White);
  161. }
  162. else
  163. {
  164. //完工添加绿色,未完工添加红色
  165. if (dh.CheckExist("Makeserial", "ms_sncode='" + sn_code.Text + "' and ms_status='2'"))
  166. PaintColor.Add(Brushes.Green);
  167. else
  168. PaintColor.Add(Brushes.White);
  169. }
  170. Refresh();
  171. SerialPanel.Refresh();
  172. sql.Clear();
  173. sql.Append("select mp_makecode,ma_prodcode,sc_linecode,ma_craftcode,mp_sourcecode,mp_sncode,");
  174. sql.Append("mp_indate,mp_inman,em_name from makeprocess left join make on mp_makecode=ma_code left join employee on mp_inman = em_code left join source on ");
  175. sql.Append("mp_sourcecode=sc_code where mp_sncode='" + sn_code.Text + "'");
  176. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  177. BaseUtil.FillDgvWithDataTable(CraftInfDgv, dt);
  178. }
  179. else MessageBox.Show("序列号" + sn_code.Text + "不存在");
  180. }
  181. }
  182. private void SerialPanel_Paint(object sender, PaintEventArgs e)
  183. {
  184. if (Step != null)
  185. {
  186. //设置一行五个展示数量
  187. int RectangleCountEachRow = 5;
  188. int x = 40;
  189. int y = SerialPanel.Height / 10;
  190. int CurrentIndex = 0;
  191. //根据记录的数量判断行数
  192. int RowCount = (Step.Count % RectangleCountEachRow) == 0 ? (Step.Count / RectangleCountEachRow) : (Step.Count / RectangleCountEachRow) + 1;
  193. //每行的循环
  194. for (int i = 1; i <= RowCount; i++)
  195. {
  196. for (int j = CurrentIndex; j < RectangleCountEachRow * i; j++)
  197. {
  198. //创建画板
  199. Graphics g = e.Graphics;
  200. //途程节点的矩形
  201. Rectangle r;
  202. if (Step[j].Contains("开始") || Step[j].Contains("结束"))
  203. {
  204. r = new Rectangle(0, 0, 40, 40);
  205. }
  206. else
  207. r = new Rectangle();
  208. r.Width = SerialPanel.Width / 10;
  209. r.Height = SerialPanel.Height / 8;
  210. //画箭头的Pen
  211. Pen p = new Pen(Color.CadetBlue, 15);
  212. p.StartCap = LineCap.Round;
  213. p.EndCap = LineCap.ArrowAnchor;
  214. //方块内的信息
  215. Label Param = new Label();
  216. Param.Text = j + " " + Step[j];
  217. Param.Name = j + Step[j] + "_label";
  218. Param.AutoSize = true;
  219. Param.Margin = new Padding(0,0,0,0);
  220. Param.Anchor = AnchorStyles.Left;
  221. Param.Anchor = AnchorStyles.Top;
  222. //获取param的宽度和高度
  223. Graphics graphics = Graphics.FromHwnd(Param.Handle);
  224. SizeF size = graphics.MeasureString(Param.Text,Param.Font);
  225. //设定param文本框的位置
  226. //Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4);
  227. Param.Location = new Point(x+(int)(r.Width-size.Width)/2,y+(int)(r.Height-size.Height)/2);
  228. graphics.Dispose();
  229. //如果在奇数行
  230. if (i % 2 != 0)
  231. {
  232. r.Location = new Point(x, y);
  233. g.FillRectangle(PaintColor[j], r);
  234. //填充方块内的信息
  235. if (SerialPanel.Controls[Param.Name] == null)
  236. SerialPanel.Controls.Add(Param);
  237. if (j + 1 == Step.Count)
  238. break;
  239. //画箭头
  240. //如果是一行中的箭头
  241. if (j + 1 < RectangleCountEachRow * i)
  242. {
  243. g.DrawLine(p, x + r.Width + 10, y + r.Height / 2, x + ScreenWidth / (RectangleCountEachRow), y + r.Height / 2);
  244. x += ScreenWidth / RectangleCountEachRow;
  245. }
  246. //如果是行的最后一个的箭头
  247. else if (j + 1 == RectangleCountEachRow * i)
  248. {
  249. g.DrawLine(p, x + r.Width / 2, y + r.Height + 10, x + r.Width / 2, y + r.Height + r.Height);
  250. y = y + r.Height + r.Height;
  251. }
  252. }
  253. //如果在偶数行
  254. else
  255. {
  256. r.Location = new Point(x, y);
  257. g.FillRectangle(PaintColor[j], r);
  258. //填充文字信息
  259. //存在这个名称的则不进行添加
  260. if (SerialPanel.Controls[Param.Name] == null)
  261. {
  262. SerialPanel.Controls.Add(Param);
  263. }
  264. //如果最后一个的画则直接Break,不用画箭头了
  265. if (j + 1 == Step.Count)
  266. {
  267. break;
  268. }
  269. //如果不是本行的最后一个画横向的箭头
  270. if (j + 1 < RectangleCountEachRow * i)
  271. {
  272. g.DrawLine(p, (x - 10), (y + r.Height / 2), (x - ScreenWidth / RectangleCountEachRow + r.Width), (y + r.Height / 2));
  273. x -= ScreenWidth / RectangleCountEachRow;
  274. }
  275. //如果是最后一个画纵向的箭头
  276. else if (j + 1 == RectangleCountEachRow * i)
  277. {
  278. g.DrawLine(p, (x + r.Width / 2), (y + r.Height + 10), (x + r.Width / 2), (y + r.Height + r.Height));
  279. y = y + r.Height + r.Height;
  280. }
  281. }
  282. CurrentIndex = CurrentIndex + 1;
  283. }
  284. }
  285. }
  286. }
  287. }
  288. }