예제 #1
0
 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();
         }
     }
 }
예제 #2
0
 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();
     }
 }
예제 #3
0
 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ść");
     }
 }
예제 #4
0
파일: Footballer.cs 프로젝트: padoski/.NET
 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);
 }
예제 #5
0
 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();
         }
     }
 }