using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; 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.Make { public partial class Make_Decompose : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); DataTable dt; DataTable dt1; DataTable dtbar; DataTable dtst; LogStringBuilder sql = new LogStringBuilder(); DataHelper dh; //记录当前序列号的ms_id string ms_id; //采集计数 int count; //Bom版本 string ma_bomversion; int rowindex; Make_NewBadCode_DE badcode; //记录当前输入框的值 string sncode_1; string sncode_2; string[] bccode; string[] bgcode; string[] id; public Make_Decompose() { InitializeComponent(); } private void Make_Decompose_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); sn_code.Focus(); OperateResult.AppendText(">>请输入序列号\n"); count = 0; deccount.Text = count + ""; dh = SystemInf.dh; } private void sn_code_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sn_code.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { sn_code.Text = dt.Rows[0]["ms_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sn_code.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { sn_code.Text = dt.Rows[0]["ms_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sn_code.Text + "' order by mil_id desc", "select"); if (dt.Rows.Count > 0) { sn_code.Text = dt.Rows[0]["mil_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sn_code.Text + "' order by mil_id desc", "select"); if (dt.Rows.Count > 0) { sn_code.Text = dt.Rows[0]["mil_sncode"].ToString(); } } } } sql.Clear(); sql.Append("select max(ms_id) from makeserial where ms_sncode ='" + sn_code.Text + "' or ms_sncode = (select max(SN)"); sql.Append(" from makesnrelation left join makeserial on ms_makecode=makecode where beforesn='" + sn_code.Text + "')"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); ms_id = dt.Rows[0][0].ToString(); sncode_1 = sn_code.Text; BaseUtil.CleanForm(this); deccount.Text = count + ""; if (ms_id != "") { sql.Clear(); sql.Append("select ms_id,ms_status,ms_makecode,ms_prodcode,pr_detail pr_name,ms_sncode,ms_firstsn,ms_craftcode,ms_craftname,ms_wccode from makeserial left join product on pr_code=ms_prodcode where ms_id='" + ms_id + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows[0]["ms_status"].ToString() == "0" || dt.Rows[0]["ms_status"].ToString() == "3") { BaseUtil.SetFormValue(this.Controls, dt); LoadData(ms_sncode.Text, sender, e); } else { OperateResult.AppendText(">>序列号" + sncode_1 + "必须处于维修或未采集状态才能做拆解\n", Color.Red, sn_code); BaseUtil.CleanForm(this); sn_code.Focus(); return; } } else { ms_id = null; OperateResult.AppendText(">>序列号" + sncode_1 + "不存在\n", Color.Red, sn_code); BaseUtil.CleanForm(this); sn_code.Focus(); return; } } } //加载此序列号上料记录 private void LoadData(string sncode, object sender, KeyEventArgs e) { //cm_wccode sncode_1 = sncode; sql.Clear(); sql.Append("select cm_craftcode,cm_spid,cm_craftname,cm_firstsn,cm_makecode,cm_stepcode,cm_stepname,cm_maprodcode,cm_fsoncode,cm_wccode,cm_maid,cm_soncode,cm_materialtype,"); sql.Append("max(cm_status) cm_status,max(cm_id) cm_id from craftmaterial where(cm_sncode in (select '" + sncode_1 + "' from dual union select firstsn from makesnrelation where sn "); sql.Append(" ='" + sncode_1 + "'union select sn from makesnrelation where firstsn = '" + sncode_1 + "')"); sql.Append(") group by cm_craftcode,cm_firstsn,cm_stepcode,cm_stepname,cm_spid,cm_makecode,cm_maprodcode,cm_maid,cm_soncode,cm_wccode,cm_materialtype,cm_craftname,cm_fsoncode ORDER BY cm_status DESC"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt); for (int i = 0; i < LabelDataGridView.Rows.Count; i++) { DataTable datatable = (DataTable)dh.ExecuteSql("select cm_barcode,cm_sncode from CRAFTMATERIAL where cm_id = '" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "'", "select"); LabelDataGridView.Rows[i].Cells["cm_barcode"].Value = datatable.Rows[0]["cm_barcode"].ToString(); LabelDataGridView.Rows[i].Cells["cm_sncode"].Value = datatable.Rows[0]["cm_sncode"].ToString(); string[] cm_sncodedetail = LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString().Split(','); string pr_name = ""; foreach (string item in cm_sncodedetail) { pr_name += "'" + item + "',"; } pr_name = pr_name.TrimEnd(','); LabelDataGridView.Rows[i].Cells["pr_detail_"].Value = dh.getFieldDataByCondition("product", "wm_concat(substr(pr_spec,0,20))", "pr_code in (" + pr_name + ")"); LabelDataGridView.Rows[i].Cells["cm_status_1"].Value = (LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() == "-1") ? "已拆解" : "上线"; } } else { OperateResult.AppendText(">>序列号" + ms_sncode.Text + "无上料数据\n", Color.Red); } } private void Make_Decompose_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void LabelDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { if (LabelDataGridView.Columns[e.ColumnIndex].Name == "AddBad") { if (ms_sncode.Text == "" || ms_makecode.Text == "") { OperateResult.AppendText(">>序列号和工单号不允许为空\n", Color.Red); } else { rowindex = e.RowIndex; badcode = new Make_NewBadCode_DE(ms_sncode.Text, ms_makecode.Text); badcode.Controls["Save"].Click += LoadBadcode; BaseUtil.SetFormCenter(badcode); badcode.ShowDialog(); } } } } //加载之前在新增不良代码界面选择的不良代码 private void LoadBadcode(object sender, EventArgs e) { sql.Clear(); for (int i = 0; i < badcode.bccode.Length; i++) { sql.Append(badcode.bgcode[i] + " : " + badcode.bccode[i] + " |"); } LabelDataGridView.Rows[rowindex].Cells["mb_badcode"].Value = sql.GetString(); badcode.Close(); } private void Decompose_Click(object sender, EventArgs e) { sql.Clear(); sql.Append("select max(ms_id) from makeserial where ms_sncode ='" + ms_sncode.Text + "' or ms_sncode = (select max(SN)"); sql.Append(" from makesnrelation left join makeserial on ms_makecode=makecode where beforesn='" + ms_sncode.Text + "')"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); ms_id = dt.Rows[0][0].ToString(); if (ms_id != "") { sql.Clear(); sql.Append("select ms_id,ms_status,ms_makecode,ms_prodcode,pr_detail pr_name,ms_sncode,ms_firstsn,ms_craftcode,ms_craftname,ms_wccode from makeserial left join product on pr_code=ms_prodcode where ms_id='" + ms_id + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (!(dt.Rows[0]["ms_status"].ToString() == "0" || dt.Rows[0]["ms_status"].ToString() == "3")) { OperateResult.AppendText(">>序列号" + ms_sncode.Text + "必须处于维修或未采集状态才能做拆解\n", Color.Red, sn_code); BaseUtil.CleanForm(this); sn_code.Focus(); return; } } else { ms_id = null; OperateResult.AppendText(">>序列号" + ms_sncode.Text + "不存在\n", Color.Red, sn_code); BaseUtil.CleanForm(this); sn_code.Focus(); return; } Boolean decompose = false; for (int i = 0; i < LabelDataGridView.Rows.Count; i++) { if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null) { //if ((Boolean)LabelDataGridView.Rows[i].Cells["Choose"].Value == true && change.Checked && (LabelDataGridView.Rows[i].Cells["mb_badcode"].Value == null || LabelDataGridView.Rows[i].Cells["New_BarCode"].Value == null) && LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() != "-1") //{ // OperateResult.AppendText("第" + (i + 1) + "行没有采集不良代码或新批号\n", Color.Red); // return; //} if ((Boolean)LabelDataGridView.Rows[i].Cells["Choose"].Value == true && change.Checked && LabelDataGridView.Rows[i].Cells["New_BarCode"].Value == null && LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() == "-1") { OperateResult.AppendText("第" + (i + 1) + "行没有采集新批号\n", Color.Red); return; } //if ((Boolean)LabelDataGridView.Rows[i].Cells["Choose"].Value == true && nochange.Checked && (LabelDataGridView.Rows[i].Cells["mb_badcode"].Value == null) && LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() != "-1") //{ // OperateResult.AppendText("第" + (i + 1) + "行没有采集不良代码\n", Color.Red); // return; //} } } for (int i = 0; i < LabelDataGridView.Rows.Count; i++) { if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null) { if ((Boolean)LabelDataGridView.Rows[i].Cells["Choose"].Value == true) { //if (LabelDataGridView.Rows[i].Cells["mb_badcode"].Value != null) //{ // String[] badcodetol = LabelDataGridView.Rows[i].Cells["mb_badcode"].Value.ToString().Split('|'); // bgcode = new string[badcodetol.Length - 1]; // bccode = new string[badcodetol.Length - 1]; // for (int h = 0; h < badcodetol.Length - 1; h++) // { // bgcode[h] = badcodetol[h].Split(':')[0].Trim(); // bccode[h] = badcodetol[h].Split(':')[1].Trim(); // } //} if (change.Checked) { dt1 = new DataTable(); sql.Clear(); sql.Append("select ma_bomversion from makeserial left join make on ma_code=ms_makecode "); sql.Append("left join product on ms_prodcode=pr_code where ms_makecode='" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value + "' order by ms_id desc"); dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt1.Rows.Count > 0) { ma_bomversion = dt1.Rows[0][0].ToString(); } dtbar = new DataTable(); sql.Clear(); sql.Append("select max(sp_id)sp_id,max(sp_detno)sp_detno,min(sp_ifrepeat)sp_ifrepeat,sp_fsoncode,max(sp_barcoderule)"); sql.Append("sp_barcoderule, min(sp_checksalecode)sp_checksalecode,sp_tracekind,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)"); sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)"); sql.Append("sp_regex,max(substr(pr_spec,0,20))pr_detail from stepproduct left join product on pr_code=sp_fsoncode where "); sql.Append("sp_bomversion='" + ma_bomversion + "' and sp_craftcode='" + LabelDataGridView.Rows[i].Cells["cm_craftcode"].Value + "'and sp_mothercode ='" + LabelDataGridView.Rows[i].Cells["cm_maprodcode"].Value + "'"); sql.Append(" group by sp_fsoncode,sp_tracekind order by SP_DETNO asc"); dtbar = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); DataRow[] dtrows = dtbar.Select("sp_soncode like '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "'"); dtbar = BaseUtil.ToDataTable(dtrows); if (dtbar.Rows.Count > 0) { string ErrorMessage; string sp_tracekind = dtbar.Rows[0]["sp_tracekind"].ToString(); string sp_soncode = dtbar.Rows[0]["sp_soncode"].ToString(); string sp_prefix = dtbar.Rows[0]["sp_prefix"].ToString(); string sp_fsoncode = dtbar.Rows[0]["sp_fsoncode"].ToString(); string length = dtbar.Rows[0]["sp_length"].ToString(); string sp_ifrepeat = dtbar.Rows[0]["sp_ifrepeat"].ToString(); string sp_barcoderule = dtbar.Rows[0]["sp_barcoderule"].ToString(); string sp_checksalecode = dtbar.Rows[0]["sp_checksalecode"].ToString(); if (sp_tracekind == "1") { //上料校验规则判断 if (!LogicHandler.CheckSNBeforeLoad(LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString(), LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString(), sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_checksalecode, out ErrorMessage)) { OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red); LoadData(sncode_1, sender, new KeyEventArgs(Keys.Enter)); continue; } dh.UpdateByCondition("makeserial", "ms_nextmacode='" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString() + "'", "ms_id=(select max(ms_id) from makeserial where ms_sncode='" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "')"); } else if (sp_tracekind == "2") { if (!dh.CheckExist("makesourcestock", " (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'")) { OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "岗位备料无条码" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "\n", Color.Red); continue; } else { sql.Clear(); sql.Append("select mss_id,MSS_REMAIN,MSS_BASEQTY from makesourcestock where (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'"); dtst = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); int MSS_REMAIN = int.Parse(dtst.Rows[0]["MSS_REMAIN"].ToString()); int MSS_BASEQTY = int.Parse(dtst.Rows[0]["MSS_BASEQTY"].ToString()); if (MSS_REMAIN < MSS_BASEQTY) { OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "条码" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "备料不足\n", Color.Red); continue; } else { dh.UpdateByCondition("makesourcestock", "MSS_REMAIN = NVL(MSS_REMAIN, 0) - MSS_BASEQTY,MSS_USEQTY = NVL(MSS_USEQTY, 0) + MSS_BASEQTY,mss_madeqty=NVL(mss_madeqty,0)+ceil(MSS_USEQTY/MSS_BASEQTY)", " mss_id = '" + dtst.Rows[0]["mss_id"].ToString() + "' and (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'"); } } } } else { //当前备料信息不再工序BOM中,为BOM之外的批管控物料备料 if (!dh.CheckExist("makesourcestock", " (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'")) { OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "不在当前工序BOM" + ma_bomversion + "中\n", Color.Black); OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "岗位备料无条码" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "\n", Color.Red); continue; } else { sql.Clear(); sql.Append("select mss_id,MSS_REMAIN,MSS_BASEQTY from makesourcestock where (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'"); dtst = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); int MSS_REMAIN = int.Parse(dtst.Rows[0]["MSS_REMAIN"].ToString()); int MSS_BASEQTY = int.Parse(dtst.Rows[0]["MSS_BASEQTY"].ToString()); if (MSS_REMAIN < MSS_BASEQTY) { OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "条码" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "备料不足\n", Color.Red); continue; } else { dh.UpdateByCondition("makesourcestock", "MSS_REMAIN = NVL(MSS_REMAIN, 0) - MSS_BASEQTY,MSS_USEQTY = NVL(MSS_USEQTY, 0) + MSS_BASEQTY,mss_madeqty=NVL(mss_madeqty,0)+ceil(MSS_USEQTY/MSS_BASEQTY)", " mss_id = '" + dtst.Rows[0]["mss_id"].ToString() + "' and (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'"); } } } if (LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() != "-1") { //判断生产信息 sql.Clear(); sql.Append("select ms_id,ms_sncode,cm_barcode from craftmaterial left join makeserial on cm_barcode = ms_sncode and cm_soncode = ms_prodcode where cm_id = '" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "' and cm_materialtype ='1' and ms_id>'0' and ms_nextmacode = '" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString() + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); //制造件 if (dt.Rows.Count > 0) { string makecode = (String)dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_sncode = '" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "' and ms_prodcode = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "'"); string mss_id = dt.Rows[0]["ms_id"].ToString(); //////MakeBad表插入物料批号不良信息 //sql.Clear(); //sql.Append(" insert into makebad (mb_id, mb_inman,mb_indate,mb_stepcode,mb_sourcecode, mb_bgcode,mb_mscode,mb_sncode, mb_badcode, mb_makecode)"); //sql.Append("values (MakeBad_seq.nextval,'" + User.UserName + "',sysdate,'" + User.CurrentStepCode + "','" + User.UserSourceCode + "',:bg_code ,'" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "',"); //sql.Append(":bc_code,'" + makecode + "')"); //dh.BatchInsert(sql.GetString(), new string[] { "bg_code", "bc_code" }, bgcode, bccode); //更新子件序列号为待维修 sql.Clear(); sql.Append("update makeserial set ms_status=3 ,ms_badtimes = ms_badtimes+1,ms_nextmacode = '' where ms_id='" + mss_id + "' "); dh.ExecuteSql(sql.GetString(), "update"); } //没有生产信息,判定为采购件,则将不良信息插入不良零件表中MAKEBADRSPART else { //sql.Clear(); //sql.Append("insert into MAKEBADRSPART(mbp_id,mbp_indate,mbp_inman,mbp_sncode, mbp_badcode, mbp_part, mbp_makecode, mbp_sccode,mbp_barcode)values"); //sql.Append("(MAKEBADRSPART_seq.nextval, sysdate, '" + User.UserCode + "','" + ms_sncode.Text + "',:bc_code,'" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "','" + ms_makecode.Text + "','" + User.UserSourceCode + "','" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "')"); //dh.BatchInsert(sql.GetString(), new string[] { "bc_code" }, bccode); } } //此物料上线状态更新为-1,代表被拆解 sql.Clear(); sql.Append("update craftmaterial set cm_status=-1,cm_lastdeco=-1,cm_dropman='" + User.UserCode + "',"); sql.Append("cm_dropdate =sysdate,cm_dropstep='" + User.CurrentStepCode + "',"); sql.Append("cm_dropsccode='" + User.UserSourceCode + "' where cm_id='" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "'"); dh.ExecuteSql(sql.GetString(), "update"); ////将新批号绑定到序列号中 //dt = (DataTable)dh.ExecuteSql("select sp_id from stepproduct where sp_mothercode='" + LabelDataGridView.Rows[i].Cells["cm_maprodcode"].Value + "'", "select"); //string sp_id = dt.Rows[0]["sp_id"].ToString(); sql.Clear(); sql.Append("insert into craftmaterial (cm_id, cm_makecode,cm_maid,cm_maprodcode,cm_soncode,cm_mscode,cm_sncode,cm_stepcode,cm_stepname,"); sql.Append("cm_craftcode,cm_craftname,cm_barcode,cm_inqty,cm_indate,cm_inman,cm_linecode,cm_wccode,cm_sourcecode,cm_spid, cm_materialtype,cm_status,cm_fsoncode,cm_firstsn)"); sql.Append("values(Craftmaterial_seq.nextval,'" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_maid"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_maprodcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "'"); sql.Append(",'" + LabelDataGridView.Rows[i].Cells["cm_sncode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_sncode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_stepcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_stepname"].Value + "',"); sql.Append("'" + LabelDataGridView.Rows[i].Cells["cm_craftcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_craftname"].Value + "','" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value + "',1,sysdate,'" + User.UserCode + "','" + User.UserLineCode + "','" + LabelDataGridView.Rows[i].Cells["cm_wccode"].Value + "',"); sql.Append("'" + User.UserSourceCode + "','" + LabelDataGridView.Rows[i].Cells["cm_spid"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_materialtype"].Value + "','0','" + LabelDataGridView.Rows[i].Cells["cm_fsoncode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_firstsn"].Value + "')"); dh.ExecuteSql(sql.GetString(), "insert"); dh.ExecuteSql("update makeserial set ms_nextmacode='" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value + "' where ms_id=(select max(ms_id) from makeserial where ms_sncode='" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value + "' and ms_makecode<>'" + ms_makecode.Text + "')", "update"); OperateResult.AppendText("物料" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "拆解换料成功\n", Color.Green); decompose = true; LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "物料" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "拆解换料", "拆解换料成功", ms_sncode.Text, ""); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "物料" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value + "拆解换料上料", "拆解换料上料成功", ms_sncode.Text, ""); } else if (nochange.Checked) { if (LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() != "-1") { //判断生产信息 sql.Clear(); sql.Append("select ms_id,ms_sncode,cm_barcode from craftmaterial left join makeserial on cm_barcode = ms_sncode and cm_soncode = ms_prodcode where cm_id = '" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "' and cm_materialtype ='1' and ms_id>'0' and ms_nextmacode = '" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString() + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); //制造件 if (dt.Rows.Count > 0) { string makecode = (String)dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_sncode = '" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "' and ms_prodcode = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "'"); string mss_id = dt.Rows[0]["ms_id"].ToString(); ////MakeBad表插入物料批号不良信息 //sql.Clear(); //sql.Append(" insert into makebad (mb_id, mb_inman,mb_indate,mb_stepcode,mb_sourcecode, mb_bgcode,mb_mscode,mb_sncode, mb_badcode, mb_makecode)"); //sql.Append("values (MakeBad_seq.nextval,'" + User.UserName + "',sysdate,'" + User.CurrentStepCode + "','" + User.UserSourceCode + "',:bg_code ,'" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "',"); //sql.Append(":bc_code,'" + makecode + "')"); //dh.BatchInsert(sql.GetString(), new string[] { "bg_code", "bc_code" }, bgcode, bccode); //更新子件序列号为待维修 sql.Clear(); sql.Append("update makeserial set ms_status=3 ,ms_badtimes = ms_badtimes+1,ms_nextmacode = '' where ms_id='" + mss_id + "' "); dh.ExecuteSql(sql.GetString(), "update"); } //没有生产信息,判定为采购件,则将不良信息插入不良零件表中MAKEBADRSPART else { //sql.Clear(); //sql.Append("insert into MAKEBADRSPART(mbp_id,mbp_indate,mbp_inman,mbp_sncode, mbp_badcode, mbp_part, mbp_makecode, mbp_sccode,mbp_barcode)values"); //sql.Append("(MAKEBADRSPART_seq.nextval, sysdate, '" + User.UserCode + "','" + ms_sncode.Text + "',:bc_code,'" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "','" + ms_makecode.Text + "','" + User.UserSourceCode + "','" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "')"); //dh.BatchInsert(sql.GetString(), new string[] { "bc_code" }, bccode); } //craftmaterial解除相应物料绑定 sql.Clear(); sql.Append("update craftmaterial set cm_status=-1,cm_dropman='" + User.UserCode + "',"); sql.Append("cm_dropdate =sysdate,cm_dropstep='" + User.CurrentStepCode + "',"); sql.Append("cm_dropsccode='" + User.UserSourceCode + "' where cm_id='" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "'"); dh.ExecuteSql(sql.GetString(), "update"); } //更新序列号信息 sql.Clear(); sql.Append("update makeserial set ms_nextmacode = '' where ms_sncode = (select cm_barcode from craftmaterial where cm_id = '" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "' and CM_MATERIALTYPE = '1') and ms_nextmacode='" + ms_makecode.Text + "'"); dh.ExecuteSql(sql.GetString(), "update"); OperateResult.AppendText("物料" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "拆解成功\n", Color.Green); decompose = true; LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "物料" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "拆解", "拆解成功", ms_sncode.Text, ""); } else { OperateResult.AppendText(">>>没有选择拆解方式\n", Color.Red); return; } } } } if (decompose) { sn_code.Focus(); count++; deccount.Text = count + ""; LoadData(sncode_1, sender, new KeyEventArgs(Keys.Enter)); } else { OperateResult.AppendText("没有成功拆解项\n", Color.Red); } } private void LabelDataGridView_Sorted(object sender, EventArgs e) { } } }