Query_ExeProgress.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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.Entity;
  12. using UAS_MES.PublicMethod;
  13. namespace UAS_MES.Query
  14. {
  15. public partial class Query_ExeProgress : Form
  16. {
  17. DataHelper dh;
  18. LogStringBuilder sql = new LogStringBuilder();
  19. //经过的步骤
  20. string PastStep = "";
  21. //经过的步骤
  22. string nextStepCode = "";
  23. //拆分后的经过的步骤
  24. Dictionary<int, string> Step;
  25. List<Brush> PaintColor = new List<Brush>();
  26. //屏幕高度
  27. int ScreenWidth;
  28. //屏幕宽度
  29. int ScreenHeight;
  30. DataTable dt;
  31. DataTable ms_id;//记录ms_id
  32. DataTable ListA;//记录数据的当前序列号和之前序列号
  33. AutoSizeFormClass asc = new AutoSizeFormClass();
  34. public Query_ExeProgress()
  35. {
  36. InitializeComponent();
  37. }
  38. private void Query_ExeProgress_Load(object sender, EventArgs e)
  39. {
  40. dh = SystemInf.dh;
  41. ScreenWidth = this.Width;
  42. ScreenHeight = this.Height;
  43. asc.controllInitializeSize(this);
  44. sn_code.Focus();
  45. }
  46. private void Query_ExeProgress_SizeChanged(object sender, EventArgs e)
  47. {
  48. asc.controlAutoSize(this);
  49. }
  50. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  51. {
  52. if (e.KeyCode == Keys.Enter)
  53. {
  54. ms_id = (DataTable)dh.ExecuteSql("select beforesn,sn from makesnrelation where beforesn='" + sn_code.Text + "' or sn='" + sn_code.Text + "'", "select");
  55. if (ms_id.Rows.Count > 0)
  56. {
  57. //说明有过转号
  58. ms_id = (DataTable)dh.ExecuteSql("select ms_id,ms_makecode from makeserial where ms_sncode='" + ms_id.Rows[0]["beforesn"].ToString() + "' or ms_sncode='" + ms_id.Rows[0]["sn"].ToString() + "' order by ms_id", "select");
  59. }
  60. else
  61. {
  62. //没有过转号
  63. ms_id = (DataTable)dh.ExecuteSql("select ms_id,ms_makecode from makeserial where ms_sncode='" + sn_code.Text + "' order by ms_id", "select");
  64. }
  65. if (ms_id.Rows.Count==0)
  66. {
  67. //无值则提示
  68. MessageBox.Show("序列号" + sn_code.Text + "不存在");
  69. return;
  70. }
  71. StringBuilder ms_ids = new StringBuilder();//存所有的ms_id
  72. //设置界面工单号
  73. ma_code.Text = ms_id.Rows[ms_id.Rows.Count-1]["ms_makecode"].ToString();
  74. int idCount = ms_id.Rows.Count;
  75. for (int i=0;i<idCount;i++)
  76. {
  77. ms_ids.Append("'"+ms_id.Rows[i]["ms_id"].ToString()+"',");
  78. }
  79. ListA = (DataTable)dh.ExecuteSql("select ms_beforesn,ms_sncode,ms_makecode from makeserial where ms_id in ("+ms_ids.ToString().Substring(0,ms_ids.ToString().Length-1)+")","select");
  80. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_nextstepcode,ms_paststep,ms_stepcode,NVL(ms_ifrework, 0) ms_ifrework,NVL(ms_reworkstatus, 0) ms_reworkstatus from makeserial where ms_id in (" + ms_ids.ToString().Substring(0, ms_ids.ToString().Length - 1) + ") order by ms_id", "select");
  81. if (dt.Rows.Count > 0)
  82. {
  83. if (Step != null && Step.Count > 0)
  84. {
  85. Step.Clear();
  86. SerialPanel.Controls.Clear();
  87. PaintColor.Clear();
  88. }
  89. string ifRework = dt.Rows[idCount-1]["ms_ifrework"].ToString();
  90. //执行过的步骤
  91. PastStep = dt.Rows[idCount - 1]["ms_paststep"].ToString();
  92. //下一步骤
  93. nextStepCode = dt.Rows[idCount - 1]["ms_nextstepcode"].ToString();
  94. //如果为不良的时候
  95. string BadStep = "";
  96. string RejectStep = "";
  97. string currentStep = "";
  98. //先判断是否是返工的
  99. if (ifRework != "0")
  100. {
  101. //是返工的
  102. if (dt.Rows[idCount - 1]["ms_reworkstatus"].ToString() == "3")
  103. {
  104. BadStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString();
  105. }
  106. else if (dt.Rows[idCount - 1]["ms_reworkstatus"].ToString() == "4")
  107. {
  108. RejectStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString();
  109. }
  110. }
  111. else
  112. {
  113. //不是返工的
  114. if (dt.Rows[idCount - 1]["ms_status"].ToString() == "3")
  115. {
  116. BadStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString();
  117. }
  118. else if (dt.Rows[idCount - 1]["ms_status"].ToString() == "4")
  119. {
  120. RejectStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString();
  121. }
  122. }
  123. currentStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString();
  124. bool flag = false;//记录返工单开始就是不良的情况
  125. //如果只有一个单
  126. if (idCount == 1)
  127. {
  128. //添加开始节点绿色,除了返工单
  129. if (BadStep == "" && ((dt.Rows[idCount - 1]["ms_status"].ToString() == "3" && ifRework == "0") || (dt.Rows[idCount - 1]["ms_reworkstatus"].ToString() == "3" && ifRework == "-1")))
  130. {
  131. PaintColor.Add(Brushes.Red);
  132. }
  133. else
  134. {
  135. PaintColor.Add(Brushes.Green);
  136. }
  137. }
  138. else//有至少两个工单,之前的工单肯定是已经完工的
  139. {
  140. PaintColor.Add(Brushes.Green);
  141. if (BadStep == "" && ((dt.Rows[idCount - 1]["ms_status"].ToString() == "3" && ifRework == "0") || (dt.Rows[idCount - 1]["ms_reworkstatus"].ToString() == "3" && ifRework == "-1")))
  142. {
  143. //单独记录返工前oqc判不良
  144. flag = true;
  145. }
  146. }
  147. //查询执行过的步骤
  148. sql.Clear();
  149. sql.Append("select CD_DETNO,CD_STEPCODE,ms_makecode,ms_id from craft left join craftdetail on cd_crid = cr_id left join makeserial ");
  150. sql.Append("on ms_craftcode=cr_code and ms_prodcode=cr_prodcode where ms_id in (" + ms_ids.ToString().Substring(0, ms_ids.ToString().Length - 1) + ") order by ms_id,cd_detno");
  151. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  152. Step = new Dictionary<int, string>();
  153. for (int i = 0; i < dt.Rows.Count + 2; i++)
  154. {
  155. if (i == 0)
  156. Step.Add(i, "开始");
  157. else if (i == dt.Rows.Count + 1)
  158. Step.Add(i, "结束");
  159. else
  160. Step.Add(i, dt.Rows[i - 1]["CD_STEPCODE"].ToString());
  161. }
  162. //添加中间节点
  163. bool passed = true;
  164. int index = 0;
  165. for (int i = 0; i < dt.Rows.Count; i++)
  166. {
  167. //正在生产的途程才算
  168. if (dt.Rows[i]["ms_id"].ToString()==ms_id.Rows[ms_id.Rows.Count-1]["ms_id"].ToString())
  169. {
  170. if (nextStepCode == dt.Rows[i]["CD_STEPCODE"].ToString())
  171. {
  172. index = i;
  173. }
  174. }
  175. }
  176. for (int i = 0; i < dt.Rows.Count; i++)
  177. {
  178. //只考虑正在生产的途程,之前工单的途程工序必定为绿色完工
  179. if (dt.Rows[i]["ms_id"].ToString() == ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"].ToString())
  180. {
  181. ////下一步不在途程中,不良或者报废或者完工
  182. if (nextStepCode == "" || nextStepCode == " ")
  183. {
  184. //返工单
  185. if (currentStep == "")
  186. {
  187. passed = false;
  188. }
  189. //找到不良步骤
  190. if (BadStep == dt.Rows[i]["CD_STEPCODE"].ToString())
  191. {
  192. PaintColor.Add(Brushes.Red);
  193. //是不良品,后面就不执行
  194. passed = false;
  195. }
  196. //找到报废步骤
  197. else if (PastStep.Contains(dt.Rows[i]["CD_STEPCODE"].ToString() + "," + RejectStep) && RejectStep != "")
  198. {
  199. PaintColor.Add(Brushes.Black);
  200. //是报废品,后面就不执行
  201. passed = false;
  202. }
  203. else
  204. {
  205. //通过加绿色
  206. if (PastStep.Contains(dt.Rows[i]["CD_STEPCODE"].ToString()))
  207. {
  208. PaintColor.Add(Brushes.Green);
  209. }
  210. //不通过加白色
  211. else
  212. {
  213. PaintColor.Add(Brushes.White);
  214. }
  215. }
  216. }
  217. ////序列号下一步不为空
  218. else
  219. {
  220. /////SN下一步是否在途程中,是则标记
  221. //找到下一步
  222. if (i < index)
  223. {
  224. //已执行
  225. PaintColor.Add(Brushes.Green);
  226. }
  227. else
  228. {
  229. //未执行
  230. PaintColor.Add(Brushes.White);
  231. }
  232. }
  233. }
  234. else
  235. {
  236. //就是之前生产的途程,为绿色,除了返工
  237. if (flag && (dt.Rows[i + 1]["ms_id"].ToString() == ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"].ToString()))
  238. {
  239. PaintColor.Add(Brushes.Red);
  240. }
  241. else
  242. {
  243. PaintColor.Add(Brushes.Green);
  244. }
  245. }
  246. }
  247. if (ifRework != "0")
  248. {
  249. //完工添加绿色,未完工添加白色
  250. if (dh.CheckExist("Makeserial", "ms_id='" + ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"] + "' and ms_reworkstatus='2'"))
  251. PaintColor.Add(Brushes.Green);
  252. else
  253. PaintColor.Add(Brushes.White);
  254. }
  255. else
  256. {
  257. //完工添加绿色,未完工添加白色
  258. if (dh.CheckExist("Makeserial", "ms_id='" + ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"] + "' and ms_status='2'"))
  259. PaintColor.Add(Brushes.Green);
  260. else
  261. PaintColor.Add(Brushes.White);
  262. }
  263. Refresh();
  264. SerialPanel.Refresh();
  265. StringBuilder mp_sncodes = new StringBuilder();
  266. StringBuilder makecodes = new StringBuilder();
  267. //拼接序列号的和工单号的
  268. for (int i=0;i<ListA.Rows.Count;i++)
  269. {
  270. //sql mp_sncode
  271. mp_sncodes.Append("'" + ListA.Rows[i]["ms_sncode"].ToString() + "',"+(ListA.Rows[i]["ms_beforesn"].ToString()==""?"":(" '"+ListA.Rows[i]["ms_beforesn"].ToString()+"',")));
  272. //sql ma_code
  273. makecodes.Append("'"+ListA.Rows[i]["ms_makecode"].ToString()+"',");
  274. }
  275. sql.Clear();
  276. sql.Append("select mp_makecode,ma_prodcode,sc_linecode,ma_craftcode,mp_sourcecode,mp_sncode,");
  277. 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 ");
  278. sql.Append("mp_sourcecode=sc_code where mp_sncode in ("+mp_sncodes.ToString().Substring(0,mp_sncodes.ToString().Length-1)+") and ma_code in (" + makecodes.ToString().Substring(0,makecodes.ToString().Length-1)+ ") order by mp_indate");
  279. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  280. BaseUtil.FillDgvWithDataTable(CraftInfDgv, dt);
  281. }
  282. else MessageBox.Show("序列号" + sn_code.Text + "不存在");
  283. }
  284. }
  285. private void SerialPanel_Paint(object sender, PaintEventArgs e)
  286. {
  287. if (Step != null)
  288. {
  289. //设置一行五个展示数量
  290. int RectangleCountEachRow = 5;
  291. int x = 40;
  292. int y = SerialPanel.Height / 10;
  293. int CurrentIndex = 0;
  294. //根据记录的数量判断行数
  295. int RowCount = (Step.Count % RectangleCountEachRow) == 0 ? (Step.Count / RectangleCountEachRow) : (Step.Count / RectangleCountEachRow) + 1;
  296. //每行的循环
  297. for (int i = 1; i <= RowCount; i++)
  298. {
  299. for (int j = CurrentIndex; j < RectangleCountEachRow * i; j++)
  300. {
  301. //创建画板
  302. Graphics g = e.Graphics;
  303. //途程节点的矩形
  304. Rectangle r;
  305. if (Step[j].Contains("开始") || Step[j].Contains("结束"))
  306. {
  307. r = new Rectangle(0, 0, 40, 40);
  308. }
  309. else
  310. r = new Rectangle();
  311. r.Width = SerialPanel.Width / 10;
  312. r.Height = SerialPanel.Height / 8;
  313. //画箭头的Pen
  314. Pen p = new Pen(Color.CadetBlue, 15);
  315. p.StartCap = LineCap.Round;
  316. p.EndCap = LineCap.ArrowAnchor;
  317. //方块内的信息
  318. Label Param = new Label();
  319. Param.Text = j + " " + Step[j];
  320. Param.Name = j + Step[j] + "_label";
  321. Param.AutoSize = true;
  322. Param.Margin = new Padding(0, 0, 0, 0);
  323. Param.Anchor = AnchorStyles.Left;
  324. Param.Anchor = AnchorStyles.Top;
  325. //获取param的宽度和高度
  326. Graphics graphics = Graphics.FromHwnd(Param.Handle);
  327. SizeF size = graphics.MeasureString(Param.Text, Param.Font);
  328. //设定param文本框的位置
  329. //Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4);
  330. Param.Location = new Point(SerialPanel.AutoScrollPosition.X + x + (int)(r.Width - size.Width) / 2, SerialPanel.AutoScrollPosition.Y + y + (int)(r.Height - size.Height) / 2);
  331. graphics.Dispose();
  332. //如果在奇数行
  333. if (i % 2 != 0)
  334. {
  335. r.Location = new Point(SerialPanel.AutoScrollPosition.X + x, SerialPanel.AutoScrollPosition.Y + y);
  336. g.FillRectangle(PaintColor[j], r);
  337. //填充方块内的信息
  338. if (SerialPanel.Controls[Param.Name] == null)
  339. SerialPanel.Controls.Add(Param);
  340. if (j + 1 == Step.Count)
  341. break;
  342. //画箭头
  343. //如果是一行中的箭头
  344. if (j + 1 < RectangleCountEachRow * i)
  345. {
  346. g.DrawLine(p, SerialPanel.AutoScrollPosition.X+ x + r.Width + 10, SerialPanel.AutoScrollPosition.Y + y + r.Height / 2, SerialPanel.AutoScrollPosition.X + x + ScreenWidth / (RectangleCountEachRow), SerialPanel.AutoScrollPosition.Y + y + r.Height / 2);
  347. x += ScreenWidth / RectangleCountEachRow;
  348. }
  349. //如果是行的最后一个的箭头
  350. else if (j + 1 == RectangleCountEachRow * i)
  351. {
  352. g.DrawLine(p, SerialPanel.AutoScrollPosition.X + x + r.Width / 2, SerialPanel.AutoScrollPosition.Y + y + r.Height + 10, SerialPanel.AutoScrollPosition.X + x + r.Width / 2, SerialPanel.AutoScrollPosition.Y + y + r.Height + r.Height);
  353. y = y + r.Height + r.Height;
  354. }
  355. }
  356. //如果在偶数行
  357. else
  358. {
  359. r.Location = new Point(SerialPanel.AutoScrollPosition.X + x, SerialPanel.AutoScrollPosition.Y + y);
  360. g.FillRectangle(PaintColor[j], r);
  361. //填充文字信息
  362. //存在这个名称的则不进行添加
  363. if (SerialPanel.Controls[Param.Name] == null)
  364. {
  365. SerialPanel.Controls.Add(Param);
  366. }
  367. //如果最后一个的画则直接Break,不用画箭头了
  368. if (j + 1 == Step.Count)
  369. {
  370. break;
  371. }
  372. //如果不是本行的最后一个画横向的箭头
  373. if (j + 1 < RectangleCountEachRow * i)
  374. {
  375. g.DrawLine(p, SerialPanel.AutoScrollPosition.X + (x - 10), SerialPanel.AutoScrollPosition.Y + (y + r.Height / 2), SerialPanel.AutoScrollPosition.X + (x - ScreenWidth / RectangleCountEachRow + r.Width), SerialPanel.AutoScrollPosition.Y + (y + r.Height / 2));
  376. x -= ScreenWidth / RectangleCountEachRow;
  377. }
  378. //如果是最后一个画纵向的箭头
  379. else if (j + 1 == RectangleCountEachRow * i)
  380. {
  381. g.DrawLine(p, SerialPanel.AutoScrollPosition.X + (x + r.Width / 2), SerialPanel.AutoScrollPosition.Y + (y + r.Height + 10), SerialPanel.AutoScrollPosition.X + (x + r.Width / 2), SerialPanel.AutoScrollPosition.Y + (y + r.Height + r.Height));
  382. y = y + r.Height + r.Height;
  383. }
  384. }
  385. CurrentIndex = CurrentIndex + 1;
  386. }
  387. }
  388. }
  389. }
  390. private void SerialPanel_Scroll(object sender, ScrollEventArgs e)
  391. {
  392. Graphics g = this.SerialPanel.CreateGraphics();
  393. g.Clear(this.BackColor);
  394. SerialPanel.Refresh();
  395. }
  396. }
  397. }