Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm working on c# winform application.
I develop an inventory management system. my software work with a Barcode scanner.

I want once I scan a barcode if the Item Stock not available then it shows a message
"Out of Stock item"

i try this but the message box not working with the barcode scanner.
i try this

What I have tried:

once I scan the barcode then I want to check the Condition if the Qty less than 0 then it shows the message Box.

if(Qty<0)
{
MessageBox.show("Out of Stock item");
}

Software checks the condition if the condition is right then it enters in Condition Code successfully but it does not show a message box.

need Experts help I try many time but unable to find the solution

Note: If I type any number in the textbox with the help of the keyboard then the message box show Successfully.
Posted
Updated 22-Apr-21 19:48pm
Comments
Dave Kreskowiak 23-Apr-21 0:17am    
Well, since all we have to work with is what you type, it's impossible to tell you what's going wrong.

So, whatever is setting the value of Qty needs to be looked at, and everything between the code that receives the barcode, looking up a tag in a database, to this one little check for Qty that you gave us.

But, since you kept all the code secret, ...
OriginalGriff 23-Apr-21 1:04am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

We can't answer this with any specifics, there are just too many possible ways you might be working this - and we have no idea at all what you have tried!

So what I'll do is explain what I would do to make this work.

First off, the barcode data.
That's a problem, because most scanners are shipped configured to act like a keyboard: when you scan the barcode, what your computer gets is a sequence of keystrokes, and it can't tell if they were typed or scanned - Windows doesn't "tag" keyboard data with the source at all and there is no way at all to know if a digit or digits came from a user typing or a scanner scanning.
So what that means is that when you scan a barcode, the data doesn't go automatically to a particular text box, or any other location: it is entered exactly where the user left the input focus!
There is a way round that: most scanners can be configured to give you a "lead in" and "tail out" sequence that your code can detect and move the input to the appropriate text box, clear it, and be ready to process. But ... how you configure it depends on the scanner manufacturer and often the actual model as well. So you need to start by finding out who made your scanner and how you configure it. We can't help you with that at all!

Once data is entered / entering into a text box, you can handle the TextChanged event for it and process the data. Most barcodes include checksums, and it's worth checking these if they are present to make sure what is entered is valid before going any further.
Again, we can't help you with this as there are many different types of barcode, and the data they encode varies: some barcodes only allow 8 digits, others allow hundreds of "free text" data, or even formatted data with prices, serial numbers, and so on as fields within the single barcode data stream.

But ... once you have what is called the Article Number (the numeric bit that uniquely identifies a product) you can cross reference that against your data source to find out how much you sell it for, how many you have, and so on.
Your data source can be anything - but I'd probably use a database, and I'd probably use a server based SQL DB (such as SQL Server) because this is the kind of app that quickly becomes multiuser.
Pass the article number to the DB - as a parameter, never concatenate strings to form SQL commands - and get the quantity from there.

Why would a quantity be negative? This isn't a bank account, that you can become overdrawn - you don't have a negative quantity of anything in the "real world" because that means you have taken 10 items out of a stock that only even held 5! If it's silly in the real world, it's silly in your model.

Compare that against what you have in your design, and see where it differs.
 
Share this answer
 

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