C # How to automatically check RFID scan?

I have a program in which a user picks up an RFID card on a reader, and the program will enter this data. There is a hint in this program in which I have to click OK. How to remove the "OK" button and make it an automatic program OK after the RFID card is pressed?

Here are the parts of the program:

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();
    }
+5
source share
2 answers

Just separate the logic of the OK button

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
source
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 " " ( ).

0

All Articles