2013-03-01 8 views
5

Mam program, w którym użytkownik wybiera kartę RFID na czytniku, a program wprowadzi te dane. W tym programie jest monit, w którym muszę kliknąć OK. Jak usunąć przycisk OK i ustawić program automatyczny po dotknięciu karty RFID?C# Jak automatycznie pracować w trybie skanowania RFID?

Oto części programu:

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

połączeń btnOK_Click od wewnątrz dataReceived powinien to zrobić? Co próbowałeś? – Floris

Odpowiedz

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

To nie jest odpowiedź na pytanie „Jak mogę usunąć przycisk OK”, ponieważ nie wykazał w jaki sposób został stworzony w pierwszej kolejności - Podejrzewam, musisz zmodyfikować definicję formularza za to. W takim przypadku zmień kod dla btnOK_click z funkcji obsługi zdarzeń na "zwykłą" funkcję (co i tak byłby dobry pomysł).

+0

Moim celem nie jest tak naprawdę usunięcie przycisku OK. Może to ukryć? Ale celem jest pojawienie się monitu, po prostu pukam kartę RFID, a prompt automatycznie się zamknie. Nie muszę klikać OK. Próbowałem twojej sugestii, ale powiedziałem, że btnOK_click nie istnieje w bieżącym kontekście. – Kael

+0

Czekajcie, to faktycznie działało. Próbowałem już tego wcześniej. Zamiast tego skopiowałem program "btnOK_click" poniżej SetRFIDText (Hexed) ;. Ale wygląda na to, że program jest w konflikcie z This.Close(); i Nieprawidłowy komunikat RFID pojawi się w tle. Dlaczego? – Kael

+0

Co to jest "ten" w kontekście wywołania funkcji? Czy możesz zamiast tego odwołać się do samego formularza (według nazwy)? Uniknęłoby to zamieszania i powinno działać (uważam ...) – Floris

1

Wystarczy oddzielić logikę przycisk 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(); 

} 
Powiązane problemy