Query_ExeProgress.cs 22 KB

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