Esempio n. 1
0
        private void btnMenu_Click(object sender, EventArgs e)
        {
            //Switch to menu form and carry user object over
            this.Hide();
            var MenuWindow = new VirusGame();

            MenuWindow.currentUserMenu = currentUserHighscores;
            MenuWindow.Closed         += (s, args) => this.Close();
            MenuWindow.Show();
        }
        private void btnMenu_Click(object sender, EventArgs e)
        {
            //Switch to menu form
            this.Hide();
            var MenuWindow = new VirusGame();

            MenuWindow.currentUserMenu = currentUserAdminPanel;
            MenuWindow.Closed         += (s, args) => this.Close();
            MenuWindow.Show();
        }
 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();
     }
 }
Esempio n. 4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                //Establish database connection
                db_connection();

                string EncryptedPassword = Eramake.eCryptography.Encrypt(txtInputPassword.Text);

                //Check to see if Username and Password combination works
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SELECT COUNT (*) FROM dbo.GAMEUSERS WHERE Username = @Username COLLATE SQL_Latin1_General_CP1_CS_AS AND Password = @Pass COLLATE SQL_Latin1_General_CP1_CS_AS";
                cmd.Parameters.AddWithValue("@Username", txtInputUsername.Text);
                cmd.Parameters.AddWithValue("@Pass", EncryptedPassword);
                cmd.Connection = connect;

                int result = (int)cmd.ExecuteScalar();

                //Close connection
                connect.Close();

                //If not found then
                if (result == 0)
                {
                    //Tell user there is invalid credentials
                    MessageBox.Show("Invalid Crententials Entered");
                }
                else
                {
                    //establish connection
                    db_connection();

                    //Get users admin value
                    cmd             = new SqlCommand();
                    cmd.CommandText = "SELECT isAdmin FROM dbo.GAMEUSERS WHERE Username = @Username";
                    cmd.Parameters.AddWithValue("@Username", txtInputUsername.Text);
                    cmd.Connection = connect;
                    result         = (int)cmd.ExecuteScalar();

                    //Close connection
                    connect.Close();

                    //Create user object
                    User currentUserLogin = new User(txtInputUsername.Text, result);

                    //Open menu form and carry user object over
                    this.Hide();
                    var MenuWindow = new VirusGame();
                    MenuWindow.currentUserMenu = currentUserLogin;
                    MenuWindow.Closed         += (s, args) => this.Close();
                    MenuWindow.Show();
                }
            }
            catch
            {
                //Inform user there was an issue connecting to the database
                SqlCommand cmd = new SqlCommand("EXECUTE InvalidStoredProcedure", connect);
                MessageBox.Show("Issue connecting to DataBase", "Connection Issue",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }