private void buttonEdytuj_Click(object sender, RoutedEventArgs e) { if (czyPuste(textBoxImie) & czyPuste(textBoxNazwisko)) { var bFootballer = new Footballer(textBoxImie.Text.Trim(), textBoxNazwisko.Text.Trim(), (int)sliderWiek.Value, (int)sliderWaga.Value); var czyJuzJest = false; foreach (var i in listBox1.Items) { var footballer = i as Footballer; if (footballer.czyIstnieje(bFootballer)) { czyJuzJest = true; break; } } if (!czyJuzJest) { var dialogResult = MessageBox.Show($"Czy na pewno chcesz zmienić dane {Environment.NewLine} {listBox1.SelectedItem}?", "Edycja", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { var nowy = listBox1.SelectedItem as Footballer; nowy.Edit(bFootballer); listBox1.Items.Refresh(); } Clear(); listBox1.SelectedIndex = -1; } else { MessageBox.Show($"{bFootballer.ToString()} już jest na liście."); } } }
private void Zaladuj(Footballer fb) { textBoxImie.Text = fb.Imie; textBoxNazwisko.Text = fb.Nazwisko; sliderWaga.Value = fb.Waga; sliderWiek.Value = fb.Wiek; }
public Footballer Edit(Footballer fb) { this.Imie = fb.Imie; this.Nazwisko = fb.Nazwisko; this.Wiek = fb.Wiek; this.Waga = fb.Waga; return(this); }
private void buttonDodaj_Click(object sender, RoutedEventArgs e) { if (czyPuste(textBoxImie) & czyPuste(textBoxNazwisko)) { var bFootballer = new Footballer(textBoxImie.Text.Trim(), textBoxNazwisko.Text.Trim(), (int)sliderWiek.Value, (int)sliderWaga.Value); listBox1.Items.Add(bFootballer); Clear(); } }
private void buttonUsun_Click(object sender, RoutedEventArgs e) { var bFootballer = new Footballer(textBoxImie.Text.Trim(), textBoxNazwisko.Text.Trim(), (int)sliderWiek.Value, (int)sliderWaga.Value); var dialogResult = MessageBox.Show($"Czy na pewno chcesz usunąć dane {Environment.NewLine} {listBox1.SelectedItem}?", "Usuń", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { listBox1.Items.RemoveAt(listBox1.SelectedIndex); } Clear(); listBox1.SelectedIndex = -1; }
private void Zamkniecie(object sender, System.ComponentModel.CancelEventArgs e) { int n = listBox1.Items.Count; Footballer[] fb = null; if (n > 0) { fb = new Footballer[n]; int i = 0; foreach (var p in listBox1.Items) { fb[i++] = p as Footballer; } Zapis.DoPliku(plik, fb); } }
public static Footballer[] ZPliku(string plik) { Footballer[] f = null; if (File.Exists(plik)) { var foot = File.ReadAllLines(plik); var dl = foot.Length; if (dl > 0) { f = new Footballer[dl]; for (int i = 0; i < dl; i++) { f[i] = Footballer.CreateFromString(foot[i]); } return(f); } } return(f); }
public bool isTheSame(Footballer footballer) { if (footballer.Surname != Surname) { return(false); } if (footballer.FirstName != FirstName) { return(false); } if (footballer.Age != Age) { return(false); } if (footballer.Weight != Weight) { return(false); } return(true); }
public bool czyIstnieje(Footballer footballer) { if (footballer.Imie != Imie) { return(false); } if (footballer.Nazwisko != Nazwisko) { return(false); } if (footballer.Wiek != Wiek) { return(false); } if (footballer.Waga != Waga) { return(false); } return(true); }