| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- 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<int, string> Step;
- List<Brush> PaintColor = new List<Brush>();
- //屏幕高度
- 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)
- {
- string ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id) ms_id", "ms_sncode='" + sn_code.Text + "'").ToString();
- 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_id='" + ms_id + "'", "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,ms_makecode 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_id='" + ms_id + "' order by cd_detno");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- Step = new Dictionary<int, string>();
- 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 (currentStep==dt.Rows[i]["CD_STEPCODE"].ToString()) {
- passed = false;
- }
- }
- if (ifRework != "0") {
- //完工添加绿色,未完工添加红色
- if (dh.CheckExist("Makeserial", "ms_id='" + ms_id + "' and ms_reworkstatus='2'"))
- PaintColor.Add(Brushes.Green);
- else
- PaintColor.Add(Brushes.White);
- }
- else
- {
- //完工添加绿色,未完工添加红色
- if (dh.CheckExist("Makeserial", "ms_id='" + ms_id + "' 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,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 ");
- sql.Append("mp_sourcecode=sc_code where mp_sncode='" + sn_code.Text + "' and ma_code='"+dt.Rows[0]["ms_makecode"].ToString()+"'");
- 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;
- }
- }
- }
- }
- }
- }
|