C
C#10mo ago
Gijs

❔ 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:
Public mwVoorraad()
{

InitializeComponent();
FillDataGrid();

}
public void FillDataGrid()
{
dt.Rows.Clear();
dt.Columns.Clear();
dt.Columns.Add("Merk");
dt.Columns.Add("Type");
dt.Columns.Add("Maat");
dt.Columns.Add("Kleur");
dt.Columns.Add("Prijs");
dt.Columns.Add("Aantal");

foreach (string[] schoen in voorraad.schoenenvoorraad)
{
dt.Rows.Add(schoen);
}
dgvAdmin.DataSource = dt;
}

private void btVerkoop_Click(object sender, EventArgs e)
{

}

private void btBackToMenu_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Public mwVoorraad()
{

InitializeComponent();
FillDataGrid();

}
public void FillDataGrid()
{
dt.Rows.Clear();
dt.Columns.Clear();
dt.Columns.Add("Merk");
dt.Columns.Add("Type");
dt.Columns.Add("Maat");
dt.Columns.Add("Kleur");
dt.Columns.Add("Prijs");
dt.Columns.Add("Aantal");

foreach (string[] schoen in voorraad.schoenenvoorraad)
{
dt.Rows.Add(schoen);
}
dgvAdmin.DataSource = dt;
}

private void btVerkoop_Click(object sender, EventArgs e)
{

}

private void btBackToMenu_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
if there is anything else you spot wrong with the code please let me know!
88 Replies
Pobiega
Pobiega10mo ago
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 data
Gijs
Gijs10mo ago
This is the vooraad class
internal class voorraad
{
public static List<string[]> schoenenvoorraad = new List<string[]>();

}
internal class voorraad
{
public static List<string[]> schoenenvoorraad = new List<string[]>();

}
and this is the program I hard coded a shoe in here just for testing
static void Main()
{

string[] schoen1 = { "Nike ", "Airmax ", "32 ", "Zwart ", "200 ", "0 "};
voorraad.schoenenvoorraad.Add(schoen1);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new inlogMenu());
}
static void Main()
{

string[] schoen1 = { "Nike ", "Airmax ", "32 ", "Zwart ", "200 ", "0 "};
voorraad.schoenenvoorraad.Add(schoen1);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new inlogMenu());
}
sorry I forgot
Pobiega
Pobiega10mo ago
okay idk dutch, so i don't know if 32 or 200is 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 numbers
Gijs
Gijs10mo ago
it's the 0 at the end
Pobiega
Pobiega10mo ago
how can you sell shoes with 0 in storage? 😛
Gijs
Gijs10mo ago
I should change that ye xD
ffmpeg -i me -f null -
they call that a promise, sometimes a future
Gijs
Gijs10mo ago
I changed it to 10 for now
Pobiega
Pobiega10mo ago
well, thats honestly not your biggest problem. Your problem is that string is a poor datatype for numbers
Gijs
Gijs10mo ago
On my other menu the manger can add shoes by adding them I can send that part of the code aswell?
Pobiega
Pobiega10mo ago
that can wait we need to fix your data types do you know any numeric data types, of the top of your head?
Gijs
Gijs10mo ago
things like int and float?
Pobiega
Pobiega10mo ago
yep!
Gijs
Gijs10mo ago
oh ye
Pobiega
Pobiega10mo ago
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?
Gijs
Gijs10mo ago
so I would use int and not string
Pobiega
Pobiega10mo ago
sounds good! but
string[] schoen1 = { "Nike ", "Airmax ", 32, "Zwart ", 200, 10};
string[] schoen1 = { "Nike ", "Airmax ", 32, "Zwart ", 200, 10};
isnt going to work is it?
Gijs
Gijs10mo ago
nope you pharse the string to an int right
Pobiega
Pobiega10mo ago
no have you learned about classes yet?
Gijs
Gijs10mo ago
not really I asked my teacher but he just made one for me without really explaining saying "we teach that later"
Pobiega
Pobiega10mo ago
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
Gijs
Gijs10mo ago
I know you can make them to use them for making "databases" without having a real database or smth like that
Pobiega
Pobiega10mo ago
one ShoeListing or ShoeInventoryRow or something unrelated. lets leave the shoe world for a while
Gijs
Gijs10mo ago
alright
Pobiega
Pobiega10mo ago
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?
Gijs
Gijs10mo ago
could you use a list or array for that? or am I just completely miss
Pobiega
Pobiega10mo ago
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
public class Person
{
public string Name { get; set; }
public DateTimeOffset DateOfBirth { get; set; }
}
public class Person
{
public string Name { get; set; }
public DateTimeOffset DateOfBirth { get; set; }
}
Gijs
Gijs10mo ago
ah I see, so just for my understanding a type is the public class person part?
Pobiega
Pobiega10mo ago
Person is the type
Gijs
Gijs10mo ago
I see
Pobiega
Pobiega10mo ago
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 classes
Gijs
Gijs10mo ago
alright
Pobiega
Pobiega10mo ago
so, lets make a type that represents your shoe-inventory can you try and show me what you come up with?
Gijs
Gijs10mo ago
public class voorraad
{
public int ShoeListing { get; set; }
pubic ShoeInventoryRow { get; set; }
}
public class voorraad
{
public int ShoeListing { get; set; }
pubic ShoeInventoryRow { get; set; }
}
` would it be something like this? or do I miss understand
Pobiega
Pobiega10mo ago
Oh, I meant each individual row 🙂
Gijs
Gijs10mo ago
ah
Pobiega
Pobiega10mo ago
Like, make a type that represents { "Nike ", "Airmax ", 32, "Zwart ", 200, 10};
Gijs
Gijs10mo ago
public class voorraad
{
public string brand { get; set; }
pubic string type { get; set; }
public string size { get; set; }
public string color { get; set; }
public decimal price { get; set; }
public int amount { get; set; }
}
public class voorraad
{
public string brand { get; set; }
pubic string type { get; set; }
public string size { get; set; }
public string color { get; set; }
public decimal price { get; set; }
public int amount { get; set; }
}
like this?
Pobiega
Pobiega10mo ago
Almost! Can you think of a better data type for a price?
Gijs
Gijs10mo ago
int!
Pobiega
Pobiega10mo ago
Sure! Or maybe even decimal in case we want to be able to say that the price is 199.99
Gijs
Gijs10mo ago
oh ye true because you work with number behind the .
Pobiega
Pobiega10mo ago
Also, C# naming convention says that classes and properties should be PascalCased so begin with a capital letter
Gijs
Gijs10mo ago
aha got it so would I make a new class for this or do I add it to my existing code?
Pobiega
Pobiega10mo ago
are those not the same thing? 🙂
Gijs
Gijs10mo ago
oh they are? 😅
Pobiega
Pobiega10mo ago
sounds like it to me 😄
Gijs
Gijs10mo ago
aha good to know, so this is added to the first piece of code I sended?
Pobiega
Pobiega10mo ago
Oh, it goes in its own file ideally
Gijs
Gijs10mo ago
so I creat another one of these? If I understand correctly
No description
Pobiega
Pobiega10mo ago
Yeah thats a code file
Gijs
Gijs10mo ago
Alright I have done that
Pobiega
Pobiega10mo ago
Cool so, now lets replace that string array we had to keep track of our inventory
Gijs
Gijs10mo ago
internal class voorraad
{
public static List<string[]> schoenenvoorraad = new List<string[]>();

}
internal class voorraad
{
public static List<string[]> schoenenvoorraad = new List<string[]>();

}
this one right?
Pobiega
Pobiega10mo ago
uh yeah, that too I was thinking about
string[] schoen1 = { "Nike ", "Airmax ", "32 ", "Zwart ", "200 ", "0 "};
voorraad.schoenenvoorraad.Add(schoen1);
string[] schoen1 = { "Nike ", "Airmax ", "32 ", "Zwart ", "200 ", "0 "};
voorraad.schoenenvoorraad.Add(schoen1);
but they both need to be changed
Gijs
Gijs10mo ago
so I replace them with the public class or?
Pobiega
Pobiega10mo ago
no, we replace the types 🙂 public static List<string[]> schoenenvoorraad is a list of string arrays we want this to be a... ?
Gijs
Gijs10mo ago
class?
Pobiega
Pobiega10mo ago
no, we already have the class you made it before, ye? this
Gijs
Gijs10mo ago
yes
No description
Pobiega
Pobiega10mo ago
thats the one fix the class name would you? AantalVooraad if nothing else
Gijs
Gijs10mo ago
should I just change it to Voorraad
Pobiega
Pobiega10mo ago
Doesnt that mean "Storage"?
Gijs
Gijs10mo ago
Yes
Pobiega
Pobiega10mo ago
I think thats a bad name to be honest How about ShoeListing, or ShoeInventoryRow? you can translate as needed
Gijs
Gijs10mo ago
Alright that does sound abit more clear indeed
Pobiega
Pobiega10mo ago
we want our names to accurately represent their content
Gijs
Gijs10mo ago
I have changed it to ShoeListing
Pobiega
Pobiega10mo ago
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?
Gijs
Gijs10mo ago
string?
Pobiega
Pobiega10mo ago
really? I think you already know the type for a list, no?
Gijs
Gijs10mo ago
I have not heared of that I have only heared of just list
Pobiega
Pobiega10mo ago
Look here
Gijs
Gijs10mo ago
class?
Pobiega
Pobiega10mo ago
What do you think List<string[]> is?
Gijs
Gijs10mo ago
ph oh array
Pobiega
Pobiega10mo ago
no its a... ?
Gijs
Gijs10mo ago
list array?
Pobiega
Pobiega10mo ago
its a list of...? insert the last words 😛
Gijs
Gijs10mo ago
I'm sorry I'm not really concentrated my normal lesson just started 😅
Pobiega
Pobiega10mo ago
Pay attention to your class then 🙂 this thread isnt going anywhere
Gijs
Gijs10mo ago
Alright, I think I can mess around from here myself! Still thanks tho and for having the patience to help me!
Pobiega
Pobiega10mo ago
I'm still here if you need help. And there are a few steps we skipped that I think you need to do
Gijs
Gijs10mo ago
Alright I'll mess around when my lesson is done thank you so much for the help
Pobiega
Pobiega10mo ago
np The answer I was looking for was A list of string arrays btw
Gijs
Gijs10mo ago
ah thanks
Pobiega
Pobiega10mo ago
List<T> where T = string[]
Accord
Accord10mo ago
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.
Want results from more Discord servers?
Add your server
More Posts