/**
         * Checks the users referenced login information against the DB
         * to see if they are allowed to login. Returns true if they are
         * allowed, and returns false if they are not.
         */
        private bool checkLogin()
        {
            // Setup our return data
            bool returnVal = false;

            // Get our info from the form.
            string userName = tb_userName.Text;
            string password = tb_password.Text;

            // Set up a structure to save our response
            List <NameValueCollection> queryResult;

            // Execute the Query, checking for username and password.
            queryResult = dbManager.query("SELECT * FROM user WHERE userName = '******' AND password = '******'");

            //queryResult = dbManager.query("SELECT * FROM user WHERE userName = @user_name AND password = @pass_word");

            if (queryResult.Count >= 1)
            {
                returnVal = true;
                stateManager.setUserName(userName, password);
            }
            else
            {
                returnVal = false;
            }

            return(returnVal);
        }
        private void generateOldQuestionFromID(string questionID)
        {
            string queryString           = "SELECT * from question WHERE id = '" + questionID + "';";
            NameValueCollection question = dbManager.query(queryString)[0];

            string    correctAnswer = question["correctAnswer"];
            ArrayList answers       = new ArrayList();

            answers.Add(question["answer1"]);
            answers.Add(question["answer2"]);
            answers.Add(question["answer3"]);
            answers.Add(question["answer4"]);
            answers.Add(question["answer5"]);
            answers.Add(question["answer6"]);
            answers.Add(question["answer7"]);
            answers.Add(question["answer8"]);
            answers.Add(question["answer9"]);
            answers.Add(question["answer10"]);
            answers.Add(question["answer11"]);
            answers.Add(question["answer12"]);
            answers.Add(question["answer13"]);
            answers.Add(question["answer14"]);
            answers.Add(question["answer15"]);

            string image = question["question"];

            int correctAnswerPosition = answers.IndexOf(correctAnswer);

            // Setup the gui with the correct questions and answers.
            populateQuestionImage(image);
            populateAnswers(answers, correctAnswerPosition);

            int totalAttempts = dbManager.getQuestionAttempts(question["id"]);
            int totalCorrect  = dbManager.getQuestionCorrect(question["id"]);
            int totalWrong    = dbManager.getQuestionWrong(question["id"]);
            int numAttempt    = dbManager.getQuestionAttemptsByUser(question["id"], stateManager.getUserID());
            int numCorrect    = dbManager.getQuestionCorrectByUser(question["id"], stateManager.getUserID());
            int numWrong      = dbManager.getQuestionWrongByUser(question["id"], stateManager.getUserID());

            //increment display labels
            currentUserTotal.Text   = numAttempt.ToString();
            currentUserCorrect.Text = numCorrect.ToString();
            currentUserWrong.Text   = numWrong.ToString();

            allUserCorrect.Text = totalCorrect.ToString();
            allUserTotal.Text   = totalAttempts.ToString();
            allUserWrong.Text   = totalWrong.ToString();

            gb_stats.Text = "Question Statistics for #id: " + question["id"];


            stateManager.setQuestionID(int.Parse(question["id"]));
            dbManager.incrementQuestionDisplay(stateManager.getUserID(), stateManager.getQuestionID());
        }
Beispiel #3
0
        /**
         * Checks the users referenced login information against the DB
         * to see if they are allowed to login. Returns true if they are
         * allowed, and returns false if they are not.
         */
        private bool checkLogin()
        {
            // Setup our return data
            bool returnVal = false;

            // Get our info from the form.
            string userName = tb_userName.Text;
            string password = tb_password.Text;

            // Set up a structure to save our response
            List <NameValueCollection> queryResult;

            // Execute the Query, checking for username and password.
            queryResult = dbManager.query("SELECT * FROM user WHERE userName = '******' AND password = '******'");

            //queryResult = dbManager.query("SELECT * FROM user WHERE userName = @user_name AND password = @pass_word");

            if (queryResult.Count >= 1)
            {
                returnVal = true;
                stateManager.setUserName(userName, password);
                stateManager.setFirstName(queryResult[0]["firstName"]);
                stateManager.setLastName(queryResult[0]["lastName"]);
                stateManager.setPassword(password);
                string str_isAdmin = queryResult[0]["isAdmin"];

                bool isAdmin;

                if (str_isAdmin == "")
                {
                    isAdmin = false;
                }
                else
                {
                    isAdmin = bool.Parse(queryResult[0]["isAdmin"]);
                }


                stateManager.setIsAdmin(isAdmin);
            }
            else
            {
                returnVal = false;
            }

            return(returnVal);
        }