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; ExcelHandler eh; List sb = new List(); public Special_Reset() { InitializeComponent(); } private void Special_BoxSplit_Load(object sender, EventArgs e) { eh = new ExcelHandler(); 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_STEPCODE = '',MS_CHECKNO = '', ms_status=1,ms_outboxcode='',ms_nextstepcode= '"+ stepcode + "' where ms_sncode='" + sncode + "' and ms_nextmacode is null", "update"); //if (checkBox1.Checked) //{ // dh.ExecuteSql("update makeserial set ms_bs = '',ms_key='',ms_keyid='',MS_HARDWREID='',MS_KEYSTATEID='',MS_BIOS='',ms_ec='',ms_uuid='',MS_KEYPARTNUMBER='',ms_bt='',ms_mac='',ms_imei='' where ms_sncode = '" + sncode + "' and ms_makecode = '" + ms_makecode.Text + "'", "update"); //} dh.ExecuteSql("delete makebad where mb_sncode = '" + sncode + "' and mb_status = 0", "delete"); dh.ExecuteSql("delete from 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 LABELPRINTLOG where lpl_value = '" + 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(); } else if (oqcBtn.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_checkno = '" + sb[i].ToString() + "' and ms_status = 1", "select"); for (int k = 0; k < dt2.Rows.Count; k++) { ReSN(dt2.Rows[k]["ms_sncode"].ToString(), cd_stepcode.Text); } 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); } else if (((RadioButton)sender).Name == "oqcBtn") { 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) { 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 if (oqcBtn.Checked) { 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 where (ob_checkno = '" + input.Text + "' or ms_sncode = '" + input.Text + "') and ob_status IN( 'NG','FNG') ", "select"); if (dt.Rows.Count > 0) { if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text) { OperatResult.AppendText("抽检批:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input); return; } BaseUtil.SetFormValue(this.Controls, dt); if (sb.Contains(dt.Rows[0]["ob_checkno"].ToString())) { OperatResult.AppendText("抽检批:" + input.Text + "已采集\n", Color.Red, input); return; } WeighRecord.Items.Add(dt.Rows[0]["ob_checkno"].ToString()); sb.Add(dt.Rows[0]["ob_checkno"].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; } } } } private void 数据清空_Click(object sender, EventArgs e) { BaseUtil.CleanControls(this.Controls); WeighRecord.Items.Clear(); sb.Clear(); } private void excelim_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { DataTable ddtt; ddtt = eh.ImportExcel(openFileDialog1.FileName, "test"); if (ddtt.Rows.Count > 0) { for (int i = 0; i < ddtt.Rows.Count; i++) { input.Text = ddtt.Rows[i][0].ToString(); input_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } } } } } }