Exemplo n.º 1
0
 //Function called when yes is selected, begins the process of 
 private void button1_Click(object sender, EventArgs e)
 {
     //Admin must choose a genre from a drop down menu as genre is not provided by Walmart, will deny if genre hasn't been selected
     string genre = genreBox.Text;
     if(genre == "Choose Here")
     {
         MessageBox.Show("Please select a genre from the drop-down menu");
     }
     else
     {
         //genre is selected, begin the DB insertion process
         DBconnect insert = new DBconnect();
         insert.DBConnect();
         bool isOpen = insert.OpenConnection();
         if (isOpen == false)
         {
             //Ensure DB coneection is still available
             MessageBox.Show("Failed to establish database connection");
         }
         else
         {
             //See DBconnect.cs for implementation, pass all variables in the correct order
             insert.populateDB(AdminAddGame.gameName, genre, AdminAddGame.console, AdminAddGame.description, AdminAddGame.UPC, AdminAddGame.imageLink);
         }
         //always close
         this.Close();
     }  
 }
Exemplo n.º 2
0
        //Submit button, initiates login when clicked
        private void button1_Click(object sender, EventArgs e)
        {
            //Assigns username and password variables to their repsective text fields
            userName = UserNameField.Text;
            string password = PasswordField.Text;
            UserNameField.Focus();
            //Creates DBconnect object that will handle DB work
            DBconnect data = new DBconnect();
            data.DBConnect();
            bool isOpen = data.OpenConnection();
            if(isOpen == false)
            {
                MessageBox.Show("Failed to establish database connection");
            }
            else
            {
                //See DBconnect.cs for implementation, if function returns false, user credentials were denied
                if (data.Validate(userName, password) == false)
                {
                    MessageBox.Show("Invalid user name or password, please try again.");
                }
                else
                {
                    //Credentials are legitimate, must check if it was a user or admin 
                    if(data.isAdmin(userName) == true)
                    {
                        //user was admin, open the admin form
                        //MessageBox.Show("Welcome Admin");
                        AdminWindow ad = new AdminWindow();
                        //create reference to admin form window in order to recal this form after it is hidden
                        ad.RefToLogin = this;
                        //hide this form and display admin window
                        this.Visible = false;
                        ad.Show();
                       
                    }
                    else
                    {
                        //User was plain user, open the user form
                        //MessageBox.Show("Welcome User");
                        UserWindow us = new UserWindow();
                        //Same process as the admin
                        us.RefToLogin = this;
                        this.Visible = false;
                        us.Show();

                    }
                    //Clear all text fields and rehighlight the username so when the form is called again 
                    //everything is blank and the username is ready for another
                    UserNameField.Text = string.Empty;
                    PasswordField.Text = string.Empty;
                }
            }
        }