❔ winforms storage system (beginner)
I'm new to winforms and for school I have to make a storage system. I'm completly done the only thing that doesn't work is the selling of shoes, I have no idea how to implement this.
I use a datagridview to show the storage, the person selling has a textbox and a button where they can first put the number in the textbox and then click the button to remove x amount of shoes
this is my code:
if there is anything else you spot wrong with the code please let me know!
88 Replies
thats literally just the code that sets up the view
you are not showing your
vooraad
and its declaration, which is where you actually store your dataThis is the vooraad class
and this is the program I hard coded a shoe in here just for testing
sorry I forgot
okay
idk dutch, so i don't know if
32
or 200
is your "number of shoes in storage"
but I see an issue here
your data is all strings
its hard to do math on strings, as they are... well, not numbersit's the 0 at the end
how can you sell shoes with 0 in storage? 😛
I should change that ye xD
they call that a
promise
, sometimes a future
I changed it to 10 for now
well, thats honestly not your biggest problem.
Your problem is that
string
is a poor datatype for numbersOn my other menu the manger can add shoes by adding them I can send that part of the code aswell?
that can wait
we need to fix your data types
do you know any numeric data types, of the top of your head?
things like int and float?
yep!
oh ye
int
being whole numbers, and float
being numbers with decimals
ie 5
vs 7.1234
so which one would be good for storing the amount of shoes?so I would use int and not string
sounds good!
but
isnt going to work is it?
nope you pharse the string to an int right
no
have you learned about classes yet?
not really I asked my teacher but he just made one for me without really explaining saying "we teach that later"
thats weird
you sorta need that to solve this problem nicely
the problem we have that a line in your datagrid should represent a single item
I know you can make them to use them for making "databases" without having a real database or smth like that
one
ShoeListing
or ShoeInventoryRow
or something
unrelated.
lets leave the shoe world for a whilealright
lets say that you want to represent a person, with name and date of birth
a single person has ONE name and ONE date of birth. They must always have both.
we want these values to be linked somehow
can you think of a way to do so right now?
could you use a list or array for that? or am I just completely miss
not really
both lists and arrays are for storing multiple things of the same type
the real answer here is to make a new type
we MAKE a new type that represents out
Person
ah I see, so just for my understanding a type is the
public class person
part?Person
is the typeI see
the
class
is the keyword that declares that this is a class
(there are other things that are also types, such as structs, enums, records etc)
but for now lets keep it simple and care only about classesalright
so, lets make a type that represents your shoe-inventory
can you try and show me what you come up with?
`
would it be something like this? or do I miss understand
Oh, I meant each individual row 🙂
ah
Like, make a type that represents
{ "Nike ", "Airmax ", 32, "Zwart ", 200, 10};
like this?
Almost!
Can you think of a better data type for a price?
int!
Sure! Or maybe even
decimal
in case we want to be able to say that the price is 199.99
oh ye true because you work with number behind the .
Also, C# naming convention says that classes and properties should be
PascalCased
so begin with a capital letteraha got it
so would I make a new class for this or do I add it to my existing code?
are those not the same thing? 🙂
oh they are? 😅
sounds like it to me 😄
aha good to know, so this is added to the first piece of code I sended?
Oh, it goes in its own file
ideally
so I creat another one of these? If I understand correctly
Yeah
thats a code file
Alright I have done that
Cool
so, now lets replace that string array we had to keep track of our inventory
this one right?
uh yeah, that too
I was thinking about
but they both need to be changed
so I replace them with the public class or?
no, we replace the types 🙂
public static List<string[]> schoenenvoorraad
is a list of string arrays
we want this to be a... ?class?
no, we already have the class
you made it before, ye?
this
yes
thats the one
fix the class name would you?
AantalVooraad
if nothing elseshould I just change it to
Voorraad
Doesnt that mean "Storage"?
Yes
I think thats a bad name to be honest
How about
ShoeListing
, or ShoeInventoryRow
?
you can translate as neededAlright that does sound abit more clear indeed
we want our names to accurately represent their content
I have changed it to ShoeListing
ok
that is the name of your type
our datagrid is a list of shoe listings
what is a type that would accurately represent that?
string?
really?
I think you already know the type for a list, no?
I have not heared of that I have only heared of just list
Look here
class?
What do you think
List<string[]>
is?ph
oh
array
no
its a...
?
list array?
its a list of...?
insert the last words 😛
I'm sorry I'm not really concentrated my normal lesson just started 😅
Pay attention to your class then 🙂
this thread isnt going anywhere
Alright, I think I can mess around from here myself!
Still thanks tho and for having the patience to help me!
I'm still here if you need help. And there are a few steps we skipped
that I think you need to do
Alright I'll mess around when my lesson is done thank you so much for the help
np
The answer I was looking for was
A list of string arrays
btwah thanks
List<T>
where T = string[]
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.