Query_ExeProgress.cs 19 KB

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