private void btnHighscores_Click(object sender, EventArgs e)
        {
            try
            {
                //Establish database connection
                db_connection();

                //Switch to highscores form and carry user object over
                this.Hide();
                var HighscoresWindow = new Highscores();
                HighscoresWindow.currentUserHighscores = currentUserMenu;
                HighscoresWindow.Closed += (s, args) => this.Close();
                HighscoresWindow.Show();
            }
            catch
            {
                //Inform user there was a issue connecting to the database
                SqlCommand cmd = new SqlCommand("EXECUTE InvalidStoredProcedure", connect);
                MessageBox.Show("Issue Connecting to DataBase");
            }
        }
 public void EndGame()
 {
     try
     {
         db_connection();
         //Switch to high score form
         this.Hide();
         var HighscoresWindow = new Highscores();
         HighscoresWindow.currentUserHighscores = currentUserGame;
         HighscoresWindow.Closed += (s, args) => this.Close();
         HighscoresWindow.Show();
     }
     catch (SqlException)
     {
         MessageBox.Show("Error Retrieving Scores from DataBase - Apologies");
         //Switch to menu form and carry user object over
         this.Hide();
         var MenuWindow = new VirusGame();
         MenuWindow.currentUserMenu = currentUserGame;
         MenuWindow.Closed         += (s, args) => this.Close();
         MenuWindow.Show();
     }
 }
        public void EndGameWin()
        {
            try
            {
                //Create Scores objects
                for (int j = 0; j < Scores.Length; j++)
                {
                    Scores[j] = new Scores();
                }

                int i = 0;

                db_connection();

                //Get all of the selected question attributes
                SqlCommand cmd = new SqlCommand("SELECT * FROM HIGHSCORES ORDER BY Score ASC;", connect);
                //Read values
                SqlDataReader sdr = cmd.ExecuteReader();

                //Whilst reading values, make local varable values to those from columns in selected row
                while (sdr.Read())
                {
                    Scores[i].ScoreID  = Int32.Parse(sdr[0].ToString());
                    Scores[i].Username = sdr[1].ToString();
                    Scores[i].Score    = Int32.Parse(sdr[2].ToString());
                    i++;
                }

                //close connection
                connect.Close();

                //If current user score is greater than current lowest score in highscores
                if (turnCounter < Scores[9].Score)
                {
                    try
                    {
                        //Establish connection
                        db_connection();

                        //Insert(Update) username and turncounter/score into highscore table
                        cmd = new SqlCommand("With NewScores as ( select username, score from HIGHSCORES where ScoreID = @ScoreID ) update NewScores set username= @Username, score=@Score;", connect);
                        cmd.Parameters.AddWithValue("@Username", currentUserGame.Username);
                        cmd.Parameters.AddWithValue("@Score", turnCounter);
                        cmd.Parameters.AddWithValue("@ScoreID", Scores[9].ScoreID);
                        cmd.ExecuteNonQuery();

                        //Close connection
                        connect.Close();
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Error Writing new Score to DataBase - Apologies");
                    }
                }
                //If not then tell them they didnt make it :(
                else
                {
                    MessageBox.Show("You didn't make the Highscores. Better luck next time!");
                }
                //Switch to high score form
                this.Hide();
                var HighscoresWindow = new Highscores();
                HighscoresWindow.currentUserHighscores = currentUserGame;
                HighscoresWindow.Closed += (s, args) => this.Close();
                HighscoresWindow.Show();
            }
            catch (SqlException)
            {
                MessageBox.Show("Error Retrieving Scores from DataBase - Apologies");
                //Switch to high score form
                this.Hide();
                var HighscoresWindow = new Highscores();
                HighscoresWindow.currentUserHighscores = currentUserGame;
                HighscoresWindow.Closed += (s, args) => this.Close();
                HighscoresWindow.Show();
            }
        }