Ejemplo n.º 1
0
 private void btnCreatePlayer_Click(object sender, RoutedEventArgs e) {
     try {
         if (!string.IsNullOrWhiteSpace(txtFname.Text) &&
             !string.IsNullOrWhiteSpace(txtLname.Text) &&
             !string.IsNullOrWhiteSpace(txtPrice.Text) &&
             cbTeam.SelectedItem != null) {
             Player player = new Player(txtFname.Text, txtLname.Text, int.Parse(txtPrice.Text), cbTeam.SelectedValue.ToString());
             bool exists = players.Any(Player => Player.Fullname == player.Fullname);
             if (exists) {
                 player = null;
                 tbStatus.Text = "Player already exists";
             } else {
                 players.Add(player);         
                 ApplyChanges();                      
                 tbStatus.Text = "New player created";
                 Clear();
             }
         } else {
             tbStatus.Text = "Fill all fields";
         }
     }
     catch (Exception ex) {
         tbStatus.Text = ex.ToString();
     }
 }
Ejemplo n.º 2
0
 private void btnCreatePlayer_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (txtFirstName.Text != "" && txtLastName.Text != "" && txtTransferCost.Text != "" && TeamSelector.Text != "")
         {
                     // tarkistetaan onko samanniminen pelaaja jo olemassa 
             if(!(JAMK.IT.IIO11300.Player.checkForSimilarities(playerList, txtFirstName.Text, txtLastName.Text)))
             {
                 int cost = Int32.Parse(txtTransferCost.Text);
                 Player newPlayer = new Player(txtFirstName.Text, txtLastName.Text, TeamSelector.Text, cost, faceSelector.Text);
                 playerList.Add(newPlayer);
                 ApplyChanges();
                 statusBarText.Text = "Player added to list!";
             }
             else
             {
                 statusBarText.Text = "Player already exists!";
             }  
         }
         else
         {
             throw new ArgumentNullException();
         }
     }
     catch (Exception ex)
     {
         statusBarText.Text = ex.Message;
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 3
0
        public static List<Player> loadDataFromTxt(string myFile)
        {
            try
            {
                if(System.IO.File.Exists(myFile))
                {
                    using (StreamReader sr = File.OpenText(myFile))
                    {
                        Player player;
                        List<Player> loadedData = new List<Player>();
                        string row = "";
                        while ((row = sr.ReadLine()) != null)
                        {
                            
                            if ((row.Length > 3) && row.Contains(","))
                            {
                                string[] split = row.Split(',');
                                // luodaan tekstinpätkistä olio
                                player = new Player(split[0], split[1], split[2], Convert.ToInt32(split[3]), split[4]);
                                loadedData.Add(player);
                            }
                        }
                        // palautetaan listan mittausolioita
                        return loadedData;
                    }

                }
                else
                {
                    List<Player> loadedData = new List<Player>();
                    return loadedData;

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }