5

ユーザーがリーダーの RFID カードをタップすると、プログラムがこのデータを入力するプログラムがあります。このプログラムでは、[OK] をクリックする必要があるプロンプトが表示されます。RFID カードがタップされると、OK ボタンを削除して自動 OK プログラムにするにはどうすればよいですか?

プログラムの一部は次のとおりです。

デリゲート 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();
    }
4

2 に答える 2

1

OKボタンのロジックを分離するだけ

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

}
于 2014-05-21T18:28:50.107 に答える
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);
}

そもそもどのように作成されたかを示していないため、「OKボタンを削除するにはどうすればよいですか」という質問には答えません。そのためのフォーム定義を編集する必要があると思います。その場合、btnOK_click のコードをイベント ハンドラーから「通常の」関数に変更します (いずれにしても良い考えです)。

于 2013-03-01T04:59:05.273 に答える