5

我有一个程序,其中用户在阅读器上点击 RFID 卡,程序将输入此数据。在这个程序中,有一个提示,我必须单击确定。RFID 卡被点击后,如何移除 OK 按钮并使其成为自动 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;
        }));

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

这没有回答“我如何删除确定按钮”的问题,因为您没有首先显示它是如何创建的 - 我怀疑您需要为此编辑表单定义。在这种情况下,将 btnOK_click 的代码从事件处理程序更改为“常规”函数(无论如何这都是个好主意)。

于 2013-03-01T04:59:05.273 回答