private void loadMacroPlan() { usersPlan = new MacroPlan(); try { var x = new XmlSerializer(typeof(MacroPlan)); var fs = new FileStream("macroPlan.xml", FileMode.Open); usersPlan = x.Deserialize(fs) as MacroPlan; fs.Close(); textBox2.Text = usersPlan.calorieGoal.ToString(); textBox3.Text = usersPlan.proteinGoal.ToString(); textBox5.Text = usersPlan.carbGoal.ToString(); textBox7.Text = usersPlan.fatGoal.ToString(); } catch (Exception e) { //No macro plan found, must make one newMacros formForMacros = new newMacros(usersPlan, this); formForMacros.Show(); } progressBar3.Maximum = usersPlan.calorieGoal; progressBar5.Maximum = usersPlan.proteinGoal; progressBar6.Maximum = usersPlan.carbGoal; progressBar7.Maximum = usersPlan.fatGoal; }
public newMacros(MacroPlan myPlan, Form primaryForm) { user = myPlan; primForm = primaryForm; InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { user = new MacroPlan((int)numericUpDown1.Value, (int)numericUpDown2.Value, (int)numericUpDown3.Value, (int)numericUpDown4.Value); Primary f1 = (Primary)primForm; f1.textBox2.Text = user.calorieGoal.ToString(); f1.textBox3.Text = user.proteinGoal.ToString(); f1.textBox5.Text = user.carbGoal.ToString(); f1.textBox7.Text = user.fatGoal.ToString(); //Now save to xml file var x = new XmlSerializer(typeof(MacroPlan)); //var fs = new FileStream("macroPlan.xml", FileMode.Open); var fs = new FileStream("macroPlan.xml", FileMode.Create); x.Serialize(fs, user); fs.Close(); this.Close(); }