Query_ExeProgress.cs 24 KB

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