Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am to the point in my application where I need to create an inventory sheet in my windows form in visual basic and have it link to my order form and allow the order form to make sure that there is enough inventory to create the sandwich and also have the inventory modified every time there are ingredients used.

I have heard of data databases but I have only created very simple programs and I don't see how I'll be able to reduce the inventory value from the GUI end where the order and depletion will happen. I have been playing around with the idea in my head about making the inventory page just consist of labels with the description of the product and text boxes with the amount left and group them all in a groupbox. And then in the inventory source code I could do this:

What I have tried:

foreach (var checkBox in ctrl.Controls.OfType<checkbox>())
{
Total = checkBox.Checked
? (Total + Convert .ToDouble(checkBox .Tag))
: Total;
}
except I am not getting how to connect the inventory amounts on the inventory page to the checkboxes that I have . Say I have a checkbox and its called roast beef. and i check the box. now I have to get the text from the checkbox and compare it to the variable for the inventory nin the other class.

selection = checkbox.Text;
foreach (var item in inventoryGroupBox)
{
if ( item == selection)
if ( selection >= item)
total += itemPrice;
}

I have searched and searched the internet for a jumping off point to no avail. If I could just be nudged in the right direction. I have been stuck on this for four days!

I hope this is making sense. I am at a stand still and I cant seem to type the right thing into google to even find a way to add a page to a form. Am i going in the right direction?
Thank you
Posted
Updated 13-Nov-18 22:24pm

1 solution

The labels idea is probably not a good one.

The database on the other hand ...

Stop and think about what you are trying to do: it's a sandwich shop yes?
So your inventory consists of 10 portions of tomato, 6 portions of lettuce, 1 portions of cucumber, 3 of cheese, 12 of ham, and 100 slices of bread.
I walk in and order a ham sandwich. You use 1 tomato, 1 lettuce, 1 cucumber, 1 ham, two slices of bread (and I complain about the lack of mayo)

So you need to remove what you used from your inventory, and most important of all save the new values so when you run your app for the next customer you know he can't have a ham salad because you are out of cucumber. This is called persistent data and it means that changes you make are maintained so that your app always has the current values.

Doing this with labels is a PITA for two reasons:
1) Labels don't store numbers, they store text - so every time you want to check or change it you have to convert it to a number, and then back to text when you are done.
2) Labels aren't persistent - they go back to the "starting value" every time you app is run.

And this is where a database comes in: it stores data so you can access it later, and allows you to update values as well as fetch the current numbers. Plus, if your shop gets busy and you need another staff member, the database allows you to share the information so you are both working with the same inventory.

I'm not going to try and explain how to use a DB - heck there are whole books written on that! - but a quick google for the name of whatever DB you have installed (Access, SQL Server, SqlLite, MySql, Oracle are all possible here) and "C# tutorial" will find you loads of beginner information to get you started.
Have fun!
 
Share this answer
 
Comments
Member 14054067 14-Nov-18 4:31am    
Thank you very much. I have been dismissing the database idea. That's the nudge I needed. :)
OriginalGriff 14-Nov-18 4:40am    
You're welcome!

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