Query_ExeProgress.cs 23 KB

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