Query_ExeProgress.cs 24 KB

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