private void buttonOK_Click(object sender, RoutedEventArgs e) { if (isNoEmpty(tbName) & isNoEmpty(tbSurname)) { var currentFootballer = new Footballer(tbName.Text.Trim(), tbSurname.Text.Trim(), Convert.ToByte(cbAge.Text), (float)slweight.Value); bool isOnList = false; foreach (var p in lb_LisOfPlayers.Items) { var pilkarz = p as Footballer; if (pilkarz.isInList(currentFootballer)) { isOnList = true; break; } } if (isOnList == false) { lb_LisOfPlayers.Items.Add(currentFootballer); ResetValues(); } else { var dialog = MessageBox.Show("Piłkarz którego chcesz dodać jest już na liście!", "Uwaga", MessageBoxButton.OK); ResetValues(); } } }
private void IsSelect(object sender, SelectionChangedEventArgs e) { //lb_LisOfPlayers.SelectedIndex != -1 if (sender != null && lb_LisOfPlayers.SelectedIndex != -1) { Footballer player = (Footballer)lb_LisOfPlayers.SelectedItem; tbName.Text = player.getName(); tbSurname.Text = player.getSurname(); slweight.Value = player.getWeight(); cbAge.Text = player.getAge().ToString(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { string[] lines = File.ReadAllLines(@"E:\SemestrIV\.NET\FootballersForm\FootballersForm\dane.txt"); foreach (string line in lines) { lb_LisOfPlayers.Items.Add(Footballer.FootballerReadyToAdd(line)); } } catch { MessageBox.Show("Nie udało się wczytać danych z pliku! Sprawdź czy plik istenieje i jego poporawność"); } }
public bool isInList(Footballer pilkarz) { if (pilkarz._name != _name) { return(false); } if (pilkarz._surname != _surname) { return(false); } if (pilkarz._age != _age) { return(false); } if (pilkarz._weight != _weight) { return(false); } return(true); }
private void ModifyFootballer(object sender, RoutedEventArgs e) { if (lb_LisOfPlayers.SelectedIndex != -1) { var dialog = MessageBox.Show("Czy na pewno chcesz modyfikować dane piłkarza?", "Uwaga", MessageBoxButton.OKCancel); int index = 0; if (dialog == MessageBoxResult.OK) { index = lb_LisOfPlayers.SelectedIndex; // lb_LisOfPlayers.SelectedIndex = -1; if (index != -1 && isNoEmpty(tbName) & isNoEmpty(tbSurname)) { var currentFootballer = new Footballer(tbName.Text.Trim(), tbSurname.Text.Trim(), Convert.ToByte(cbAge.Text), (float)slweight.Value); bool isOnList = false; foreach (var p in lb_LisOfPlayers.Items) { var pilkarz = p as Footballer; if (pilkarz.isInList(currentFootballer)) { isOnList = true; break; } } if (isOnList == false) { lb_LisOfPlayers.Items.Remove(lb_LisOfPlayers.SelectedItem); lb_LisOfPlayers.Items.Insert(index, currentFootballer); } else { var dialog2 = MessageBox.Show("Już taki piłkarz jest na liście, wprowadź innego!", "Uwaga", MessageBoxButton.OK); } } ResetValues(); } } }