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 LoadPlayer(Footballer fballer)
 {
     textBoxWEP_Name.Text    = fballer.Name;
     textBoxWEP_Surname.Text = fballer.Surname;
     sliderAge.Value         = fballer.Age;
     sliderWeight.Value      = fballer.Weight;
     buttonEdit.IsEnabled    = true;
     buttonDelete.IsEnabled  = true;
     textBoxWEP_Name.SetFocus();
 }
        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 Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            int n = listBoxFootballer.Items.Count;

            Footballer[] fballer = null;
            if (n > 0)
            {
                fballer = new Footballer[n];
                int index = 0;
                foreach (var o in listBoxFootballer.Items)
                {
                    fballer[index++] = o as Footballer;
                }
                Archiving.SaveFootballerToFile(ArchivingFile, fballer);
            }
        }
示例#5
0
 public static Footballer[] ReadFootballerFromFile(string file)
 {
     Footballer[] fballers = null;
     if (File.Exists(file))
     {
         var sfballers = File.ReadAllLines(file);
         var n         = sfballers.Length;
         if (n > 0)
         {
             fballers = new Footballer[n];
             for (int i = 0; i < n; i++)
             {
                 fballers[i] = Footballer.CreateFromString(sfballers[i]);
             }
             return(fballers);
         }
     }
     return(fballers);
 }
示例#6
0
 public bool isTheSame(Footballer pilkarz)
 {
     if (pilkarz.Surname != Surname)
     {
         return(false);
     }
     if (pilkarz.Name != Name)
     {
         return(false);
     }
     if (pilkarz.Age != Age)
     {
         return(false);
     }
     if (pilkarz.Weight != Weight)
     {
         return(false);
     }
     return(true);
 }
        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");
                }
            }
        }