//扫描 private void textBox7_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { //---开始MAC扫描 ScanDataInitial(); setRichtexBox("-----开始MAC扫描--------"); string tt_task = this.textBox1.Text.ToUpper().Trim(); string tt_scanmac = this.textBox7.Text.Trim(); string tt_shortmac = tt_scanmac.Replace("-", ""); //第一步位数判断 Boolean tt_flag1 = false; tt_flag1 = CheckStrLengh(tt_scanmac, this.textBox3.Text); //第二步包含符判断 Boolean tt_flag2 = false; if (tt_flag1) { tt_flag2 = CheckStrContain(tt_scanmac, this.textBox4.Text.Trim()); } //第三步 不包含符判断 Boolean tt_flag3 = false; if (tt_flag2) { tt_flag3 = CheckStrContain2(tt_scanmac, this.textBox2.Text.Trim()); } //第四步 扣数判断 Boolean tt_flag4 = false; if (tt_flag3) { int tt_shouldscan = getTransmitStrToInt(this.label58.Text); int tt_scanint = getTransmitStrToInt(this.label59.Text); if (tt_scanint <= tt_shouldscan) { tt_flag4 = true; setRichtexBox("4、还没有达到上限,应扫描数量:" + tt_shouldscan.ToString() + ",实际扫描数量:" + tt_scanint.ToString() + ",goon"); } else { } } //第五步 获取单板信息 string tt_pcba = ""; string tt_mac = ""; Boolean tt_flag5 = false; if (tt_flag4) { string tt_sql5 = "select pcbasn,maclable from odc_alllable " + "where hprintman = '" + tt_task + "' and maclable = '" + tt_shortmac + "' "; DataSet ds5 = Dataset1.GetDataSet(tt_sql5, tt_conn); if (ds5.Tables.Count > 0 && ds5.Tables[0].Rows.Count > 0) { tt_flag5 = true; tt_pcba = ds5.Tables[0].Rows[0].ItemArray[0].ToString(); //单板号 tt_mac = ds5.Tables[0].Rows[0].ItemArray[1].ToString(); //单板号 setRichtexBox("5、关联表查询到一条数据,pcba=" + tt_pcba + ",mac=" + tt_mac + ",goon"); } else { setRichtexBox("5、关联表没有查询到数据,over"); PutLableInfor("关联表没有查询到数据,请检查!"); } } //第六步 获取站位 Boolean tt_flag6 = false; if (tt_flag5) { string tt_sql6 = "select count(1),min(ccode),min(ncode) from odc_routingtasklist " + "where pcba_pn = '" + tt_shortmac + "' and napplytype is null "; string[] tt_array6 = new string[3]; tt_array6 = Dataset1.GetDatasetArray(tt_sql6, tt_conn); if (tt_array6[0] == "1") { if (tt_array6[2] == tt_ccode) { tt_flag6 = true; setRichtexBox("6、该单板有待测站位,站位:" + tt_array6[1] + "," + tt_array6[2] + ",可以过站 goon"); } else if (tt_array6[2] == "2220") { tt_flag6 = true; setRichtexBox("6、该单板有待测站位,站位:" + tt_array6[1] + "," + tt_array6[2] + ",可以过站 goon"); } else if (int.Parse(tt_array6[2]) < int.Parse(tt_ccode) || "2200,2205".Contains(tt_array6[2])) { setRichtexBox("6、该单板待测站位不在" + tt_ccode + ",站位:" + tt_array6[1] + "," + tt_array6[2] + ",不可以过站 goon"); PutLableInfor("该单板当前站位:" + tt_array6[2] + "不在" + tt_ccode + "站位,产品尚未测试耦合,不允许进站"); } else { setRichtexBox("6、该单板待测站位不在" + tt_ccode + ",站位:" + tt_array6[1] + "," + tt_array6[2] + ",不可以过站 goon"); PutLableInfor("该单板当前站位:" + tt_array6[2] + "不在" + tt_ccode + "站位!"); } } else { setRichtexBox("6、没有找到待测站位,或有多条待测站位,流程异常,over"); PutLableInfor("没有找到待测站位,或有多条待测站位,流程异常!"); } } //第六步附 检查2115 站位状态 Boolean tt_flag6_1 = false; if (tt_flag6) { string tt_sql6_1 = "select ncode,napplytype from dbo.odc_routingtasklist where pcba_pn = '" + tt_shortmac + "' and ccode = '2115'"; string tt_allprocesses = Dataset2.getGyidAllProcess(tt_gyid, tt_conn); DataSet ds6_1 = Dataset1.GetDataSetTwo(tt_sql6_1, tt_conn); bool tt_processcheck = true; if (ds6_1.Tables.Count > 0 && ds6_1.Tables[0].Rows.Count > 0) { string tt_napplytype = "1"; for (int i = 0; i < ds6_1.Tables[0].Rows.Count; i++) { tt_napplytype = ds6_1.Tables[0].Rows[i].ItemArray[1].ToString(); if (tt_napplytype == "0") { tt_processcheck = false; break; } } if ((tt_allprocesses.Contains("2111") && tt_napplytype == "1") || tt_processcheck) { tt_flag6_1 = true; setRichtexBox("6.1、该产品产品耦合测试没有出现过不良,或者有2111站位,且当前已通过耦合测试,可以过站,goon"); } else if (!tt_allprocesses.Contains("2111") && !tt_processcheck) { setRichtexBox("6.1、该产品流程没有2111站位,且耦合测试曾经出现过测试失败,不允许过站,over"); PutLableInfor("该产品2111不是必测站位,且耦合测试曾经出现过测试失败,不建议测试吞吐量!"); } else if (tt_allprocesses.Contains("2111") && tt_napplytype == "0") { setRichtexBox("6.1、该产品流程有2111站位,但耦合测试没有通过测试,不允许过站,over"); PutLableInfor("该产品流程有2111站位,但耦合测试没有通过测试,不允许过站!"); } } else { string tt_sql6_2 = "select ncode,napplytype from dbo.odc_routingtasklist where pcba_pn = '" + tt_shortmac + "' and ccode = '2185'"; tt_allprocesses = Dataset2.getGyidAllProcess(tt_gyid, tt_conn); DataSet ds6_2 = Dataset1.GetDataSetTwo(tt_sql6_2, tt_conn); tt_processcheck = true; if (ds6_2.Tables.Count > 0 && ds6_2.Tables[0].Rows.Count > 0) { string tt_napplytype = "1"; for (int i = 0; i < ds6_2.Tables[0].Rows.Count; i++) { tt_napplytype = ds6_2.Tables[0].Rows[i].ItemArray[1].ToString(); if (tt_napplytype == "0") { tt_processcheck = false; break; } } if ((tt_allprocesses.Contains("2111") && tt_napplytype == "1") || tt_processcheck) { tt_flag6_1 = true; setRichtexBox("6.1、该产品产品耦合测试没有出现过不良,或者有2111站位,且当前已通过耦合测试,可以过站,goon"); } else if (!tt_allprocesses.Contains("2111") && !tt_processcheck) { setRichtexBox("6.1、该产品流程没有2111站位,且耦合测试曾经出现过测试失败,不允许过站,over"); PutLableInfor("该产品2111不是必测站位,且耦合测试曾经出现过测试失败,不建议测试吞吐量!"); } } else { setRichtexBox("6.1、没有找到耦合站位状态,流程异常,over"); PutLableInfor("没有找到耦合站位状态,流程异常!"); } } } //第七步 开始过站 Boolean tt_flag7 = false; if (tt_flag6_1) { string tt_sql7 = "update odc_routingtasklist set ncode = '2111',Fremark ='10%扫描耦合' " + "where pcba_pn = '" + tt_mac + "' and napplytype is null "; int tt_int7 = Dataset1.ExecCommand(tt_sql7, tt_conn); if (tt_int7 > 0) { tt_flag7 = true; setRichtexBox("7、OK过站成功,跳站到2111"); } else { setRichtexBox("7、Fail过站失败,over"); PutLableInfor("跳站2111失败,请重新扫描!"); } } //第八步 记录数据 Boolean tt_flag8 = false; if (tt_flag7) { string tt_sql8 = "insert into odc_insertcode(Taskcode,MAC,PCBA,Ncode,Fdate) " + "values('" + tt_task + "','" + tt_mac + "','" + tt_pcba + "','" + tt_ccode + "',getdate()) "; int tt_int8 = Dataset1.ExecCommand(tt_sql8, tt_conn); if (tt_int8 > 0) { tt_flag8 = true; setRichtexBox("8、过站记录成功,goon"); } else { setRichtexBox("8、过站记录成功,over"); PutLableInfor("过站记录失败,扫描其他单板!"); } } //最后判断 if (tt_flag1 && tt_flag2 && tt_flag3 && tt_flag4 && tt_flag5 && tt_flag6 && tt_flag7 && tt_flag8) { GetProductNumInfo(); this.richTextBox1.BackColor = Color.Chartreuse; setRichtexBox("9、over"); tt_yield++; this.label8.Text = tt_yield.ToString(); PutListViewData(tt_mac, tt_pcba); PutLableInfor("请继续扫描"); textBox7.Focus(); textBox7.SelectAll(); } else { this.richTextBox1.BackColor = Color.Red; textBox7.Focus(); textBox7.SelectAll(); } } }
//异常处理 private void Button3_Click(object sender, EventArgs e) { //数据准备 string tt_scan = this.textBox1.Text.Trim().ToUpper(); string tt_scansn = GetShortMac(tt_scan); //第一步 条码确定 #region bool tt_flag1 = false; MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确定要对条码:" + tt_scansn + ",进行处理吗?这个处理主要是出来没有待测站位\\有多个待测站位\\没有1920站位的情况,请确认你输入的是单板号,还是MAC", "异常处理", messButton); if (dr == DialogResult.OK)//如果点击“确定”按钮 { tt_flag1 = true; } #endregion //第二步 确定MAC #region bool tt_flag2 = false; string tt_shortmac = ""; if (tt_flag1) { //选择的是MAC if (this.radioButton1.Checked == true) { tt_flag2 = true; tt_shortmac = tt_scansn; } //选择的是单板号 if (this.radioButton2.Checked == true) { string tt_sql2 = "select count(1),min(maclable),min(taskscode) from odc_alllable where pcbasn = '" + tt_scansn + "' "; string[] tt_array2 = new string[3]; tt_array2 = Dataset1.GetDatasetArray(tt_sql2, tt_conn); if (tt_array2[0] == "1") { tt_flag2 = true; tt_shortmac = tt_array2[1]; } else { MessageBox.Show("根据你输入的单板号:" + tt_scansn + ",无法在关联表中找到对应的MAC"); } } } #endregion //第三步 确定单板号 #region bool tt_flag3 = false; string tt_pcba = ""; if (tt_flag2) { //选择的单板号 if (this.radioButton2.Checked == true) { tt_flag3 = true; tt_pcba = tt_scansn; } //选择的是MAC if (this.radioButton1.Checked == true) { string tt_sql3 = "select count(1),min(pcbasn),min(taskscode) from odc_alllable where maclable = '" + tt_scansn + "' "; string[] tt_array3 = new string[3]; tt_array3 = Dataset1.GetDatasetArray(tt_sql3, tt_conn); if (tt_array3[0] == "1") { tt_flag3 = true; tt_pcba = tt_array3[1]; } else { MessageBox.Show("根据你输入的MAC:" + tt_scansn + ",无法在关联表中找到对应的单板号"); } } } #endregion //第四步 确定待测站位个数/是否缺失1920站位 #region int tt_intrownum = 0; string tt_nullmaxid = ""; string tt_nullminid = ""; bool tt_flag4 = false; bool tt_flag4_1 = false; if (tt_flag3) { string tt_sql4 = "select count(1),max(id),min(id) from odc_routingtasklist " + "where pcba_pn = '" + tt_shortmac + "' and napplytype is NULL "; string tt_sql4_1 = "select id,ncode,ccode from odc_routingtasklist " + "where pcba_pn = '" + tt_shortmac + "' and ncode = '2100' and napplytype = '1' order by id"; string tt_sql4_2 = "select count(1),max(id),min(id) from odc_routingtasklist " + "where pcba_pn = '" + tt_shortmac + "' and ncode = '2100' and napplytype = '1'"; DataSet tt_dataset1 = Dataset2.getMacAllCodeInfo(tt_shortmac, tt_conn); int tt_int1920id = Dataset2.getFirstCodeId(tt_dataset1); string[] tt_array4 = new string[3]; tt_array4 = Dataset1.GetDatasetArray(tt_sql4, tt_conn); string[] tt_array4_2 = new string[3]; tt_array4_2 = Dataset1.GetDatasetArray(tt_sql4_2, tt_conn); DataSet ds4_1 = Dataset1.GetDataSet(tt_sql4_1, tt_conn); if (ds4_1.Tables.Count > 0 && ds4_1.Tables[0].Rows.Count > 0 && tt_int1920id == -2) { string tt_id_1 = ds4_1.Tables[0].Rows[0].ItemArray[0].ToString(); string tt_ccode_1 = ds4_1.Tables[0].Rows[0].ItemArray[1].ToString(); string tt_ncode_1 = ds4_1.Tables[0].Rows[0].ItemArray[2].ToString(); if (int.Parse(tt_ccode_1) > 1920 && tt_id_1 == tt_array4_2[2]) { tt_flag4_1 = true; } } if (tt_array4[0] == "1" && tt_flag4_1 == false) { MessageBox.Show("该MAC:" + tt_shortmac + ",只有一个待测站位,没有异常,不需要处理"); } else if (tt_flag4_1) { int chang_ccode1920 = Change_ccode1920(tt_shortmac, tt_array4_2[2]); MessageBox.Show("该MAC:" + tt_shortmac + ",无1920站位的问题已处理完毕"); } else { tt_flag4 = true; tt_intrownum = GetStringToInt(tt_array4[0]); tt_nullmaxid = tt_array4[1]; tt_nullminid = tt_array4[2]; } } #endregion //第五步 确定异常问题 #region bool tt_flag5 = false; //没有待测站位 bool tt_flag6 = false; //多个待测站位 if (tt_flag4) { if (tt_intrownum == 0) { tt_flag5 = true; } else { if (tt_intrownum > 1) { tt_flag6 = true; } } } #endregion //第五步 没有待测站位处理 #region if (tt_flag5) { string tt_rowmaxid = ""; string tt_sql5 = "select count(1),max(id),0 from odc_routingtasklist " + "where pcba_pn = '" + tt_shortmac + "' "; string[] tt_array5 = new string[3]; tt_array5 = Dataset1.GetDatasetArray(tt_sql5, tt_conn); //查找最大的ID值 bool tt_flag51 = false; if (tt_array5[0] == "0") { MessageBox.Show("MAC:" + tt_shortmac + ",在站位表中没有找到记录"); } else { tt_flag51 = true; tt_rowmaxid = tt_array5[1]; } if (tt_flag51) { string tt_sql51 = "update odc_routingtasklist set napplytype = NULL " + "where pcba_pn = '" + tt_shortmac + "' and id = " + tt_rowmaxid; int tt_intexec = Dataset1.ExecCommand(tt_sql51, tt_conn); if (tt_intexec > 0) { MessageBox.Show("---OK---,操作1成功,该MAC:" + tt_shortmac + ",没有待测站位,现在已给出一个待测站位,请再次查询"); } else { MessageBox.Show("---Fail---,操作1失败,该MAC:" + tt_shortmac + ",没有待测站位,现在还是没有给出待测站位,请再次检查"); } } } #endregion //第六步 有多个待测站位,确定处理方法 #region bool tt_flag7 = false; bool tt_flag8 = false; string tt_maxid2 = ""; if (tt_flag6) { string tt_sql6 = "select count(1),max(id),0 from odc_routingtasklist " + "where pcba_pn = '" + tt_shortmac + "' "; string[] tt_array6 = new string[3]; tt_array6 = Dataset1.GetDatasetArray(tt_sql6, tt_conn); if (tt_array6[0] == "0") { MessageBox.Show("程序逻辑有问题,这是查找有多个待测站位的最大ID值,但是MAC:" + tt_shortmac + ",在站位表中没有发现有多个待测站位"); } else { tt_maxid2 = tt_array6[1]; if (tt_nullmaxid == tt_maxid2) //MAC的最大ID值和多个待测站位的最大ID值一致 { tt_flag7 = true; } else { tt_flag8 = true; } } } #endregion //第七步 有多个待测值 最大待测ID值和MAC的最大ID值一致(正常情况) #region if (tt_flag7) { string tt_sql7 = "update odc_routingtasklist set napplytype = 1 " + "where pcba_pn = '" + tt_shortmac + "' and napplytype is NULL and ID <" + tt_nullmaxid + " and id>=" + tt_nullminid; int tt_intexec7 = Dataset1.ExecCommand(tt_sql7, tt_conn); if (tt_intexec7 > 0) { MessageBox.Show("---OK---,操作2成功,该MAC:" + tt_shortmac + ",有多个待测站位,最大ID值就是待测站位,现在已只有一个待测站位,请再次查询"); } else { MessageBox.Show("---Fail---,操作2失败,该MAC:" + tt_shortmac + ",有多个待测站位,最大ID值就是待测站位,现在还是没有给出一个待测站位,请再次检查"); } } #endregion //第八步 有多个待测值 最大待测ID值和MAC的最大ID值不一致(非正常情况) #region if (tt_flag8) { //第8.1步 将最大ID值的设置为待测站位 string tt_sql81 = "update odc_routingtasklist set napplytype = NULL " + "where pcba_pn = '" + tt_shortmac + "' and id = " + tt_maxid2; int tt_intexec81 = Dataset1.ExecCommand(tt_sql81, tt_conn); //第8.2步 将其他的待测站位取消 string tt_sql82 = "update odc_routingtasklist set napplytype = 1 " + "where pcba_pn = '" + tt_shortmac + "' and napplytype is NULL and ID <=" + tt_nullmaxid + " and id>=" + tt_nullminid; int tt_intexec82 = Dataset1.ExecCommand(tt_sql82, tt_conn); //第8.3步 判断 if (tt_intexec81 > 0 && tt_intexec82 > 0) { MessageBox.Show("---OK---,操作3成功,该MAC:" + tt_shortmac + ",有多个待测站位,最大ID值不是待测站位,现在已只有一个待测站位,请再次查询"); } else { MessageBox.Show("---Fail---,操作4失败,该MAC:" + tt_shortmac + ",有多个待测站位,最大ID值不是待测站位,现在还是没有给出一个待测站位,请再次检查"); } } #endregion }