2013-03-01 11 views
5

Ho un programma in cui l'utente tocca una scheda RFID su un lettore e il programma inserirà questi dati. In questo programma, c'è un prompt in cui devo cliccare OK. Come rimuovere il pulsante OK e renderlo un programma auto-OK dopo aver toccato la carta RFID?C# Come attivare automaticamente la scansione RFID?

Qui sono le parti del programma:

delegato vuoto 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(); 
    } 
+0

chiamata btnOK_Click dall'interno DataReceived dovrebbe farlo? Cosa hai provato? – Floris

risposta

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

Questo non risponde alla domanda "come faccio a rimuovere il pulsante OK", in quanto non è stato mostrare come è stato creato in primo luogo - ho il sospetto è necessario modificare la definizione del modulo per quello. In tal caso, modifica il codice per btnOK_click da un gestore di eventi a una funzione "regolare" (che sarebbe comunque una buona idea).

+0

Il mio obiettivo non è quello di rimuovere veramente il pulsante OK. Forse per nasconderlo? Ma l'obiettivo è quando viene visualizzato il prompt, ho appena toccato la scheda RFID e il prompt si chiuderà automaticamente. Non devo fare clic su OK. Ho provato il tuo suggerimento ma ha detto che btnOK_click non esiste nel contesto attuale. – Kael

+0

Aspetta, in realtà ha funzionato. L'ho provato prima. Invece, ho copiato il programma "btnOK_click" sotto SetRFIDText (Hexed) ;. Ma sembra che il programma sia in conflitto con This.Close(); e la casella di messaggio RFID non valida viene visualizzata in background. Perché? – Kael

+0

A cosa si riferisce questo? Nel contesto della chiamata di funzione? Potresti fare riferimento al modulo stesso (per nome), invece? Eviterebbe ogni confusione e dovrebbe funzionare (credo ...) – Floris

1

semplicemente separare la logica del pulsante 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(); 

} 
Problemi correlati