using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.Special { public partial class Special_CancelCollection : Form { DataHelper dh = SystemInf.dh; LogStringBuilder sql = new LogStringBuilder(); public Special_CancelCollection() { InitializeComponent(); } private void Confirm_Click(object sender, EventArgs e) { //获取序列号的途程 DataTable dt = (DataTable)dh.ExecuteSql("select ms_id,ms_nextstepcode,ms_currentstepcode,ms_makecode,ms_status,ms_checkno,ms_craftcode,ms_prodcode,ms_stepcode from makeserial where ms_sncode='" + sn_code.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { string pr_code = dt.Rows[0]["ms_prodcode"].ToString(); string cr_code = dt.Rows[0]["ms_craftcode"].ToString(); string ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString(); string ms_makecode = dt.Rows[0]["ms_makecode"].ToString(); string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString(); string ms_checkno = dt.Rows[0]["ms_checkno"].ToString(); string ms_status = dt.Rows[0]["ms_status"].ToString(); string ms_currentstepcode = dt.Rows[0]["ms_currentstepcode"].ToString(); string ms_id = dt.Rows[0]["ms_id"].ToString(); sql.Clear(); sql.Append("select cd_stepcode from craft left join craftdetail on cr_id=cd_crid where "); sql.Append("cr_prodcode='" + pr_code + "' and cr_code='" + cr_code + "' order by cd_detno "); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (ms_stepcode == dt.Rows[0]["cd_stepcode"].ToString() || (ms_stepcode == "" && ms_nextstepcode == User.CurrentStepCode)) { List sqls = new List(); //存在不良删除不良记录 if (ms_status == "3") { sqls.Add("delete from makebad where mb_sncode='" + sn_code.Text + "' and mb_makecode='" + ms_makecode + "'"); //更新MakeCraftDetail表记录 sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty-1 where mcd_macode='" + ms_makecode + "' and mcd_stepcode='" + ms_stepcode + "'"); } else { sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1,mcd_okqty=mcd_okqty-1 where mcd_macode='" + ms_makecode + "' and mcd_stepcode='" + ms_stepcode + "'"); } if (ms_checkno != "") { //删除送检明细 sqls.Add("delete from oqcbatchdetail where obd_sncode='" + sn_code.Text + "' and obd_makecode='" + ms_makecode + "'"); //送检数量-1 sqls.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + ms_checkno + "'"); } //清除上料数据 dt = (DataTable)dh.ExecuteSql("select cm_barcode,cm_materialtype,cm_makecode,cm_stepcode from craftmaterial where cm_sncode='" + sn_code.Text + "' and cm_makecode='" + ms_makecode + "'", "select"); if (dt.Rows.Count > 0) { List barcode = new List(); for (int i = 0; i < dt.Rows.Count; i++) { barcode.Add(dt.Rows[i]["cm_barcode"].ToString()); //存在批管控的物料 if (dt.Rows[i]["cm_materialtype"].ToString() == "2") { string mss_id = dh.getFieldDataByCondition("makesourcestock", "mss_id", "mss_makecode='" + dt.Rows[i]["cm_makecode"].ToString() + "' and mss_barcode='" + dt.Rows[i]["cm_barcode"].ToString() + "' and mss_stepcode='" + dt.Rows[i]["cm_stepcode"].ToString() + "' and mss_validtime is not null and mss_invalidtime is null").ToString(); dh.UpdateByCondition("makesourcestock", "mss_remain=mss_remain+mss_baseqty,mss_useqty=mss_useqty-mss_baseqty", "mss_id='" + mss_id + "'"); } } sql.Clear(); sql.Append("update makeserial set ms_nextmacode='' where ms_sncode=:barcode and ms_nextmacode='" + ms_makecode + "'"); dh.BatchInsert(sql.GetString(), new string[] { "barcode" }, barcode.ToArray()); sqls.Add("delete from craftmaterial where cm_sncode='" + sn_code.Text + "' and cm_makecode='" + ms_makecode + "'"); } //删除打印日志 sqls.Add("delete from labelprintlog where lpl_value='" + sn_code.Text + "' and lpl_makecode='" + ms_makecode + "'"); //删除老化记录 sqls.Add("delete from AGINGRECORD where ar_sncode='" + sn_code.Text + "' and ar_macode='" + ms_makecode + "'"); //解除前一工单板的使用 sqls.Add("update makeserial set ms_nextmacode='' where ms_sncode='" + sn_code.Text + "' and ms_nextmacode='" + ms_makecode + "'"); //初始化导入数据状态 sqls.Add("update makesnlist set msl_status=0 where msl_sncode='" + sn_code.Text + "' and msl_makecode='" + ms_makecode + "' and msl_type='before'"); ////初始化号段状态 sqls.Add("update MAKESNRULEDETAIL set msd_status=0 where msd_sncode='" + sn_code.Text + "' and msd_makecode='" + ms_makecode + "' and msd_type='before'"); //清除操作日志 //sqls.Add("delete from commandlog where cl_makecode='" + ms_makecode + "' and cl_sncode='" + sn_code.Text + "'"); //删除过站记录 //sqls.Add("delete from makeprocess where mp_sncode='" + sn_code.Text + "' and mp_makecode='" + ms_makecode + "'"); //投入数-1 sqls.Add("update make set ma_inqty=ma_inqty-1 where ma_code='" + ms_makecode + "'"); //删除StepPass sqls.Add("delete from steppassed where sp_sncode='" + sn_code.Text + "' and sp_makecode='" + ms_makecode + "'"); sqls.Add("delete from makeserial where ms_id='" + ms_id + "'"); dh.ExecuteSQLTran(sqls.ToArray()); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "取消采集", "取消采集成功", sn_code.Text, ""); OperateResult.AppendText(">>序列号" + sn_code.Text + "成功解除绑定\n", Color.Green, sn_code); } else OperateResult.AppendText(">>序列号" + sn_code.Text + "不处于第一道工序,不允许取消采集\n", Color.Red, sn_code); } else OperateResult.AppendText(">>序列号" + sn_code.Text + "不存在\n", Color.Red, sn_code); } private void Clean_Click(object sender, EventArgs e) { OperateResult.Clear(); } } }