How to capture whole Barcode value on Winform without using TextChanged event?

后端 未结 3 454
广开言路
广开言路 2020-12-06 19:10

When a barcode is scanned on form1, I make a call to database to get the item for this barcode and open form2 with pre-populated data.

If I use text changed event t

3条回答
  •  一向
    一向 (楼主)
    2020-12-06 19:48

    You could try to let the event wait for 1 second, or long enough to finish scanning

    private async void txt_Barcode_TextChanged(object sender, EventArgs e)
    {
        await Task.Delay(1000);
        con.Open();
        GenerateInvoice gn = new GenerateInvoice();
        string query = "SELECT * FROM dbo.Inventory WHERE Barcode = '" + txt_Barcode.Text + "' ";
    
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataReader dr = cmd.ExecuteReader();
    
    
        while (DR1.Read())
        {
            gn.txt_Barcode.Text = dr["Barcode"].ToString();
            gn.txt_ProductName.Text = dr["ProductName"].ToString();
            gn.txt_Price.Text = dr["SellingPrice"].ToString();
            gn.txt_QTY.Text = 1.ToString();
            gn.txt_Total.Text = dr["SellingPrice"].ToString();
    
        }
        con.Close();
    }
    

提交回复
热议问题