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_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.Query { public partial class Query_ExeProgress : Form { DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); //经过的步骤 string PastStep = ""; //经过的步骤 string nextStepCode = ""; //序列号对应抽检批 string checkno = ""; //拆分后的经过的步骤 Dictionary Step; List PaintColor = new List(); //屏幕高度 int ScreenWidth; //屏幕宽度 int ScreenHeight; DataTable dt; DataTable ms_id;//记录ms_id DataTable ListA;//记录数据的当前序列号和之前序列号 AutoSizeFormClass asc = new AutoSizeFormClass(); public Query_ExeProgress() { InitializeComponent(); } private void Query_ExeProgress_Load(object sender, EventArgs e) { dh = SystemInf.dh; ScreenWidth = this.Width; ScreenHeight = this.Height; asc.controllInitializeSize(this); sn_code.Focus(); } private void Query_ExeProgress_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void sn_code_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { ms_id = (DataTable)dh.ExecuteSql("select beforesn,sn from makesnrelation where beforesn='" + sn_code.Text + "' or sn='" + sn_code.Text + "'", "select"); if (ms_id.Rows.Count > 0) { //说明有过转号 ms_id = (DataTable)dh.ExecuteSql("select ms_id,ms_makecode,ms_checkno,ms_outboxcode,pr_code,pr_orispeccode from makeserial left join product on ms_prodcode = pr_code where ms_sncode='" + ms_id.Rows[0]["beforesn"].ToString() + "' or ms_sncode='" + ms_id.Rows[0]["sn"].ToString() + "' order by ms_id", "select"); } else { //没有过转号 ms_id = (DataTable)dh.ExecuteSql("select ms_id,ms_makecode,ms_checkno,ms_outboxcode,pr_code,pr_orispeccode from makeserial left join product on ms_prodcode = pr_code where ms_sncode='" + sn_code.Text + "' order by ms_id", "select"); } if (ms_id.Rows.Count == 0) { //无值则提示 MessageBox.Show("序列号" + sn_code.Text + "不存在"); return; } StringBuilder ms_ids = new StringBuilder();//存所有的ms_id //设置界面工单号 ma_code.Text = ms_id.Rows[ms_id.Rows.Count - 1]["ms_makecode"].ToString(); pr_code.Text = ms_id.Rows[ms_id.Rows.Count - 1]["pr_code"].ToString(); pr_orispeccode.Text = ms_id.Rows[ms_id.Rows.Count - 1]["pr_orispeccode"].ToString(); ms_checkno.Text = ms_id.Rows[ms_id.Rows.Count - 1]["ms_checkno"].ToString(); pallet.Text = dh.getFieldDataByCondition("mes_package_view", "v_outboxcode", "v_barcode = '"+sn_code.Text+"' and v_type = 3").ToString(); ms_outboxcode.Text = ms_id.Rows[ms_id.Rows.Count - 1]["ms_outboxcode"].ToString(); int idCount = ms_id.Rows.Count; for (int i = 0; i < idCount; i++) { ms_ids.Append("'" + ms_id.Rows[i]["ms_id"].ToString() + "',"); } ListA = (DataTable)dh.ExecuteSql("select ms_beforesn,ms_sncode,ms_firstsn,ms_makecode from makeserial where ms_id in (" + ms_ids.ToString().Substring(0, ms_ids.ToString().Length - 1) + ")", "select"); dt = (DataTable)dh.ExecuteSql("select ms_status,ms_nextstepcode,ms_paststep,ms_stepcode,ms_checkno,ms_outboxcode,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"); if (dt.Rows.Count > 0) { if (Step != null && Step.Count > 0) { Step.Clear(); SerialPanel.Controls.Clear(); PaintColor.Clear(); } string ifRework = dt.Rows[idCount - 1]["ms_ifrework"].ToString(); //执行过的步骤 PastStep = dt.Rows[idCount - 1]["ms_paststep"].ToString(); //下一步骤 nextStepCode = dt.Rows[idCount - 1]["ms_nextstepcode"].ToString(); //序列号所属抽检批 checkno = dt.Rows[idCount - 1]["ms_checkno"].ToString(); //如果为不良的时候 string BadStep = ""; string RejectStep = ""; string currentStep = ""; //先判断是否是返工的 if (ifRework != "0") { //是返工的 if (dt.Rows[idCount - 1]["ms_reworkstatus"].ToString() == "3") { BadStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString(); } else if (dt.Rows[idCount - 1]["ms_reworkstatus"].ToString() == "4") { RejectStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString(); } } else { //不是返工的 if (dt.Rows[idCount - 1]["ms_status"].ToString() == "3") { BadStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString(); } else if (dt.Rows[idCount - 1]["ms_status"].ToString() == "4") { RejectStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString(); } } currentStep = dt.Rows[idCount - 1]["ms_stepcode"].ToString(); bool flag = false;//记录返工单开始就是不良的情况 //如果只有一个单 if (idCount == 1) { //添加开始节点绿色,除了返工单 if (BadStep == "" && ((dt.Rows[idCount - 1]["ms_status"].ToString() == "3" && ifRework == "0") || (dt.Rows[idCount - 1]["ms_reworkstatus"].ToString() == "3" && ifRework == "-1"))) { PaintColor.Add(Brushes.Red); } else { PaintColor.Add(Brushes.Green); } } else//有至少两个工单,之前的工单肯定是已经完工的 { PaintColor.Add(Brushes.Green); if (BadStep == "" && ((dt.Rows[idCount - 1]["ms_status"].ToString() == "3" && ifRework == "0") || (dt.Rows[idCount - 1]["ms_reworkstatus"].ToString() == "3" && ifRework == "-1"))) { //单独记录返工前oqc判不良 flag = true; } } //查询执行过的步骤 sql.Clear(); sql.Append("select CD_DETNO,CD_STEPCODE,CD_STEPNAME,cd_ifoqc,ms_makecode,ms_id 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 in (" + ms_ids.ToString().Substring(0, ms_ids.ToString().Length - 1) + ") order by ms_id,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_STEPNAME"].ToString()); } //添加中间节点 bool passed = true; int index = 0; for (int i = 0; i < dt.Rows.Count; i++) { //正在生产的途程才算 if (dt.Rows[i]["ms_id"].ToString() == ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"].ToString()) { if (nextStepCode == dt.Rows[i]["CD_STEPCODE"].ToString()) { index = i; } } } for (int i = 0; i < dt.Rows.Count; i++) { //只考虑正在生产的途程,之前工单的途程工序必定为绿色完工 if (dt.Rows[i]["ms_id"].ToString() == ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"].ToString()) { ////下一步不在途程中,不良或者报废或者完工 if (nextStepCode == "" || nextStepCode == " ") { //返工单 if (currentStep == "") { passed = false; } //找到不良步骤 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.Black); //是报废品,后面就不执行 passed = false; } else { //通过加绿色 if (PastStep.Contains(dt.Rows[i]["CD_STEPCODE"].ToString())&&passed) { PaintColor.Add(Brushes.Green); } //不通过加白色 else { PaintColor.Add(Brushes.White); } } } ////序列号下一步不为空 else { /////SN下一步是否在途程中,是则标记 //找到下一步 if (i < index) { //已执行 //判断是否为OQC工序 if (dt.Rows[i]["cd_ifoqc"].ToString() == "-1") { string oqcpass = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno = '" + checkno + "'").ToString(); if (oqcpass == "OK") { PaintColor.Add(Brushes.Green); } else { PaintColor.Add(Brushes.White); } } else PaintColor.Add(Brushes.Green); } else { //未执行 PaintColor.Add(Brushes.White); } } } else { //就是之前生产的途程,为绿色,除了返工 if (flag && (dt.Rows[i + 1]["ms_id"].ToString() == ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"].ToString())) { PaintColor.Add(Brushes.Red); } else { PaintColor.Add(Brushes.Green); } } } if (ifRework != "0") { //完工添加绿色,未完工添加白色 if (dh.CheckExist("Makeserial", "ms_id='" + ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"] + "' and ms_reworkstatus='2'")) PaintColor.Add(Brushes.Green); else PaintColor.Add(Brushes.White); } else { //完工添加绿色,未完工添加白色 if (dh.CheckExist("Makeserial", "ms_id='" + ms_id.Rows[ms_id.Rows.Count - 1]["ms_id"] + "' and ms_status='2'")) PaintColor.Add(Brushes.Green); else PaintColor.Add(Brushes.White); } Refresh(); SerialPanel.Refresh(); StringBuilder mp_sncodes = new StringBuilder(); StringBuilder makecodes = new StringBuilder(); //拼接序列号的和工单号的 for (int i = 0; i < ListA.Rows.Count; i++) { //sql mp_sncode mp_sncodes.Append("'" + ListA.Rows[i]["ms_sncode"].ToString() + "'," + (ListA.Rows[i]["ms_firstsn"].ToString() == "" ? "" : (" '" + ListA.Rows[i]["ms_firstsn"].ToString() + "',"))); //sql ma_code makecodes.Append("'" + ListA.Rows[i]["ms_makecode"].ToString() + "',"); } sql.Clear(); sql.Append("select mp_makecode,ma_prodcode,sc_linecode,ma_craftcode,mp_sourcecode,mp_sncode,mp_stepname,"); 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 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"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BaseUtil.FillDgvWithDataTable(CraftInfDgv, dt); sql.Clear(); sql.Append("select cm_makecode,cm_soncode,pr_detail,cm_barcode,cm_stepcode,cm_stepname,cm_status,cm_indate "); sql.Append("from craftmaterial left join product on pr_code=cm_soncode "); sql.Append("left join employee on cm_inman = em_code where cm_sncode IN (" + mp_sncodes.ToString().Substring(0, mp_sncodes.ToString().Length - 1) + " ) order by cm_id asc"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BaseUtil.FillDgvWithDataTable(CraftmaterialData, 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(SerialPanel.AutoScrollPosition.X + x + (int)(r.Width - size.Width) / 2, SerialPanel.AutoScrollPosition.Y + y + (int)(r.Height - size.Height) / 2); graphics.Dispose(); //如果在奇数行 if (i % 2 != 0) { r.Location = new Point(SerialPanel.AutoScrollPosition.X + x, SerialPanel.AutoScrollPosition.Y + 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, SerialPanel.AutoScrollPosition.X + x + r.Width + 10, SerialPanel.AutoScrollPosition.Y + y + r.Height / 2, SerialPanel.AutoScrollPosition.X + x + ScreenWidth / (RectangleCountEachRow), SerialPanel.AutoScrollPosition.Y + y + r.Height / 2); x += ScreenWidth / RectangleCountEachRow; } //如果是行的最后一个的箭头 else if (j + 1 == RectangleCountEachRow * i) { g.DrawLine(p, SerialPanel.AutoScrollPosition.X + x + r.Width / 2, SerialPanel.AutoScrollPosition.Y + y + r.Height + 10, SerialPanel.AutoScrollPosition.X + x + r.Width / 2, SerialPanel.AutoScrollPosition.Y + y + r.Height + r.Height); y = y + r.Height + r.Height; } } //如果在偶数行 else { r.Location = new Point(SerialPanel.AutoScrollPosition.X + x, SerialPanel.AutoScrollPosition.Y + 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, SerialPanel.AutoScrollPosition.X + (x - 10), SerialPanel.AutoScrollPosition.Y + (y + r.Height / 2), SerialPanel.AutoScrollPosition.X + (x - ScreenWidth / RectangleCountEachRow + r.Width), SerialPanel.AutoScrollPosition.Y + (y + r.Height / 2)); x -= ScreenWidth / RectangleCountEachRow; } //如果是最后一个画纵向的箭头 else if (j + 1 == RectangleCountEachRow * i) { g.DrawLine(p, SerialPanel.AutoScrollPosition.X + (x + r.Width / 2), SerialPanel.AutoScrollPosition.Y + (y + r.Height + 10), SerialPanel.AutoScrollPosition.X + (x + r.Width / 2), SerialPanel.AutoScrollPosition.Y + (y + r.Height + r.Height)); y = y + r.Height + r.Height; } } CurrentIndex = CurrentIndex + 1; } } } } private void SerialPanel_Scroll(object sender, ScrollEventArgs e) { Graphics g = this.SerialPanel.CreateGraphics(); g.Clear(this.BackColor); SerialPanel.Refresh(); } private void barcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { dt = (DataTable)dh.ExecuteSql("select cm_sncode from craftmaterial where cm_barcode = '"+barcode.Text+ "' and cm_status =0 order by cm_id desc", "select"); if (dt.Rows.Count == 0) { MessageBox.Show("未找到此零部件对应成品SN号"); } else if (dt.Rows.Count > 1) { MessageBox.Show("此零部件为可重复件"); } else { sn_code.Text = dt.Rows[0]["cm_sncode"].ToString(); sn_code_KeyDown(this, new KeyEventArgs(Keys.Enter)); } } } } }