Query_ExeProgress.cs 18 KB

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