Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to auto okay from RFID scanning?

Tags:

c#

button

rfid

I have a program wherein the user taps an RFID card on a reader and the program will input this data. In this program, there is a prompt wherein I have to click OK. How do I remove the OK button and make it an auto-OK program once the RFID card is tapped?

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();
    }
like image 581
Kael Avatar asked Nov 13 '22 10:11

Kael


1 Answers

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

}
like image 73
Julio S. Avatar answered Nov 15 '22 00:11

Julio S.