Query_ExeProgress.cs 21 KB

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