Query_ExeProgress.cs 20 KB

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