I'm currently stuck with a small problem.
My program currently outputs a return value and puts it in a listbox with this method:
public override string ToString()
{
CheckKamer();
if (IsKamerBezet == true)
{
return $"Kamer: {Nummer} is bezet";
}
else
{
return $"Kamer: {Nummer} is vrij";
}
}
after that my program saves the return values provided by the method in a .txt file with this method:
private void ReserveringText()
{
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(filepath, true))
file.WriteLine(reserveringLB.Items.ToString());
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(filepath);
foreach (var item in reserveringLB.Items)
{
SaveFile.WriteLine(item.ToString());
}
}
Now when I restart my program it reads the lines put in the .txt file and sets it back in the listbox, with another simple method:
private void LaadItems()
{
var lines = File.ReadAllLines(filepath);
reserveringLB.DataSource = lines;
}
But whenever I try to add a new guest to my hotel, it says the object reference isnt set to an instance of the object, because it loads it from the .txt file and not from the class list I used to load it from.
My guest is added to the class here:
private void reserveerBtn_Click(object sender, EventArgs e)
{
Gast gast = new Gast(tbNaam1.Text, cbOntbijt1.Checked, cbDiner1.Checked, (Model.Enum.Geslacht)cbGeslacht1.SelectedValue);
Reservering reservering = new Reservering(vrijekamer, dateTimePicker1.Value, dateTimePicker2.Value, gast);
gast.Reservering = reservering;
admin.VoegGastToe(gast);
admin.VoegReserveringToe(reservering);
}
Could anyone help me out and tell me how I'd be able to let the program load the .txt file, and put that back into the List so I can actually add a guest to the program.
If anything is unclear please let me know, I'll be looking at this post alot so I can immediatly change it / add something if u guys need anything.