//menu update work same as update button private void mnuUpdate_Click(object sender, RoutedEventArgs e) { if (lstHockeyPlayers.SelectedItem == null) { MessageBox.Show("Please select the player!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { int game, assist, goal; if (Int32.TryParse(txtHPGames.Text, out game) && Int32.TryParse(txtHPGames.Text, out assist) && Int32.TryParse(txtHPGames.Text, out goal)) { var result = MessageBox.Show("You sure you want to update the players? ", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { int index = lstHockeyPlayers.SelectedIndex; HockeyPlayer hp = pla[index]; hp.PlayerName = txtHPName.Text; hp.TeamName = txtHPTeam.Text; hp.GamesPlayed = int.Parse(txtHPGames.Text); hp.Assists = int.Parse(txtHPAssists.Text); hp.Goals = int.Parse(txtHPGoals.Text); } } else { MessageBox.Show("Invalid Input! Please try again!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Reload(); }
//menu insert work same as insert button private void mnuInsert_Click(object sender, RoutedEventArgs e) { if (txtHPName.Text.Length == 0 || txtHPTeam.Text.Length == 0 || txtHPGames.Text.Length == 0 || txtHPAssists.Text.Length == 0 || txtHPGoals.Text.Length == 0) { MessageBox.Show("Please select the player!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { int game, assist, goal; if (Int32.TryParse(txtHPGames.Text, out game) && Int32.TryParse(txtHPAssists.Text, out assist) && Int32.TryParse(txtHPGoals.Text, out goal)) { HockeyPlayer p1 = new HockeyPlayer(PlayerType.HockeyPlayer, pla.Count, txtHPName.Text, txtHPTeam.Text, int.Parse(txtHPGames.Text), int.Parse(txtHPAssists.Text), int.Parse(txtHPGoals.Text)); pla.Add(p1); } else { MessageBox.Show("Invalid Input! Please try again!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Reload(); }