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; //屏幕高度 int ScreenWidth; //屏幕宽度 int ScreenHeight; DataTable dt; public Query_ExeProgress() { InitializeComponent(); } private void 工单执行进度_Load(object sender, EventArgs e) { dh = new DataHelper(); ScreenWidth = this.Width; ScreenHeight = this.Height; } private void 工单执行进度_SizeChanged(object sender, EventArgs e) { } private void sn_code_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (Step != null && Step.Count > 0) { for (int i = 0; i < Step.Count; i++) { Controls.Remove(Controls[i + Step[i] + "_label"]); } } //查询执行过的步骤 sql.Clear(); sql.Append("select CD_DETNO, CD_STEPCODE from craft left join craftdetail on cd_crid = cr_id where "); sql.Append("cr_code=(select ms_craftcode from makeserial where ms_sncode='" + sn_code.Text + "') order by cd_detno"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); Step = new Dictionary(); PastStep = dh.getFieldDataByCondition("makeserial", "ms_paststep", "ms_sncode='" + sn_code.Text + "'").ToString(); 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()); } Refresh(); } } 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.Anchor = AnchorStyles.Left; Param.Anchor = AnchorStyles.Top; Param.Location = new Point(x + r.Width / 14 * RectangleCountEachRow, y + r.Height / 10 * 4); //如果在奇数行 if (i % 2 != 0) { r.Location = new Point(x, y); if (PastStep.Contains(Step[j])) { g.FillRectangle(Brushes.Green, r); } else { if (Step[j].Contains("开始") || Step[j].Contains("结束")) g.FillEllipse(Brushes.Green, r); else g.FillRectangle(Brushes.White, r); } //填充方块内的信息 if (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); if (PastStep.Contains(Step[j])) { g.FillRectangle(Brushes.Green, r); } else { if (Step[j].Contains("开始") || Step[j].Contains("结束")) { g.FillEllipse(Brushes.Green, r); } else { g.FillRectangle(Brushes.White, r); } } //填充文字信息 //存在这个名称的则不进行添加 if (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; } } } } } }