private void buttonDodaj_Click(object sender, RoutedEventArgs e) { // var button = sender as Button; if (isValid(forename) & isValid(surname) & isValid(sliderAge) & isValid(sliderWeight)) { var newPlayer = new Pilkarz(forename.Text, surname.Text, sliderAge.Value, sliderWeight.Value); if (!isDuplicate(newPlayer)) { listBoxPilkarze.Items.Add(newPlayer); Clear(); } else { var dialog = MessageBox.Show($"{newPlayer.ToString()} już jest na liście {Environment.NewLine} Czy wyczyścić formularz?", "Uwaga", MessageBoxButton.OKCancel); if (dialog == MessageBoxResult.OK) { Clear(); } } } // var button = sender as Button; // to jest referencja, jezeli button to zrzuca a jak nie to null ?? zabezpieczenie null // var button=(Button)sender tutaj jak nie zrzutuje to wywali wyjatek // textBoxName.Text = button.Content.ToString();// wyciąganie tego kto jest senderem }
private void buttonEdytuj_Click(object sender, RoutedEventArgs e) { var biezacyPilkarz = new Pilkarz(forename.Text.Trim(), surname.Text.Trim(), (uint)sliderAge.Value, (uint)sliderWeight.Value); if (!isDuplicate(biezacyPilkarz)) { var dialogResult = MessageBox.Show($"Czy na pewno chcesz zmienić dane {Environment.NewLine} {listBoxPilkarze.SelectedItem}?", "Edycja", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { //zamiana refernecji do obiektu piłkarza edytowanego //zmień implementację tak aby zmieniać stan obiektu a nie podmieniać referencję //zrobione Pilkarz selected = listBoxPilkarze.Items[listBoxPilkarze.SelectedIndex] as Pilkarz; selected.Copy(biezacyPilkarz); listBoxPilkarze.Items.Refresh(); } Clear(); listBoxPilkarze.SelectedIndex = -1; } else { MessageBox.Show($"{biezacyPilkarz.ToString()} już jest na liście.", "Uwaga"); } }