/// <summary> /// 根据完整网址获取扫描信息 /// </summary> /// <param name="fullInfor"></param> /// <returns></returns> private scanInfor GetScanInfor(string fullInfor) { scanInfor temInfor = new scanInfor(); fullInfor = fullInfor.Substring(fullInfor.Length - 20); if (fullInfor.Substring(0, 2) != "o=") { return(temInfor); } temInfor.Batch = fullInfor.Substring(9, 6); temInfor.Number = fullInfor.Substring(fullInfor.Length - 3, 3); return(temInfor); }
private void txtNumber_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) { return; } string fullInfor = txtNumber.Text.Trim(); int strLength = fullInfor.Length; if (strLength < 30) { txtLog.Text += DateTime.Now.ToString("HH:mm:ss") + " 录入错误信息,长度不够: " + fullInfor + "\n"; txtNumber.Text = string.Empty; txtNumber.Focus(); return; } scanInfor temScan = GetScanInfor(fullInfor); if (temScan.Batch == null) { txtLog.Text += DateTime.Now.ToString("HH:mm:ss") + " 录入错误信息,获取批号及号码失败: " + fullInfor + "\r\n"; txtNumber.Text = string.Empty; txtNumber.Focus(); return; } if (mastList.Count < 1) //首次添加 { //temScan.IsReBath = false; //temScan.IsReNumber = false; curBath = temScan.Batch; curUrl = GetUrlByFull(fullInfor); txtCurBath.Text = curBath; txtUrl.Text = curUrl; mastList.Add(temScan); RefdgvMaster(); txtLog.Text += DateTime.Now.ToString("HH:mm:ss") + " 第一枪编号: " + temScan.Number + "\r\n"; txtNumber.Text = string.Empty; txtNumber.Focus(); } else { if (curUrl != GetUrlByFull(fullInfor)) { txtLog.Text += DateTime.Now.ToString("HH:mm:ss") + " 录入错误信息,主域名不符: " + fullInfor + "\r\n"; txtNumber.Text = string.Empty; txtNumber.Focus(); return; } if (curBath != temScan.Batch) { temScan.IsBathDif = true; //检查批号是否相同 lbReBath.Text = "不同批"; lbReBath.BackColor = Color.Red; txtLog.Text += DateTime.Now.ToString("HH:mm:ss") + " 发现不同批号: " + fullInfor + "\r\n"; } //下面验证编号重复 bool isRe = false; foreach (scanInfor item in mastList) { if (item.Number == temScan.Number) { item.IsReNumber = true; isRe = true; temScan.IsReNumber = true; } } if (isRe) { lbIsRepass.Text = "有重复"; lbIsRepass.BackColor = Color.Red; txtLog.Text += DateTime.Now.ToString("HH:mm:ss") + " 发现编号重复: " + fullInfor + "\r\n"; } mastList.Add(temScan); txtNumber.Text = string.Empty; txtNumber.Focus(); RefdgvMaster(); } }