Query_ExeProgress.cs 25 KB

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