/// <summary> /// 手动验证 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnManually_Click(object sender, EventArgs e) { try { //获取当前选中行 if (dtSource == null || dtSource.Rows.Count == 0) { return; } int index = dataGrid.CurrentRowIndex; if (index < 0) { MessageBox.Show("请选择要验证的行!"); return; } DataRow row = dtSource.Rows[index]; //判断当前行是否已经上车 bool flag = row["ikey0"].Equals("已上车"); string ID = row["ID"].ToString(); if (flag) { MessageBox.Show("该物资已经上车!"); return; } string errMsg; //手动验证 try { Cursor.Current = Cursors.WaitCursor; flag = new BLL.LoadingVerify().Verify(ID, out errMsg); if (!flag) { throw new Exception(errMsg); } row["ikey0"] = "已上车"; } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { Cursor.Current = Cursors.Default; } dataGrid.DataSource = dtSource; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 扫描条码验证 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void txtBarCode_KeyPress(object sender, KeyPressEventArgs e) { string barCode = txtBarCode.Text.Trim(); if (!string.IsNullOrEmpty(barCode) && e.KeyChar == (char)Keys.Enter) { string errMsg; //第一步:判断该条码是否在该单据中 bool flag = false; DataRow temprow = null; foreach (DataRow row in dtSource.Rows) { if (row["cNO"].Equals(barCode)) { flag = true; temprow = row; break; } } //如果不存在 if (!flag) { MessageBox.Show("对不起,此物资不在该单据中!"); txtBarCode.Focus(); txtBarCode.SelectAll(); return; } //第二步:判断该条码是否已经上车 if (temprow["ikey0"].Equals("已上车")) { MessageBox.Show("该物资已经上车!"); txtBarCode.Focus(); txtBarCode.SelectAll(); return; } //第三步:验证该条码 try { Cursor.Current = Cursors.WaitCursor; flag = new BLL.LoadingVerify().Verify(temprow["ID"].ToString(), out errMsg); if (!flag) { throw new Exception(errMsg); } //修改当前行的状态 temprow["ikey0"] = "已上车"; } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { Cursor.Current = Cursors.Default; } dataGrid.DataSource = dtSource; //成功后 txtBarCode.Focus(); txtBarCode.SelectAll(); } }