Exemplo n.º 1
0
        private void ViewExamBtn_Click(object sender, EventArgs e)
        {
            ComboboxItem item    = (ComboboxItem)examsCombobox.SelectedItem;
            int          exam_id = Int32.Parse(item.Value.ToString());


            examquestions = ExamQuestionDAL.GetExamQuestions(exam_id);


            for (int i = 0; i < examquestions.Count; i++)
            {
                string name = QuestionDAL.GetQuestionTypeName(examquestions[i].Question.Type);

                dataGridView1.Rows.Add(name, examquestions[i].Question.QuestionText);
            }
        }
        public static ExamQuestionCollection GetExamQuestions(int exam_id)
        {
            DataTable              dt           = DBLayer.ExecuteQuery(string.Format("select * from Question_Exam where FK_ExamID = {0}", exam_id));
            List <int>             questions_id = new List <int>();
            ExamQuestionCollection questions    = new ExamQuestionCollection();

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    questions_id.Add(Convert.ToInt32(dt.Rows[i]["FK_QuestionID"].ToString()));
                }
            }

            for (int i = 0; i < questions_id.Count; i++)
            {
                DataTable dt2 = DBLayer.ExecuteQuery(string.Format("select * from Question where id = {0}", questions_id[i]));

                Question q = new Question();
                q.Id           = Convert.ToInt32(dt2.Rows[0]["id"].ToString());
                q.QuestionText = dt2.Rows[0]["question_text"].ToString();

                q.Course    = new Course();
                q.Course.Id = Convert.ToInt32(dt2.Rows[0]["Course_ID"].ToString());

                q.Modelanswer    = new QuestionAnswer();
                q.Modelanswer.ID = Convert.ToInt32(dt2.Rows[0]["question_modelAns"].ToString());

                q.Answers = new QuestionAnswerCollection();
                q.Type    = Convert.ToInt32(dt2.Rows[0]["question_type"].ToString());
                DataTable dt3 = DBLayer.ExecuteQuery(string.Format("select * from Quest_ans where Quest_ID = {0}", q.Id));

                for (int j = 0; j < dt3.Rows.Count; j++)
                {
                    QuestionAnswer qa = new QuestionAnswer();
                    qa.ID     = Convert.ToInt32(dt3.Rows[j]["id"].ToString());
                    qa.Answer = dt3.Rows[j]["text"].ToString();
                    q.Answers.Add(qa);
                }
                ExamQuestion qe = new ExamQuestion();
                qe.Question = q;
                qe.Exam     = MyExam.Exam;
                questions.Add(qe);
            }
            return(questions);
        }
Exemplo n.º 3
0
        private void Student_TakingExam_Load(object sender, EventArgs e)
        {
            //Data Source=BASMA-HP\SQLEXPRESS;Initial Catalog=ExaminationSystems;Integrated Security=True
            //Data Source=.;Initial Catalog=ExaminationSystems;Integrated Security=True
            //DBLayer.connection = @"Data Source=.;Initial Catalog=ExaminationSystems;Integrated Security=True";
            DBLayer.connection = @"Data Source=FATMA\FATMAGAMAL;Initial Catalog=ExaminationSystems;Integrated Security=True";

            SqlConnection sqlConnection = new SqlConnection(DBLayer.connection);

            //course_id should come as a parameter to the form in the first place
            //getExamQuestions(sqlConnection, course_id, student_id);
            //MessageBox.Show(MyExam.Exam.ExamSessions[0].Id.ToString() + "   " + MyExam.Exam.Id.ToString());

            examQuestions = ExamQuestionDAL.GetExamQuestions(MyExam.Exam.Id);

            if (count > 0)
            {
                showQuestion(count);
            }
        }