private void CalculateCandies_Click(object sender, RoutedEventArgs e)
        {
            switch (selectedRb)
            {
            case 1:
                cHandler.DivideCandyByAge(Convert.ToInt32(CandiesTotal.Text));
                PersonList.ItemsSource = null;
                PersonList.ItemsSource = cHandler.SortByAge();
                break;

            case 2:
                cHandler.DivideCandy(Convert.ToInt32(CandiesTotal.Text));
                PersonList.ItemsSource = null;
                PersonList.ItemsSource = cHandler.SortByName();
                break;

            case 3:
                cHandler.DivideCandy(Convert.ToInt32(CandiesTotal.Text));
                PersonList.ItemsSource = null;
                PersonList.ItemsSource = cOriginalList;
                break;

            default:
                cHandler.DivideCandy(Convert.ToInt32(CandiesTotal.Text));
                PersonList.ItemsSource = null;
                PersonList.ItemsSource = cOriginalList;
                break;
            }
        }
Beispiel #2
0
        } // lägger till nya personer

        private void Button_Click_1(object sender, RoutedEventArgs e) // knapp som fördelar godisar efter önskad sortering
        {
            int input = int.Parse(InNumOfC.Text);

            if (BtnAge.IsChecked == true)
            {
                candyCalculator.DivideCandyByAge(input);
                ListBox.ItemsSource = null;
                ListBox.ItemsSource = candyCalculator.GetPeopleByAge();
            }

            if (BtnLetter.IsChecked == true)
            {
                candyCalculator.DivideCandyByName(input);
                ListBox.ItemsSource = null;
                ListBox.ItemsSource = candyCalculator.GetPeopleByName();
            }

            if (BtnOriginal.IsChecked == true)
            {
                candyCalculator.DivideCandy(input);
                ListBox.ItemsSource = null;
                ListBox.ItemsSource = candyCalculator.GetPeople();
            }
        }
Beispiel #3
0
 private void Fördelagodisknapp_Click(object sender, RoutedEventArgs e)
 {
     peoplelist = candyCalculator.GetPeople();
     List1.Items.Clear();
     if (Åldersknapp.IsChecked == true)
     {
         peoplelist = candyCalculator.DivideCandyByAge(peoplelist);
     }
     if (Bokstavsordningsknapp.IsChecked == true)
     {
         peoplelist = candyCalculator.DivideCandyByName(peoplelist);
     }
     candyCalculator.DivideCandy(peoplelist, double.Parse(Antalgodisbox.Text));
     for (int i = 0; i < peoplelist.Count; i++)
     {
         List1.Items.Add($"{peoplelist[i].Firstname} ({peoplelist[i].Age} år): ---> {(peoplelist[i].Candies)} godisar");
     }
 }