Click here to Skip to main content
14,691,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a manufacturing form and the goals when I scan it with a barcode reader it should appear in the text boxes corresponding to the barcodes. It will also manufacture parts. When I ran it, the EmpID corresponds with the barcode but doesn't display the Employee name. As soon as I scan the barcode for the Part Number "P" appeared in the text and "1-1" appeared in the quantity textbox which it shouldn't then a message saying input string is not in the correct format.

this is my code:

private void txtEmpID_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)Keys.Enter)
    {
        txtPartNumber.Focus();
    }
}

private void txtPartNumber_KeyPress(object sender, KeyPressEventArgs e)
{
    txtQuantity.Focus();
}

private void txtQuantity_KeyPress(object sender, KeyPressEventArgs e)
{
    try
    {
        if (e.KeyChar == (char)Keys.Enter)
        {
            SQLInventoryClass MySQL = new SQLInventoryClass();
            int Quantity = int.Parse(txtQuantity.Text);
            lb1PartName.Text = MySQL.GetPartName(txtPartNumber.Text);
            if (txtPartNumber.Text == "p1-1" || txtPartNumber.Text == "p1-2" || txtPartNumber.Text == "p1-3" || txtPartNumber.Text == "p1-4")
            {
                MySQL.AddInventory(txtPartNumber.Text, 
                                  Int32.Parse(txtQuantity.Text), 
                                  txtEmpID.Text);
                lb1Status.Text = txtPartNumber.Text + " added ";
            }
            // Manufacture a p2-1
            else if (txtPartNumber.Text == "p2-1")
            {
                int numPart1 = MySQL.GetQuantity("p1-1");
                int numPart2 = MySQL.GetQuantity("p2-1");
                if  (numPart1 >= Quantity && numPart2 >= Quantity * 2)
                {
                    MySQL.RemoveInventory("p1-1", 1 * Quantity, txtEmpID.Text);
                    MySQL.RemoveInventory("p1-2", 2 * Quantity, txtEmpID.Text);
                    MySQL.AddInventory("p2-1", 1 * Quantity, txtEmpID.Text);
                    lb1Status.Text = "Quantity of " + txtQuantity.Text + " added with part number " + txtPartNumber.Text;
                    txtEmpID.Text = "";
                    txtPartNumber.Text = "";
                    txtQuantity.Text = "";
                    txtEmpID.Focus();
                }
                else
                {
                    lb1Status.Text = "Error: not enough parts in inventory of manufacture parts.";
                }
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


What I have tried:

I have tried googling the problem, I emailed my instructor early but receive no response. I used the debugger and went in step over the code.
Posted
Updated 20-Oct-20 22:39pm
v3
Comments
Gerry Schmitz 20-Oct-20 21:13pm
   
You said a lot but not what the barcode reader is actually reporting. You "bullet-proof" the barcode reader process; only then do you start worrying about text boxes, SQL, and the rest. Logging everything the barcode reader reports would be a good start.
kumih101 20-Oct-20 21:41pm
   
actually, my instructor shipped a barcode reader to us so already been through the process, I just trying to figure out why it keeps on saying "input string is not the correct format?
BillWoodruff 21-Oct-20 5:45am
   
why do you think your instructor has not responded ? have you put breakpoints, and single-stepped through the code to find out where the error occurs ?
kumih101 21-Oct-20 9:29am
   
Yeah I figure out the problem, it was because I didn't put an if statement

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900