public bool UpdateDBPre(QuestionStruct question, string answer)
 {
     if (TestAnswerValidity(question.Category, answer) == false)
     {
         return(false);
     }
     else
     {
         UserAnswerList[currentQuestion] = answer;
         return(true);
     }
 }
        public void LoadContent(string paperID)
        {
            SqlConnection conn    = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString);
            string        cmdStr  = "select * from Questions where PaperID = @PaperID";
            SqlCommand    cmd     = new SqlCommand(cmdStr, conn);
            SqlParameter  IDparam = new SqlParameter("@PaperID", SqlDbType.NChar, 5);

            IDparam.Value = PaperID;
            cmd.Parameters.Add(IDparam);
            conn.Open();
            SqlDataReader mcpReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            GridView1.DataSource = mcpReader;
            GridView1.DataBind();
            //GridView1.Visible = false;
            conn.Open();
            mcpReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (mcpReader.Read())
            {
                QuestionStruct qs = new QuestionStruct();
                qs.Answer   = mcpReader["Answer"].ToString();
                qs.Category = mcpReader["Category"].ToString();
                qs.PaperID  = mcpReader["PaperID"].ToString();
                qs.QNo      = mcpReader["QNo"].ToString();
                qs.Question = mcpReader["Question"].ToString();
                QuestionList.Add(qs);
                if (!hasLoaded)
                {
                    resultCount++;
                }
            }
            LoadQuestion();
            TestButtonEnable();
            if (UserAnswerList.Count == 0)
            {
                for (int i = 0; i < resultCount; i++)
                {
                    UserAnswerList.Add(string.Empty);
                }
            }
        }
        public void LoadQuestion()
        {
            QuestionStruct qs = QuestionList[currentQuestion];

            QuestionTextBox.Text = string.Format("{0}. {1}", qs.QNo, qs.Question);
            if (qs.Category == "S    ")
            {
                HintLabel.Text = "There are EXACTLY one choice is correct. Please input the corresponding letter.";
            }
            else if (qs.Category == "M    ")
            {
                HintLabel.Text = "There are one or more correct choices. Please input the corresponding letter seperated with commas. (e.g. \"A,C\")";
            }
            else if (qs.Category == "R    ")
            {
                HintLabel.Text = "\"Y\" indicates a right statement, \"N\" indicates a wrong statement.";
            }
            else
            {
                HintLabel.Text = string.Empty;
            }
        }
Exemple #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            QuestionStruct qstmp = new QuestionStruct();

            if (corList.Count < Test_Final.resultCount)
            {
                for (int i = 0; i < Test_Final.resultCount; i++)
                {
                    corList.Add(qstmp);
                }
            }
            if (mineList.Count < Test_Final.resultCount)
            {
                for (int i = 0; i < Test_Final.resultCount; i++)
                {
                    mineList.Add(qstmp);
                }
            }
            for (int i = 0; i < Test_Final.resultCount; i++)
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ExamSystemConnectionString"].ConnectionString);

                string       cmdstrCor    = "select * from Questions where PaperID = @PaperID and QNo = @QNo";
                SqlCommand   cmdCor       = new SqlCommand(cmdstrCor, conn);
                SqlParameter paperIDparam = new SqlParameter("@PaperID", SqlDbType.NChar, 5);
                SqlParameter qnoparam     = new SqlParameter("@QNo", SqlDbType.Int);
                paperIDparam.Value = paperID;
                qnoparam.Value     = i + 1;
                cmdCor.Parameters.Add(paperIDparam);
                cmdCor.Parameters.Add(qnoparam);

                string       cmdstrMine = "select * from UserAnswer where PaperID = @PaperID and QNo = @QNo and UserID = @UserID order by TestTime desc";
                SqlCommand   cmdMine    = new SqlCommand(cmdstrMine, conn);
                SqlParameter idParam    = new SqlParameter("@PaperID", SqlDbType.NChar, 5);
                SqlParameter noParam    = new SqlParameter("@QNo", SqlDbType.Int);
                SqlParameter userParam  = new SqlParameter("@UserID", SqlDbType.NChar, 5);
                idParam.Value   = paperID;
                noParam.Value   = i + 1;
                userParam.Value = userID;
                cmdMine.Parameters.Add(idParam);
                cmdMine.Parameters.Add(noParam);
                cmdMine.Parameters.Add(userParam);
                QuestionStruct qs = new QuestionStruct();

                conn.Open();
                SqlDataReader corReader = cmdCor.ExecuteReader();
                corReader.Read();
                qs.Answer   = corReader["Answer"].ToString();
                qs.Category = corReader["Category"].ToString();
                qs.PaperID  = corReader["PaperID"].ToString();
                qs.QNo      = corReader["QNo"].ToString();
                qs.Question = corReader["Question"].ToString();
                corList[i]  = qs;
                conn.Close();

                conn.Open();
                SqlDataReader mineReader = cmdMine.ExecuteReader();
                mineReader.Read();
                qs.Answer   = mineReader["Answer"].ToString();
                mineList[i] = qs;
                conn.Close();
            }
            LabelQNo.Text        = string.Format("Question {0}", currentQNo + 1);
            TextBoxQuestion.Text = string.Format("{0}. {1}", currentQNo + 1, corList[currentQNo].Question);
            TextBoxCorrect.Text  = string.Format("This is the correct answer:\n{0}", corList[currentQNo].Answer);
            TextBoxMine.Text     = string.Format("This is your answer:\n{0}", mineList[currentQNo].Answer);
        }