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.Special { public partial class Special_Reset : Form { DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); AutoSizeFormClass asc = new AutoSizeFormClass(); DataTable Dbfind; DataTable dt; List sb = new List(); public Special_Reset() { InitializeComponent(); } private void Special_BoxSplit_Load(object sender, EventArgs e) { dh = SystemInf.dh; asc.controllInitializeSize(this); cd_stepcode.FormName = Name; cd_stepcode.TableName = "craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id"; cd_stepcode.SetValueField = new string[] { "cd_stepcode", "cd_stepno" }; cd_stepcode.SelectField = "cd_stepname # 工序名称 ,cd_stepcode # 工序编号,cd_stepno # 执行顺序"; cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno"; cd_stepcode.DBTitle = "回流工序"; cd_stepcode.DbChange += Cd_stepcode_DbChange; } private void Cd_stepcode_DbChange(object sender, EventArgs e) { Dbfind = cd_stepcode.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); } private void ReSN(string sncode, string stepcode) { string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + stepcode + "'").ToString(); dh.ExecuteSql("update makeserial set ms_status=1,ms_outboxcode='',ms_printcount = 0, ms_nextstepcode= '" + stepcode + "' where ms_sncode='" + sncode + "'", "update"); dh.ExecuteSql("delete makebad where mb_sncode = '" + sncode + "' and mb_status = 0", "delete"); //dh.ExecuteSql("delete labelprintlog where lpl_value = '" + sncode + "' ", "delete"); sql.Clear(); sql.Append("update craftmaterial set cm_status=-1,cm_lastdeco=-1,cm_dropman='" + User.UserCode + "',"); sql.Append("cm_dropdate =sysdate,CM_REMARK = '重置站点拆解',cm_dropstep='" + User.CurrentStepCode + "',"); sql.Append("cm_dropsccode='" + User.UserSourceCode + "' where cm_sncode = '" + sncode + "' and cm_stepcode in (select cd_stepcode from craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id where ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_detno >=" + cd_stepno.Text + " )"); dh.ExecuteSql(sql.GetString(), "update"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sncode, ""); } private void Split_Click(object sender, EventArgs e) { if (sb.Count == 0|| cd_stepcode.Text == "") { OperatResult.AppendText(">>采集数与回流工位不能为空\n", Color.Red); return; } string Delete = MessageBox.Show(this.ParentForm, "是否确认重置站点?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (Delete == "Yes") { if (serBtn.Checked) { for (int i = 0; i < sb.Count; i++) { ReSN(sb[i].ToString(), cd_stepcode.Text); OperatResult.AppendText("SN:" + sb[i].ToString()+ "回流至"+ cd_stepcode.Text + "完成\n", Color.Green); } WeighRecord.Items.Clear(); sb.Clear(); } else if(bigboxBtn.Checked) { string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + cd_stepcode.Text + "'").ToString(); for (int i = 0; i < sb.Count; i++) { DataTable dt2 = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_outboxcode = '" + sb[i].ToString() + "'", "select"); for (int k = 0; k < dt2.Rows.Count; k++) { ReSN(dt2.Rows[k]["ms_sncode"].ToString(), cd_stepcode.Text); } dh.ExecuteSql("insert into PACKAGEBACKUP select * from package where pa_outboxcode='" + sb[i].ToString() + "'", "insert"); dh.ExecuteSql("insert into PACKAGEBACKUPDETAIL select * from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "insert"); dh.ExecuteSql("delete from package where pa_outboxcode = '" + sb[i].ToString() + "'", "delete"); //删除箱的明细 dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "delete"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sb[i].ToString(), ""); OperatResult.AppendText("卡通箱:" + sb[i].ToString() + "回流至" + cd_stepcode.Text + "完成\n", Color.Green); } WeighRecord.Items.Clear(); sb.Clear(); } sql.Clear(); sql.Append("MERGE INTO makecraftdetail USING (select mcd_macode,mcd_detno,mcd_stepcode,mcd_stepname,nvl(count(distinct A.ms_sncode),0) n,nvl(count(distinct B.ms_sncode),0) bn,(select nvl(count(distinct sp_sncode),0) from STEPPASSED where SP_MAKECODE = mcd_macode AND SP_STEPCODE = mcd_stepcode) inqty from MAKECRAFTdetail"); sql.Append(" left join makeserial A on mcd_macode = A.ms_makecode and mcd_stepcode = A.ms_nextstepcode AND A.MS_STATUS = 1 LEFT JOIN MAKESERIAL B ON mcd_macode = B.ms_makecode AND MCD_STEPCODE = B.MS_STEPCODE AND B.MS_STATUS = 3 where mcd_macode = '"+ ms_makecode.Text + "' group by mcd_macode,mcd_detno, mcd_stepcode, mcd_stepname order by mcd_detno asc) A"); sql.Append(" ON (makecraftdetail.MCD_MACODE = A.MCD_MACODE and makecraftdetail.mcd_stepcode = A.mcd_stepcode) "); sql.Append(" WHEN MATCHED THEN UPDATE SET makecraftdetail.mcd_inqty = A.inqty,makecraftdetail.mcd_outqty = A.inqty,makecraftdetail.mcd_okqty = A.inqty "); dh.ExecuteSql(sql.GetString(), "update"); } } private void bigboxBtn_Click(object sender, EventArgs e) { if (((RadioButton)sender).Checked == true) { if (WeighRecord.Items.Count > 0) { string logout_confirm = MessageBox.Show(this.ParentForm, "是否更换采集项(已录入信息会清空)?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (logout_confirm == "Yes") { WeighRecord.Items.Clear(); sb.Clear(); ms_makecode.Text = ""; ms_prodcode.Text = ""; cr_code.Text = ""; cd_stepcode.Text = ""; } else { serBtn.Checked = bigboxBtn.Checked; bigboxBtn.Checked = !serBtn.Checked; } } if (((RadioButton)sender).Name == "serBtn") { input.Focus(); OperatResult.AppendText("请输入序列号进行采集\n", Color.Black, input); } else if (((RadioButton)sender).Name == "bigboxBtn") { input.Focus(); OperatResult.AppendText("请输入箱号进行采集\n", Color.Black, input); } } } private void cr_code_TextChanged(object sender, EventArgs e) { cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno"; } private void input_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (serBtn.Checked) { dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_prodcode,ms_sncode,ms_craftcode cr_code,ms_status,ms_outboxcode from makeserial where ms_sncode = '" + input.Text + "' order by ms_id desc" , "select"); if (dt.Rows.Count > 0) { if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text) { OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input); return; } if (dt.Rows[0]["ms_status"].ToString() == "3") { OperatResult.AppendText("SN:" + input.Text + "为不良品,不允许采集\n", Color.Red, input); return; } if (dt.Rows[0]["ms_outboxcode"].ToString() != "") { OperatResult.AppendText("SN:" + input.Text + "已装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + ",不允许采集\n", Color.Red, input); return; } BaseUtil.SetFormValue(this.Controls, dt); if (sb.Contains(dt.Rows[0]["ms_sncode"].ToString())) { OperatResult.AppendText("SN:" + input.Text + "已采集\n", Color.Red, input); return; } WeighRecord.Items.Add(dt.Rows[0]["ms_sncode"].ToString()); sb.Add(dt.Rows[0]["ms_sncode"].ToString()); OperatResult.AppendText("SN:" + input.Text + "采集\n", Color.Green, input); cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno"; } else { OperatResult.AppendText("SN:" + input.Text + "不存在\n", Color.Red, input); return; } } else if (bigboxBtn.Checked) { if (!checkBox1.Checked) { dt = (DataTable)dh.ExecuteSql("select pa_makecode ms_makecode,pa_prodcode ms_prodcode,pa_outboxcode,pa_mothercode,ma_craftcode cr_code from package left join make on pa_makecode = ma_code where pa_outboxcode = '" + input.Text + "' and pa_type = '1'", "select"); if (dt.Rows.Count > 0) { if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text) { OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input); return; } if (dt.Rows[0]["pa_mothercode"].ToString() != "") { OperatResult.AppendText("卡通箱:" + input.Text + "已装栈板" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许采集\n", Color.Red, input); return; } BaseUtil.SetFormValue(this.Controls, dt); if (sb.Contains(dt.Rows[0]["pa_outboxcode"].ToString())) { OperatResult.AppendText("卡通箱:" + input.Text + "已采集\n", Color.Red, input); return; } WeighRecord.Items.Add(dt.Rows[0]["pa_outboxcode"].ToString()); sb.Add(dt.Rows[0]["pa_outboxcode"].ToString()); OperatResult.AppendText("卡通箱:" + input.Text + "采集\n", Color.Green, input); cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno"; } else { OperatResult.AppendText("卡通箱:" + input.Text + "不存在\n", Color.Red, input); return; } } else { WeighRecord.Items.Clear(); sb.Clear(); dt = (DataTable)dh.ExecuteSql("select ob_makecode ms_makecode,ob_prodcode ms_prodcode,ob_checkno,ma_craftcode cr_code from oqcbatch left join make on ob_makecode = ma_code left join makeserial on ms_checkno = ob_checkno where (ob_checkno = '" + input.Text + "' or ms_sncode = '" + input.Text + "') and ob_status IN( 'NG','FNG') ", "select"); if (dt.Rows.Count > 0) { BaseUtil.SetFormValue(this.Controls, dt); DataTable dd = (DataTable)dh.ExecuteSql(" select distinct(obd_outboxcode) obd_outboxcode from OQCBATCHDETAIL where obd_checkno = '"+ dt.Rows[0]["ob_checkno"].ToString() + "' and obd_outboxcode is not null ", "select"); if (dd.Rows.Count > 0) { for (int i = 0; i < dd.Rows.Count; i++) { WeighRecord.Items.Add(dd.Rows[i]["obd_outboxcode"].ToString()); sb.Add(dd.Rows[i]["obd_outboxcode"].ToString()); } } OperatResult.AppendText("抽检批:" + dt.Rows[0]["ob_checkno"].ToString() + "箱号返工采集\n", Color.Green, input); cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_ifoqc <> -1 order by cd_stepno"; } else { OperatResult.AppendText("录入信息:" + input.Text + "不存在抽检批或不是批退状态\n", Color.Red, input); return; } } } } } private void 数据清空_Click(object sender, EventArgs e) { BaseUtil.CleanControls(this.Controls); WeighRecord.Items.Clear(); sb.Clear(); } private void Special_Reset_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } } }