so I've made a simple program meant to increase and decrease numbers, then save those numbers, basically a rubbish stock taking app, I want to make one I can use and well it's usable I'd say the code isn't refined enough to take it from this little program to a bigger better one. I want to make one because I want to practice programming more and I want a simple program that works well with a tablet. I'm wondering if there is a better way to program the buttons and the way it saves and loads more efficiently I don't want every button to have the same code but I can't seem to figure out how. Thanks
This was done with C# in Windows forms
The top section of my code saves it, the middle loads it and the long repetitive end are all the buttons, there is also an attempt to make a timer in there
Code in text:
using (StreamWriter outputfile = new
StreamWriter($@"SaveData.txt"))
{
//Loads the stuff from the last session
string OutPut = Item1.Text + "\n" + Amount1.Text + "\n" + Item2.Text + "\n" + Amount2.Text + "\n" + Item3.Text + "\n" + Amount3.Text
+ "\n" + Item4.Text + "\n" + Amount4.Text + "\n" + Item5.Text + "\n" + Amount5.Text + "\n" + Item6.Text + "\n" + Amount6.Text;
outputfile.WriteLine(OutPut);
};
z
Save.Text = "Saved";
//My attempt to make a timer v
{
/*
My attempt at making the saved button count up.
for (int a = 0; a < 60; a++)
{
int savedSince = a;
Save.Text = "Saved" + " " + Convert.ToString(savedSince);
Task.Delay(1000);
}
Save.Text = "Saved <1 Min";
*/
}
}
private void Load_Click(object sender, EventArgs e)
{
using (StreamReader inputfile = new StreamReader($@"SaveData.txt"))
{
//This is to load everything by reading the text file line by line for each thing.
Item1.Text = inputfile.ReadLine();
Amount1.Text = inputfile.ReadLine();
Item2.Text = inputfile.ReadLine();
Amount2.Text = inputfile.ReadLine();
Item3.Text = inputfile.ReadLine();
Amount3.Text = inputfile.ReadLine();
Item4.Text = inputfile.ReadLine();
Amount4.Text = inputfile.ReadLine();
Item5.Text = inputfile.ReadLine();
Amount5.Text = inputfile.ReadLine();
Item6.Text = inputfile.ReadLine();
Amount6.Text = inputfile.ReadLine();
}
}
/*
The first one adds 1 to the count by taking the text box and turning it into an int
then taking the new int and turning it into a string and replacing the text box with it,
same for the second one but it takes one off, then it repeats for the next two buttons
and so on
*/
private void Add1_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount1.Text) + 1;
Amount1.Text = Convert.ToString(amount);
}
private void Decrease1_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount1.Text) - 1;
Amount1.Text = Convert.ToString(amount);
}
private void Add2_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount2.Text) + 1;
Amount2.Text = Convert.ToString(amount);
}
private void Decrease2_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount2.Text) - 1;
Amount2.Text = Convert.ToString(amount);
}
private void Add3_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount3.Text) + 1;
Amount3.Text = Convert.ToString(amount);
}
private void Decrease3_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount3.Text) - 1;
Amount3.Text = Convert.ToString(amount);
}
private void Add4_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount4.Text) + 1;
Amount4.Text = Convert.ToString(amount);
}
private void Decrease4_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount4.Text) - 1;
Amount4.Text = Convert.ToString(amount);
}
private void Add5_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount5.Text) + 1;
Amount5.Text = Convert.ToString(amount);
}
private void Decrease5_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount5.Text) - 1;
Amount5.Text = Convert.ToString(amount);
}
private void Add6_Click(object sender, EventArgs e)
{
int amount = Convert.ToInt32(Amount6.Text) + 1