Query_ExeProgress.cs 22 KB

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