我有一个程序,其中用户点击阅读器上的RFID卡,该程序将输入此数据。在此程序中,有一个提示,我必须单击“确定”。轻按RFID卡后,如何删除“确定”按钮并使之成为自动OK程序?

这是程序的一部分:

委托(delegate)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();
    }

最佳答案

只需将“确定”按钮的逻辑分开即可

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();

}

关于C#如何从RFID扫描自动进行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15150672/

10-11 14:18