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_LabelCheck : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; LogStringBuilder sql; DataTable dt; DataTable info; DataTable checkItemInfo;//存储需要核对的所有信息列表 string needCheckedInfo = ""; bool isCheckItem = false; string oErrorMessage = ""; string SN = ""; string TSN = "";//存TSN string omakeCode = ""; string oMsid = ""; int checkIndex = 0;//记录核对的当前位置,从0开始 public Make_LabelCheck() { 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(); } 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.Red); return; } //输入的是SN if (!isCheckItem) { OperateResult.AppendText("<<"+sncode.Text+"\n", Color.Black); //查询是否存在该ms_id sql.Clear(); sql.Append("select ms_id,ms_prodcode,ms_makecode,ms_craftcode,ms_beforesn from makeserial where ms_id = (select max(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() == "") { //SN错误,不存在 //请输入SN OperateResult.AppendText("<>请采集SN\n", Color.Black); return; } //存在该SN号,查询相关需要核对的信息 sql.Clear(); sql.Append("select checkitem,fsoncode,type,detno from (select psr_type checkitem ,'' fsoncode,'MS' type ,"); sql.Append("ROW_NUMBER() OVER (order by psr_detno asc )detno from productsnrelation where psr_prodcode='"+ dt.Rows[0]["ms_prodcode"].ToString() + "' and nvl(psr_iflabelcheck,0)<>0"); sql.Append(" UNION ALL select wm_concat(sp_soncode)checkitem,sp_fsoncode fsoncode ,'SP' type,"); sql.Append(" ROW_NUMBER()OVER(order by min(sp_detno)asc) detno from make inner join stepbom on sb_bomversion=ma_bomversion and sb_prodcode=ma_prodcode"); sql.Append(" inner join stepproduct on sp_sbid=sb_id where ma_code='"+ dt.Rows[0]["ms_makecode"].ToString() + "' and sb_craftcode='"+ dt.Rows[0]["ms_craftcode"].ToString() + "' and nvl(sp_iflabelcheck,0)<>0"); sql.Append(" GROUP BY sp_fsoncode) order by type,detno"); checkItemInfo = (DataTable)dh.ExecuteSql(sql.GetString(),"select"); //判断是否无需要核对的项 if (checkItemInfo.Rows.Count==0) { OperateResult.AppendText("<<序列号" + sncode.Text + "没有需要核对的项\n", Color.Red, sncode); OperateResult.AppendText(">>请采集SN\n", Color.Black); return; } //记录SN SN = sncode.Text; TSN = dt.Rows[0]["ms_beforesn"].ToString(); //查询第一个需要核对的信息 getNextInfo(checkIndex); //设定要输入核对信息 isCheckItem = true; } //输入的是imei1 else { OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black); if (needCheckedInfo == sncode.Text||((needCheckedInfo == sncode.Text.Replace(":", "").Replace("-", ""))&&(checkItemInfo.Rows[checkIndex]["checkitem"].ToString() == "MAC"|| checkItemInfo.Rows[checkIndex]["checkitem"].ToString() == "BT"))) { checkIndex += 1;//序号+1,进入下一步 if (checkIndex == checkItemInfo.Rows.Count) { //说明输入的核对信息对比一致 //判断工序属性attribute if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage)) { //判断序列号下一工序(CHECKSTEPSNANDMACODE) if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, SN, User.UserCode, out omakeCode, out oMsid, out oErrorMessage)) { //调用 SETSTEPRESULT ,获取返回的工单号, if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, SN, "标签核对", "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(SN, DateTime.Now.ToString(), "成功"); //记录日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "标签核对成功", SN, ""); //IMEI核对成功 //>> 请输入SN OperateResult.AppendText("<<核对成功\n", Color.Green, sncode); } else { //setstepresult不通过 OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode); recordResult(SN, DateTime.Now.ToString(), "失败"); } } else { //判定序列号下一工序不通过 OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode); recordResult(SN, DateTime.Now.ToString(), "失败"); } } else { //判定工序属性不通过 OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode); recordResult(SN, DateTime.Now.ToString(), "失败"); } OperateResult.AppendText(">>请采集SN\n", Color.Black); checkIndex = 0; isCheckItem = false; } else { //输入一致则进入下一个 getNextInfo(checkIndex); } } //说明比对不一致 else { //信息核对失败 //>> 请输入SN OperateResult.AppendText(">>上料信息或序列号采集信息"+needCheckedInfo+"核对失败,不一致\n", Color.Red, sncode); //为采集信息 if (checkItemInfo.Rows[checkIndex]["TYPE"].ToString() == "MS") { OperateResult.AppendText(">>请采集" + checkItemInfo.Rows[checkIndex]["checkitem"].ToString() + "\n", Color.Black, sncode); } else//为上料信息 { OperateResult.AppendText(">>请采集物料" + checkItemInfo.Rows[checkIndex]["checkitem"].ToString() + "条码\n", Color.Black, sncode); } } } } } private void recordResult(string SN, string time, string result) { //if (showResult.Items.Count >= 10) //{ // //如果有10行的话,则删除最前一行 // showResult.Items.RemoveAt(0); //} //创建一个item 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 = ""; needCheckedInfo = ""; } private void getNextInfo(int index) { //判断为上料或者采集信息 //为采集信息 if (checkItemInfo.Rows[index]["TYPE"].ToString() == "MS") { //从makeserial表中查询对应字段的值 needCheckedInfo = dh.getFieldDataByCondition("makeserial","ms_"+ checkItemInfo.Rows[index]["checkitem"].ToString(),"ms_id ='"+ dt.Rows[0]["ms_id"].ToString() + "'").ToString(); OperateResult.AppendText("<<序列号" + SN + "对应的"+ checkItemInfo.Rows[index]["checkitem"].ToString() + "为" + needCheckedInfo + "\n", Color.Green); OperateResult.AppendText(">>请采集"+ checkItemInfo.Rows[index]["checkitem"].ToString() + "\n", Color.Black, sncode); } else//为上料信息 { //从craftmaterial中查询上料记录 needCheckedInfo = dh.getFieldDataByCondition("craftmaterial", "cm_barcode", "cm_makecode='"+ dt.Rows[0]["ms_makecode"].ToString() + "' and cm_sncode in ('"+SN+"'"+(TSN==""?"":(",'"+TSN+"'"))+") and cm_fsoncode='"+checkItemInfo.Rows[index]["fsoncode"].ToString()+"' and cm_status=0").ToString(); OperateResult.AppendText("<<序列号" + SN + "上料物料"+ checkItemInfo.Rows[index]["checkitem"].ToString() + "的条码号为" + needCheckedInfo + "\n", Color.Green); OperateResult.AppendText(">>请采集物料"+ checkItemInfo.Rows[index]["checkitem"].ToString() + "条码\n", Color.Black, sncode); } } private void cancel_Click(object sender, EventArgs e) { OperateResult.AppendText(">>请采集SN\n", Color.Black); checkIndex = 0; isCheckItem = false; SN = ""; } } }