Query_ExeProgress.cs 14 KB

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