private void buttonAdd_Click(object sender, RoutedEventArgs e) { if (IsNotEmpty(textBoxWEP_Name) & IsNotEmpty(textBoxWEP_Surname)) { var currentFootballer = new Footballer(textBoxWEP_Name.Text.Trim(), textBoxWEP_Surname.Text.Trim(), (uint)sliderAge.Value, (uint)sliderWeight.Value); var onList = false; foreach (var p in listBoxFootballer.Items) { var fballer = p as Footballer; if (fballer.isTheSame(currentFootballer)) { onList = true; break; } } if (!onList) { listBoxFootballer.Items.Add(currentFootballer); Clear(); } else { var dialog = MessageBox.Show($"{currentFootballer.ToString()} już jest na liście {Environment.NewLine} Czy wyczyścić formularz?", "Uwaga", MessageBoxButton.OKCancel); if (dialog == MessageBoxResult.OK) { Clear(); } } } }
private void buttonDelete_Click(object sender, RoutedEventArgs e) { var currentFootballer = new Footballer(textBoxWEP_Name.Text.Trim(), textBoxWEP_Surname.Text.Trim(), (uint)sliderAge.Value, (uint)sliderWeight.Value); var dialog = MessageBox.Show($"Czy na pewno chcesz usunąć {currentFootballer.ToString()} z listy?", "Uwaga", MessageBoxButton.OKCancel); if (dialog == MessageBoxResult.OK) { listBoxFootballer.Items.Remove(listBoxFootballer.SelectedItem); Clear(); } }
private void buttonEdit_Click(object sender, RoutedEventArgs e) { if (IsNotEmpty(textBoxWEP_Name) & IsNotEmpty(textBoxWEP_Surname)) { var currentFootballer = new Footballer(textBoxWEP_Name.Text.Trim(), textBoxWEP_Surname.Text.Trim(), (uint)sliderAge.Value, (uint)sliderWeight.Value); var onList = false; foreach (var p in listBoxFootballer.Items) { var fballer = p as Footballer; if (fballer.isTheSame(currentFootballer)) { onList = true; break; } } if (!onList) { var dialogResult = MessageBox.Show($"Czy na pewno chcesz zmienić dane {Environment.NewLine} {listBoxFootballer.SelectedItem}?", "Edycja", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { var selectedFootballer = (Footballer)listBoxFootballer.SelectedItem; selectedFootballer.Name = currentFootballer.Name; selectedFootballer.Surname = currentFootballer.Surname; selectedFootballer.Age = currentFootballer.Age; selectedFootballer.Weight = currentFootballer.Weight; listBoxFootballer.Items.Refresh(); } Clear(); listBoxFootballer.SelectedIndex = -1; } else { MessageBox.Show($"{currentFootballer.ToString()} już jest na liście.", "Uwaga"); } } }