我有一个程序,其中用户在阅读器上轻敲RFID卡,程序将输入该数据。在这个程序中,有一个提示,我必须单击确定。点击RFID卡后,如何取下确定按钮并将其设为自动确认程序?
以下是该计划的部分内容:
委托void Function();
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string sdsd = serialPort1.ReadLine();
string Hexed = new LasalleRFIDComputerRentals.BLL.DAL.Utils().HexIt(sdsd);
SetRFIDText(Hexed);
}
protected void SetRFIDText(string input)
{
this.Invoke(new Function(delegate()
{
txtRFID.Text = input;
}));
CustomerInfo customer = new Customer().GetCustomerByRFID(txtRFID.Text);
}
private void btnOk_Click(object sender, EventArgs e)
{
if (txtRFID.Text.Trim() == "")
{
MessageBox.Show(this, "Please supply the RFID.", "RFID Reader", MessageBoxButtons.OK);
txtRFID.Focus();
return;
}
CustomerInfo customer = new Customer().GetCustomerByRFID(txtRFID.Text);
if (customer.CustomerID <= 0)
{
MessageBox.Show("Invalid RFID", "Validation");
this.Close();
return;
}
if (_parentForm == "StandBy")
{
Utils.CurrentCustomer.CustomerInfo = customer;
frmStandBy form = (frmStandBy)this.Owner;
form.xResult = "OK";
}
this.Close();
}
答案 0 :(得分:1)
只需单击“确定”按钮的逻辑
即可private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string sdsd = serialPort1.ReadLine();
string Hexed = new LasalleRFIDComputerRentals.BLL.DAL.Utils().HexIt(sdsd);
SetRFIDText(Hexed);
}
protected void SetRFIDText(string input)
{
this.Invoke(new Function(delegate()
{
txtRFID.Text = input;
}));
// what is it for?
//CustomerInfo customer = new Customer().GetCustomerByRFID(txtRFID.Text);
SearchCustomer();
}
private void btnOk_Click(object sender, EventArgs e)
{
SearchCustomer();
}
private void SearchCustomer()
{
if (txtRFID.Text.Trim() == "")
{
MessageBox.Show(this, "Please supply the RFID.", "RFID Reader", MessageBoxButtons.OK);
txtRFID.Focus();
return;
}
CustomerInfo customer = new Customer().GetCustomerByRFID(txtRFID.Text);
if (customer.CustomerID <= 0)
{
MessageBox.Show("Invalid RFID", "Validation");
this.Close();
return;
}
if (_parentForm == "StandBy")
{
Utils.CurrentCustomer.CustomerInfo = customer;
frmStandBy form = (frmStandBy)this.Owner;
form.xResult = "OK";
}
// what is it for?
//this.Close();
}
答案 1 :(得分:0)
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string sdsd = serialPort1.ReadLine();
string Hexed = new LasalleRFIDComputerRentals.BLL.DAL.Utils().HexIt(sdsd);
SetRFIDText(Hexed);
btnOK_click(sender, e);
}
这不回答“如何删除确定按钮”这一问题,因为您没有首先显示它是如何创建的 - 我怀疑您需要为此编辑表单定义。在这种情况下,将btnOK_click的代码从事件处理程序更改为“常规”函数(无论如何这都是个好主意)。