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.PublicForm; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.Make { public partial class Make_ImeiCheck_ThreeLabel_WN : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; LogStringBuilder sql; DataTable dt; DataTable info; string imei1 = ""; string imei2 = ""; bool isImei1 = false; bool isImei2 = false; string oErrorMessage = ""; string SN = ""; string omakeCode = ""; string oMsid = ""; public Make_ImeiCheck_ThreeLabel_WN() { InitializeComponent(); } private void Make_LabelCheck_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); //聚焦SN号 sncode.Focus(); //打开界面提示用户:请输入SN OperateResult.AppendText(">>请输入SN\n", Color.Black); sql = new LogStringBuilder(); dh = SystemInf.dh; StepCount.StepCode = User.CurrentStepCode; StepCount.Source = User.UserSourceCode; StepCount.LineCode = User.UserLineCode; StepCount.Dh = dh; StepCount.Start(); } string checksn = ""; private void Make_LabelCheck_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void sncode_KeyDown(object sender, KeyEventArgs e) { //判断是enter事件 if (e.KeyCode == Keys.Enter) { if (sncode.Text == "") { OperateResult.AppendText("<<输入不能为空\n", Color.DarkRed); return; } dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sncode.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { sncode.Text = dt.Rows[0]["ms_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sncode.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count > 0) { sncode.Text = dt.Rows[0]["ms_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sncode.Text + "' order by mil_id desc", "select"); if (dt.Rows.Count > 0) { sncode.Text = dt.Rows[0]["mil_sncode"].ToString(); } else { dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sncode.Text + "' order by mil_id desc", "select"); if (dt.Rows.Count > 0) { sncode.Text = dt.Rows[0]["mil_sncode"].ToString(); } } } } if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, sncode.Text, User.UserCode, out omakeCode, out oMsid, out oErrorMessage)) { } //输入的是SN if (!isImei1 && !isImei2) { OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black); sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei1 ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei2 ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { OperateResult.AppendText("<>请输入SN\n", Color.Black); } } } } } //存在该SN号 //根据该ms_id查询ms_imei1,ms_makecode信息 sql.Clear(); sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'"); info = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (info.Rows.Count > 0) { //用变量记录imei1和makecode checksn = info.Rows[0]["ms_sncode"].ToString(); SN = sncode.Text; //>> 请输入彩盒上的SN OperateResult.AppendText("<<条码" + sncode.Text + "对应的SN号为:" + checksn + "\n", Color.Green); OperateResult.AppendText(">>请输入需要核对的条码1\n", Color.Black, sncode); //设定要输入imei1 isImei1 = true; } else { OperateResult.AppendText("<>请输入SN\n", Color.Black); SetCheck set = new SetCheck("NG", Color.DarkRed); BaseUtil.SetFormCenter(set); set.ShowDialog(); } } else if (isImei1) { OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black); sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial where ms_sncode ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial where ms_imei1 ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial where ms_imei2 ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei1 ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { sql.Clear(); sql.Append("select max(ms_id) ms_id from makeimeilist left join makeserial on mil_makecode=ms_makecode and mil_sncode=ms_sncode where mil_imei2 ='" + sncode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { OperateResult.AppendText("<>请输入SN\n", Color.Black); SetCheck set = new SetCheck("NG", Color.DarkRed); BaseUtil.SetFormCenter(set); set.ShowDialog(); } } } } } sql.Clear(); sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'"); info = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (info.Rows.Count > 0) { imei1 = info.Rows[0]["ms_sncode"].ToString(); } if (imei1 == checksn) { OperateResult.AppendText("<<条码1核对成功\n", Color.Green, sncode); OperateResult.AppendText(">>请输入需要核对的条码2\n", Color.Black); isImei2 = true; isImei1 = false; } else { //清空imei1变量的值 imei1 = ""; imei2 = ""; checksn = ""; //SN核对失败 //>> 请输入SN OperateResult.AppendText(">>SN核对失败,不一致\n", Color.DarkRed, sncode); SetCheck set = new SetCheck("NG", Color.DarkRed); BaseUtil.SetFormCenter(set); set.ShowDialog(); OperateResult.AppendText(">>请输入SN\n", Color.Black); isImei1 = false; isImei2 = false; } } //输入的是imei1 else { OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black); sql.Clear(); sql.Append("select max(ms_id) ms_id from makeserial left join craftmaterial on cm_sncode=ms_sncode and cm_makecode=ms_makecode where cm_barcode ='" + sncode.Text + "' and nvl(cm_status,0)<>-1"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 || dt.Rows[0]["ms_id"].ToString() == "") { OperateResult.AppendText("<>请输入SN\n", Color.Black); } sql.Clear(); sql.Append("select ms_sncode from makeserial where ms_id='" + dt.Rows[0]["ms_id"].ToString() + "'"); info = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (info.Rows.Count > 0) { imei2 = info.Rows[0]["ms_sncode"].ToString(); } if (imei1 == checksn && imei2 == checksn) { //说明输入的imei1对比一致 //判断工序属性attribute if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage)) { //判断序列号下一工序(CHECKSTEPSNANDMACODE) if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, checksn, User.UserCode, out omakeCode, out oMsid, out oErrorMessage)) { string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsid + "'").ToString(); if (nextstepcode != User.CurrentStepCode) { string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString(); OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.DarkRed, sncode); imei1 = ""; imei2 = ""; checksn = ""; isImei1 = false; isImei2 = false; return; } //调用 SETSTEPRESULT ,获取返回的工单号, if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, checksn, "标签核对", "OK", User.UserCode, out oErrorMessage)) { //提示正确返回时传递的信息 if (oErrorMessage.Contains("AFTERSUCCESS")) OperateResult.AppendText(">>" + oErrorMessage + "\n"); //根据工单号查询makecraftdetail 表中的 mcd_okqty 计数,剩余数为ma_qty - nvl(mcd_inqty,0),刷新页面中工单信息的显示 sql.Clear(); sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,"); sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on "); sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BaseUtil.SetFormValue(Controls, dt); //将SN,时间,结果记录在页面 recordResult(checksn, DateTime.Now.ToString(), "成功"); //记录日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "标签核对成功", SN, ""); //SN核对成功 //>> 请输入SN OperateResult.AppendText("<<条码2核对成功\n", Color.LightGreen, sncode); OperateResult.AppendText(">>请输入SN\n", Color.Black); } else { //setstepresult不通过 OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode); recordResult(checksn, DateTime.Now.ToString(), "失败"); SetCheck set = new SetCheck("NG", Color.DarkRed); BaseUtil.SetFormCenter(set); set.ShowDialog(); } } else { //判定序列号下一工序不通过 OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode); recordResult(checksn, DateTime.Now.ToString(), "失败"); SetCheck set = new SetCheck("NG", Color.DarkRed); BaseUtil.SetFormCenter(set); set.ShowDialog(); } } else { //判定工序属性不通过 OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.DarkRed, sncode); SetCheck set = new SetCheck("NG", Color.DarkRed); BaseUtil.SetFormCenter(set); set.ShowDialog(); recordResult(checksn, DateTime.Now.ToString(), "失败"); } } //说明比对不一致 else { //清空imei1变量的值 imei1 = ""; imei2 = ""; checksn = ""; //SN核对失败 //>> 请输入SN OperateResult.AppendText(">>SN核对失败,不一致\n", Color.DarkRed, sncode); SetCheck set = new SetCheck("NG", Color.DarkRed); BaseUtil.SetFormCenter(set); set.ShowDialog(); OperateResult.AppendText(">>请输入SN\n", Color.Black); } //imei1校对结束,下次输入的是SN isImei1 = false; isImei2 = false; } } } private void recordResult(string SN, string time, string result) { ListViewItem lvi = new ListViewItem(); //分条赋值 lvi.SubItems.Add(SN); lvi.SubItems.Add(time); lvi.SubItems.Add(result); //添加结果的信息进去 showResult.Items.Add(lvi); } private void clear() { //清空变量的值 omakeCode = ""; oMsid = ""; SN = ""; imei1 = ""; imei2 = ""; checksn = ""; } private void StepCount_Load(object sender, EventArgs e) { } } }