/// <summary>Method: deleteToolStripMenuItem_Click
 /// Delete selected player
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (editPiece != null && editPiece is Player)
     {
         Player p = (Player)editPiece;
         if (p.IsHomeTeam)
         {
             model.homeTeamCount--;
         }
         else
         {
             model.awayTeamCount--;
         }
         model.DeletePiece(p);
         editPiece = null;
     }
 }
Пример #2
0
        /// <summary>Method: btnDelete_Click
        /// Delete the selected piece
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string o             = string.Empty;
            var    checkedButton = Controls.OfType <RadioButton>()
                                   .FirstOrDefault(r => r.Checked);

            if (checkedButton == null)
            {
                MessageBox.Show("Please select the object first");
                return;
            }
            string obj      = checkedButton.Text;
            string selector = txbSelector.Text;

            if (selector.Equals(o) && !obj.Equals("Ball"))
            {
                MessageBox.Show("Please type in the selector.");
                return;
            }
            if (obj.Equals("Player"))
            {
                string selected_side   = string.Empty;
                string selected_number = string.Empty;
                string pattern         = @"^(home|away) (\d+)$";
                foreach (Match match in Regex.Matches(selector, pattern, RegexOptions.IgnoreCase))
                {
                    selected_side   = match.Groups[1].Value;
                    selected_number = match.Groups[2].Value;
                }
                if (selected_side == string.Empty || selected_number == string.Empty)
                {
                    MessageBox.Show("The selector of player should be Home/Away<space>Number.");
                    return;
                }
                Player player = (Player)model.GetAPiece(typeof(Player),
                                                        selected_side.ToLower(), Convert.ToInt32(selected_number));
                if (player == null)
                {
                    MessageBox.Show("Not Found the player.");
                    return;
                }
                model.DeletePiece(player);
            }
            else if (obj.Equals("Ball"))
            {
                Ball ball = (Ball)model.GetAPiece(typeof(Ball), "Ball");
                if (ball == null)
                {
                    MessageBox.Show("Not Found the ball.");
                    return;
                }
                model.DeletePiece(ball);
            }
            else if (obj.Equals("Referee"))
            {
                Referee referee = (Referee)model.GetAPiece(typeof(Referee), selector);
                if (referee == null)
                {
                    MessageBox.Show("Not Found the referee. You can check the selector example above the textbox.");
                    return;
                }
                model.DeletePiece(referee);
            }
            model.UpdateViews();
        }