Query_ExeProgress.cs 24 KB

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