Exemplo n.º 1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //open connection
            //set reference to database

            //String query = "select * UserAccounts where Username= '******' and Password='******'";

            //  OleDbConnection conn = Connections.connect();
            //OleDbCommand processQuery = new OleDbCommand(query, conn);//execute the query


            var service = new OnlineTestService();//create object
            int userID;
            var pulledData = service.validUser(txtUsername.Text, txtPassword.Text, out userID);


            if (pulledData.Keys.First() == false)
            {
                lblInvalidCredentials.Visible = true;
            }
            if (pulledData.Keys.First() & pulledData.Values.First() == false)
            {
                Tests tests = new Tests();
                Response.Redirect($"~/Tests.aspx?userID={userID}");//INTERPOLATION
            }
            else if ((pulledData.Keys.First() && pulledData.Values.First() == true))
            {
                AddQuestions addQuestions = new AddQuestions();
                Response.Redirect($"~/AddQuestions.aspx?userID={userID}");
            }
        } //buton click
        protected void btnAddQuestion_Click(object sender, EventArgs e)
        {
            lblError.Visible = false;
            String topic    = txtTopic.Text;
            String question = txtQuestion.Text;
            //1=easy 2==medium 3=hard
            int    difficulty    = Convert.ToInt32(ddlDifficulty.SelectedValue.ToString());
            String questionTypeA = ddlQuestionType.SelectedValue;
            int    questionType  = 0;

            if (Convert.ToInt32(questionTypeA) == 1)
            {
                if (txtTopic.Text.Equals("") || txtQuestion.Text.Equals("") || txtSingleAns.Text.Equals(""))
                {
                    lblError.Visible = true;
                    lblQuestionAddedConfirmation.Visible = false;
                }
            }

            //if (Convert.ToInt32(questionTypeA) == 2) {//2 value = multiple choice selected
            //  questionType = 1;
            //}

            if (Convert.ToInt32(questionTypeA) == 2)
            {
                if (txtTopic.Text.Equals("") || txtQuestion.Text.Equals("") || txtA.Text.Equals("") || txtB.Text.Equals("") || txtC.Text.Equals("") || txtD.Text.Equals(""))
                {
                    lblError.Visible = true;
                    lblQuestionAddedConfirmation.Visible = false;
                }
            }

            if (lblError.Visible == false)
            {
                //1=6-10yrs 2=11-13yrs 3=14-16yrs
                int level = Convert.ToInt32(ddlQuizLevel.SelectedValue.ToString());


                String correctSingleAns = txtSingleAns.Text;
                //collect 4 answers for mutiple choice type questions
                String ansA = txtA.Text;
                String ansB = txtB.Text;
                String ansC = txtC.Text;
                String ansD = txtD.Text;
                //identify the correct answers **there can be more than one correct answer for the mutiple choice
                //correct answer is the one that admin chooses to tick
                bool isA_right = chkA.Checked;
                bool isB_right = chkB.Checked;
                bool isC_right = chkC.Checked;
                bool isD_right = chkD.Checked;

                var service = new OnlineTestService(); //create object
                                                       //insert the new question created
                service.insertQuestions(topic, question, difficulty, level, questionType, correctSingleAns, ansA, ansB, ansC, ansD, isA_right, isB_right, isC_right, isD_right);
                //insert the corresponding answers
                lblQuestionAddedConfirmation.Visible = true;
                lblError.Visible = false;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            OnlineTestService service              = new OnlineTestService();
            List <String>     goldMedallistsList   = service.getGoldMeds();
            List <String>     silverMedallistsList = service.getSilverMeds();

            foreach (String name in goldMedallistsList)
            {
                txtGold.Text += name + Environment.NewLine;
            }
            foreach (String name in silverMedallistsList)
            {
                txtSilver.Text += name + Environment.NewLine;
            }
        }