if (e.KeyCode == Keys.Enter) { // 判断条码是否为设置的良品或不良品条码 string barcode = txt_barcode.Text.Trim(); string connectionString = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = db.accdb;Jet OLEDB:Database Password = @maruhi"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection.Open(); OleDbCommand command = new OleDbCommand("SELECT COUNT(*) FROM ICT_test WHERE Date=@date AND Barcode=@barcode AND Result='OK'", connection); command.Parameters.AddWithValue("@date", DateTime.Now.ToString("yyyy-MM-dd")); command.Parameters.AddWithValue("@barcode", barcode); int count = (int)command.ExecuteScalar(); if (count == 0) { // 条码错误 lb_test_state.BackColor = Color.Red; lb_test_state.Text = "条码错误 "; { // 良品或不良品点检 if (goodBarcodeList.Contains(barcode)) { lb_test_state.BackColor = Color.Yellow; lb_test_state.Text = "请进行良品点检"; SendBarcode(); } else if (badBarcodeList.Contains(barcode)) { lb_test_state.BackColor = Color.Yellow; lb_test_state.Text = "请进行不良品点检"; SendBarcode(); } } } }在此基础上修改,当良品和不良品测试结束后,条码不再受约束,无论输入什么条码,label状态栏始终是黄色,并提示,“已点检,请进行ICT测试”,并且所有条码都可以发送到ICT测试软件
时间: 2024-02-27 13:55:05 浏览: 92
event.keyCode键码值表 附只能输入特定的字符串代码
根据您的描述,您需要在良品和不良品测试结束后,解除对条码的限制,使得无论输入什么条码,都可以发送到ICT测试软件并提示“已点检,请进行ICT测试”,而且label状态栏始终是黄色。那么您可以参考下面的代码进行修改:
```
if (e.KeyCode == Keys.Enter)
{
// 判断条码是否为设置的良品或不良品条码
string barcode = txt_barcode.Text.Trim();
string connectionString = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = db.accdb;Jet OLEDB:Database Password = @maruhi";
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
OleDbCommand command = new OleDbCommand("SELECT COUNT(*) FROM ICT_test WHERE Date=@date AND Barcode=@barcode AND Result='OK'", connection);
command.Parameters.AddWithValue("@date", DateTime.Now.ToString("yyyy-MM-dd"));
command.Parameters.AddWithValue("@barcode", barcode);
int count = (int)command.ExecuteScalar();
if (count == 0)
{
// 条码错误
lb_test_state.BackColor = Color.Red;
lb_test_state.Text = "条码错误 ";
// 良品或不良品点检
if (goodBarcodeList.Contains(barcode))
{
lb_test_state.BackColor = Color.Yellow;
lb_test_state.Text = "请进行良品点检";
SendBarcode();
}
else if (badBarcodeList.Contains(barcode))
{
lb_test_state.BackColor = Color.Yellow;
lb_test_state.Text = "请进行不良品点检";
SendBarcode();
}
else
{
lb_test_state.BackColor = Color.Yellow;
lb_test_state.Text = "已点检,请进行ICT测试";
SendBarcode();
}
}
else
{
lb_test_state.BackColor = Color.Green;
lb_test_state.Text = "测试通过";
SendBarcode();
}
}
}
```
在代码中,我们加入了一个`else`语句,当条码不是良品和不良品条码时,就会执行这个`else`语句,将label状态栏设为黄色,并提示“已点检,请进行ICT测试”,然后将条码发送到ICT测试软件。这样,无论输入什么条码,都可以发送到ICT测试软件并提示“已点检,请进行ICT测试”,而且label状态栏始终是黄色。
阅读全文