using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms; using UAS_MES.DataOperate; using UAS_MES.PublicMethod; namespace UAS_MES.Query { public partial class Query_ExeProgress : Form { DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); //经过的步骤 string PastStep = ""; //拆分后的经过的步骤 Dictionary Step; List PaintColor = new List(); //屏幕高度 int ScreenWidth; //屏幕宽度 int ScreenHeight; DataTable dt; AutoSizeFormClass asc = new AutoSizeFormClass(); public Query_ExeProgress() { InitializeComponent(); } private void 工单执行进度_Load(object sender, EventArgs e) { dh = new DataHelper(); ScreenWidth = this.Width; ScreenHeight = this.Height; asc.controllInitializeSize(this); } private void 工单执行进度_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void sn_code_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { dt = (DataTable)dh.ExecuteSql("select ms_status,ms_paststep,ms_stepcode,NVL(ms_ifrework, 0) ms_ifrework,NVL(ms_reworkstatus, 0) ms_reworkstatus from makeserial where ms_sncode='" + sn_code.Text + "'", "select"); if (dt.Rows.Count > 0) { if (Step != null && Step.Count > 0) { Step.Clear(); SerialPanel.Controls.Clear(); PaintColor.Clear(); } string ifRework = dt.Rows[0]["ms_ifrework"].ToString(); //执行过的步骤 PastStep = dt.Rows[0]["ms_paststep"].ToString(); //如果为不良的时候 string BadStep = ""; string RejectStep = ""; string currentStep = ""; //先判断是否是返工的 if (ifRework!= "0") { //是返工的 if (dt.Rows[0]["ms_reworkstatus"].ToString() == "3") { BadStep = dt.Rows[0]["ms_stepcode"].ToString(); } else if (dt.Rows[0]["ms_reworkstatus"].ToString() == "4") { RejectStep = dt.Rows[0]["ms_stepcode"].ToString(); } } else { //不是返工的 if (dt.Rows[0]["ms_status"].ToString() == "3") { BadStep = dt.Rows[0]["ms_stepcode"].ToString(); } else if (dt.Rows[0]["ms_status"].ToString() == "4") { RejectStep = dt.Rows[0]["ms_stepcode"].ToString(); } } currentStep= dt.Rows[0]["ms_stepcode"].ToString(); //查询执行过的步骤 sql.Clear(); sql.Append("select CD_DETNO,CD_STEPCODE from craft left join craftdetail on cd_crid = cr_id left join makeserial "); sql.Append("on ms_craftcode=cr_code and ms_prodcode=cr_prodcode where ms_sncode='" + sn_code.Text + "' order by cd_detno"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); Step = new Dictionary(); for (int i = 0; i < dt.Rows.Count + 2; i++) { if (i == 0) Step.Add(i, "开始"); else if (i == dt.Rows.Count + 1) Step.Add(i, "结束"); else Step.Add(i, dt.Rows[i - 1]["CD_STEPCODE"].ToString()); } //添加开始节点绿色 PaintColor.Add(Brushes.Green); //添加中间节点 bool passed = true; for (int i = 0; i < dt.Rows.Count; i++) { //还未开始返工 if (currentStep == "") { passed = false; } //passed==true;说明经过了这一步 if (passed) { if (BadStep == dt.Rows[i]["CD_STEPCODE"].ToString()) { PaintColor.Add(Brushes.Red); //是不良品,后面就不执行 passed = false; } else { if (!PastStep.Contains(dt.Rows[i]["CD_STEPCODE"].ToString() + "," + RejectStep) || RejectStep == "") PaintColor.Add(Brushes.Green); else { //判断之前有没有添加过黑色 if (PaintColor.Contains(Brushes.Black)) { //移除之前的, int index = PaintColor.IndexOf(Brushes.Black); PaintColor.RemoveAt(PaintColor.IndexOf(Brushes.Black)); PaintColor.Insert(index, Brushes.Green); } PaintColor.Add(Brushes.Black); //是报废品,后面也不执行 passed = false; } } } //还没经过 else { PaintColor.Add(Brushes.White); } } if (ifRework != "0") { //完工添加绿色,未完工添加红色 if (dh.CheckExist("Makeserial", "ms_sncode='" + sn_code.Text + "' and ms_reworkstatus='2'")) PaintColor.Add(Brushes.Green); else PaintColor.Add(Brushes.White); } else { //完工添加绿色,未完工添加红色 if (dh.CheckExist("Makeserial", "ms_sncode='" + sn_code.Text + "' and ms_status='2'")) PaintColor.Add(Brushes.Green); else PaintColor.Add(Brushes.White); } Refresh(); SerialPanel.Refresh(); sql.Clear(); sql.Append("select mp_makecode,ma_prodcode,sc_linecode,ma_craftcode,mp_sourcecode,mp_sncode,"); sql.Append("mp_indate from makeprocess left join make on mp_makecode=ma_code left join source on "); sql.Append("mp_sourcecode=sc_code where mp_sncode='" + sn_code.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BaseUtil.FillDgvWithDataTable(CraftInfDgv, dt); } else MessageBox.Show("序列号" + sn_code.Text + "不存在"); } } private void SerialPanel_Paint(object sender, PaintEventArgs e) { if (Step != null) { //设置一行五个展示数量 int RectangleCountEachRow = 5; int x = 40; int y = SerialPanel.Height / 10; int CurrentIndex = 0; //根据记录的数量判断行数 int RowCount = (Step.Count % RectangleCountEachRow) == 0 ? (Step.Count / RectangleCountEachRow) : (Step.Count / RectangleCountEachRow) + 1; //每行的循环 for (int i = 1; i <= RowCount; i++) { for (int j = CurrentIndex; j < RectangleCountEachRow * i; j++) { //创建画板 Graphics g = e.Graphics; //途程节点的矩形 Rectangle r; if (Step[j].Contains("开始") || Step[j].Contains("结束")) { r = new Rectangle(0, 0, 40, 40); } else r = new Rectangle(); r.Width = SerialPanel.Width / 10; r.Height = SerialPanel.Height / 8; //画箭头的Pen Pen p = new Pen(Color.CadetBlue, 15); p.StartCap = LineCap.Round; p.EndCap = LineCap.ArrowAnchor; //方块内的信息 Label Param = new Label(); Param.Text = j + " " + Step[j]; Param.Name = j + Step[j] + "_label"; Param.AutoSize = true; Param.Margin = new Padding(0,0,0,0); Param.Anchor = AnchorStyles.Left; Param.Anchor = AnchorStyles.Top; //获取param的宽度和高度 Graphics graphics = Graphics.FromHwnd(Param.Handle); SizeF size = graphics.MeasureString(Param.Text,Param.Font); //设定param文本框的位置 //Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4); Param.Location = new Point(x+(int)(r.Width-size.Width)/2,y+(int)(r.Height-size.Height)/2); graphics.Dispose(); //如果在奇数行 if (i % 2 != 0) { r.Location = new Point(x, y); g.FillRectangle(PaintColor[j], r); //填充方块内的信息 if (SerialPanel.Controls[Param.Name] == null) SerialPanel.Controls.Add(Param); if (j + 1 == Step.Count) break; //画箭头 //如果是一行中的箭头 if (j + 1 < RectangleCountEachRow * i) { g.DrawLine(p, x + r.Width + 10, y + r.Height / 2, x + ScreenWidth / (RectangleCountEachRow), y + r.Height / 2); x += ScreenWidth / RectangleCountEachRow; } //如果是行的最后一个的箭头 else if (j + 1 == RectangleCountEachRow * i) { g.DrawLine(p, x + r.Width / 2, y + r.Height + 10, x + r.Width / 2, y + r.Height + r.Height); y = y + r.Height + r.Height; } } //如果在偶数行 else { r.Location = new Point(x, y); g.FillRectangle(PaintColor[j], r); //填充文字信息 //存在这个名称的则不进行添加 if (SerialPanel.Controls[Param.Name] == null) { SerialPanel.Controls.Add(Param); } //如果最后一个的画则直接Break,不用画箭头了 if (j + 1 == Step.Count) { break; } //如果不是本行的最后一个画横向的箭头 if (j + 1 < RectangleCountEachRow * i) { g.DrawLine(p, (x - 10), (y + r.Height / 2), (x - ScreenWidth / RectangleCountEachRow + r.Width), (y + r.Height / 2)); x -= ScreenWidth / RectangleCountEachRow; } //如果是最后一个画纵向的箭头 else if (j + 1 == RectangleCountEachRow * i) { g.DrawLine(p, (x + r.Width / 2), (y + r.Height + 10), (x + r.Width / 2), (y + r.Height + r.Height)); y = y + r.Height + r.Height; } } CurrentIndex = CurrentIndex + 1; } } } } } }