Beispiel #1
0
 private void ÖppnaKnapp_Click(object sender, RoutedEventArgs e)
 {
     if (File.Exists("peoplelist.bin"))
     {
         //List<Person> peoplelist = new List<Person>();
         peoplelist = (List <Person>)FileOperations.Deserialize("peoplelist.bin");
         for (int j = 0; j < peoplelist.Count; j++)
         {
             candyCalculator.AddPerson(peoplelist[j]);
         }
         for (int i = 0; i < peoplelist.Count; i++)
         {
             List1.Items.Add($"{peoplelist[i].Firstname} ({peoplelist[i].Age} år) ");
         }
     }
 }
Beispiel #2
0
        }  // spar mitt program

        private void BtnAddPerson_Click(object sender, RoutedEventArgs e)
        {
            string name = InputNamne.Text;
            int    age  = int.Parse(InPutAge.Text);

            candyCalculator.AddPerson(name, age);
            ListBox.ItemsSource = null;
            ListBox.ItemsSource = candyCalculator.GetPeople();
        } // lägger till nya personer
        public MainWindow()
        {
            InitializeComponent();

            if (File.Exists("CandyCalculator.bin"))
            {
                PersonList.ItemsSource = (List <Person>)FileOperations.Deserialize("CandyCalculator.bin");
                foreach (Person p in PersonList.ItemsSource)
                {
                    cHandler.AddPerson(p);
                }
            }

            if (File.Exists("CandyCalculator_Original.bin"))
            {
                foreach (Person p in (List <Person>)FileOperations.Deserialize("CandyCalculator_Original.bin"))
                {
                    cOriginalList.Add(p);
                }
            }
        }