Esempio n. 1
0
        private void btnChooseGame_Click(object sender, EventArgs e)
        {
            ChooseGame Game = new ChooseGame();

            this.Hide();
            Game.Show();
        }
Esempio n. 2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text == "")
            {
                MessageBox.Show("Please enter Username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserName.Focus();
                return;
            }
            if (txtPassword.Text == "")
            {
                MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPassword.Focus();
                return;
            }



            try
            {
                SqlConnection myConnection = default(SqlConnection);
                myConnection = new SqlConnection(cs);

                SqlCommand myCommand = default(SqlCommand);

                myCommand = new SqlCommand("SELECT Username,Password FROM TblLogin WHERE Username = @Username AND Password = @Password", myConnection);

                SqlParameter uName     = new SqlParameter("@Username", SqlDbType.VarChar);
                SqlParameter uPassword = new SqlParameter("@Password", SqlDbType.VarChar);

                uName.Value     = txtUserName.Text;
                uPassword.Value = txtPassword.Text;

                myCommand.Parameters.Add(uName);
                myCommand.Parameters.Add(uPassword);


                myCommand.Connection.Open();

                SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

                if (myReader.Read() == true)
                {
                    ChooseGame Game = new ChooseGame();
                    this.Hide();
                    Game.Show();
                }


                else
                {
                    MessageBox.Show("Login Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    txtUserName.Clear();
                    txtPassword.Clear();
                    txtUserName.Focus();
                }

                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //checks to see if text boxes are filled
            if (txtUserName.Text == "")
            {
                MessageBox.Show("Please enter Username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserName.Focus();
                return;
            }
            if (txtPassword.Text == "")
            {
                MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPassword.Focus();
                return;
            }


            try
            {
                //creates new sql connection
                SqlConnection myConnection = new SqlConnection(cs);


                //sql command to get sql user data from table
                SqlCommand myCommand = new SqlCommand("SELECT Username,Password FROM TblLogin WHERE Username = @Username AND Password = @Password", myConnection);

                //sql data from table is set up as uName, and uPassword
                SqlParameter uName     = new SqlParameter("@Username", SqlDbType.VarChar);
                SqlParameter uPassword = new SqlParameter("@Password", SqlDbType.VarChar);

                //grab user info from text box
                uName.Value     = txtUserName.Text.Trim();
                uPassword.Value = txtPassword.Text.Trim();

                //takes sql command adds sql parameters and then adds to DB
                myCommand.Parameters.Add(uName);
                myCommand.Parameters.Add(uPassword);

                //open sql connection
                myCommand.Connection.Open();

                //set up new sql data reader
                SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

                //if the user is in the DB they will be redirected to the choose game page
                if (myReader.Read() == true)
                {
                    ChooseGame Game = new ChooseGame();
                    this.Hide();
                    Game.Show();
                }

                //login failed error pops up for any entries are worng
                else
                {
                    MessageBox.Show("Login Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    txtUserName.Clear();
                    txtPassword.Clear();
                    txtUserName.Focus();
                }
                //closed sql connection
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }