Esempio n. 1
0
        //----------------------------//
        //// New Player Tab Methods ////
        //----------------------------//

        //Save+close button
        private void saveBtn_Click_1(object sender, EventArgs e)
        {
            // validate ssn input and assign converted int to variable
            int ssn;
            if (!int.TryParse(ssnBox.Text, out ssn) || ssnBox.Text.Length != 9)
            {
                // alert user if invalid entry by length or unable to parse
                MessageBox.Show("Please Enter a valid SSN!", "Invalid Input!");
                return;
            }
            // verify the path is set
            VerifyPathSet();
            // update existing player list
            util.RefreshPlayerList();
            // instantiate new player
            Player newPlayer = new Player(firstNameBox.Text, lastNameBox.Text, ssn);

            // check if new player is a duplicate,
            // and if so, alert user and remove
            // existing player (done in DataUtility class)
            if (util.IsDupcliatePlayer(newPlayer))
            {
                MessageBox.Show("That player already exists\n" +
                                "The existing player has been updated",
                                "Duplicate player message");
            }

            // add new player to players list
            util.Players.Add(newPlayer);
            // save players list
            util.SavePlayers();

            //Confirm that the data was saved, and close the window
            MessageBox.Show("The player has been saved, thank you!",
                "Save Confirmation");

            //move to winnings tab on save
            TabPage t = tabControl1.TabPages[1];
            tabControl1.SelectedTab = t; //go to tab

            // clear text boxes
            firstNameBox.Clear();
            lastNameBox.Clear();
            ssnBox.Clear();

        }
Esempio n. 2
0
        //--------------------------//
        //// Winnings Tab Methods ////
        //--------------------------//

        // search button searches players by ssn
        private void btnSearch_Click(object sender, EventArgs e)
        {
            // verify paths set
            VerifyPathSet();
            // update player list
            util.RefreshPlayerList();

            // convert and assign search input to variable
            int ssn;
            if (Int32.TryParse(ssnSearchForTextBox.Text, out ssn))
                {
                // find players that match this ssn (returns -1 if not found)
                int i = util.SearchPlayersBySSN(ssn);

                // if not found, then alert user
                if (i == -1)
                {
                    MessageBox.Show("No players with the SSN exist", "Player not found");
                }
                // otherwise, update form information
                else
                {
                    selectPlayer.Text = util.Players[i].FirstName + " " + util.Players[i].LastName;
                    currentPlayer = util.Players[i];
                    playerPos = i;
                    totalWinnings.Text = currentPlayer.Winnings.CalculateTotalWinnings().ToString("C");
                }

                // clear search text box
                ssnSearchForTextBox.Clear();
            }
            else
            {
                MessageBox.Show("Enter a valid SSN before searching", "SSN not valid Error");
            }
        }
Esempio n. 3
0
        // method allows user to double-click user in list box to load details in winnings tab
        private void displayResultsListBox_DoubleClick(object sender, EventArgs e)
        {
            // split selected list box item at space delimeter
            string[] fields = displayResultsListBox.SelectedItem.ToString().Split(' ');

            // find players that match this ssn (returns -1 if not found)
            int i = util.SearchPlayersBySSN(Convert.ToInt32(fields[2]));

            // if not found, then alert user
            if (i == -1)
            {
                MessageBox.Show("No players with the SSN exist", "Player not found");
            }
            // otherwise, update form information
            else
            {
                selectPlayer.Text = util.Players[i].FirstName + " " + util.Players[i].LastName;
                currentPlayer = util.Players[i];
                playerPos = i;
                totalWinnings.Text = currentPlayer.Winnings.CalculateTotalWinnings().ToString("C");
            }

            // change selected tab
            tabControl1.SelectedIndex = 1;
        }
Esempio n. 4
0
        // returns true if duplicate player is found
        // and removes that player from the players list
        public bool IsDupcliatePlayer(Player newPlayer)
        {
            foreach (Player existingPlayer in Players)
            {
                if (existingPlayer.Equals(newPlayer))
                {
                    Players.Remove(existingPlayer);
                    return true;
                }
            }

            return false;
        }