示例#1
0
        /// <summary>
        /// Creates an exam given the selected configuration, also locks said exam.
        /// </summary>
        /// <returns>NO_ERROR if created successfully.</returns>
        public int Create()
        {
            string sql = "INSERT INTO UserExam(IdUser, IdExam, Status) VALUES(" + IdUser + ", " + IdExam + ", " + UserExamStatus.PENDING + ")";

            Common.BDExecute(sql);
            IdUserExam = Common.GetBDNum("lastId", "SELECT MAX(IdUserExam) AS lastId FROM UserExam");
            Exam exam = new Exam(IdExam);

            foreach (ExamContent examContent in exam.examContents)
            {
                if (examContent.IdTheme != 0)
                {
                    ExamTheme  theme       = new ExamTheme(examContent.IdTheme);
                    List <int> selectedIds = Common.GetIdList("IdQuestion", "SELECT TOP " + examContent.QuestionCount + " IdQuestion FROM ExamQuestion WHERE IdTheme IN (" + theme.GetChildrenThemes(examContent.IdTheme.ToString()) + ") ORDER BY newid();");
                    foreach (int selectedId in selectedIds)
                    {
                        UserExamQuestion examQuestion = new UserExamQuestion(IdUserExam, selectedId);
                        examQuestion.Create();
                    }
                }
                else if (examContent.IdQuestion != 0)
                {
                    UserExamQuestion examQuestion = new UserExamQuestion(IdUserExam, examContent.IdQuestion);
                    examQuestion.QuestionSequence = examContent.QuestionSequence;
                    examQuestion.Create();
                }
            }
            return(ErrorCode.NO_ERROR);
        }
示例#2
0
        /// <summary>
        /// Constructor private auxiliar function.
        /// </summary>
        /// <param name="id">IdUserExam</param>
        private void ExamSetup(int id)
        {
            List <Dictionary <string, string> > userExam = Common.GetRS("SELECT * FROM UserExam WHERE IdUserExam = " + id);

            foreach (Dictionary <string, string> record in userExam)
            {
                IdUserExam = id;
                IdUser     = Convert.ToInt32(record["IdUser"]);
                IdExam     = Convert.ToInt32(record["IdExam"]);
                Status     = Convert.ToInt32(record["Status"]);
                try
                {
                    DateComplete = Convert.ToDateTime(record["DateComplete"]);
                }
                catch (FormatException ex) { }
                Score = Convert.ToDouble(record["Score"]);
            }
            List <Dictionary <string, string> > userExamQuestions = Common.GetRS("SELECT * FROM UserExamQuestion WHERE IdUserExam = " + id);

            foreach (Dictionary <string, string> record in userExamQuestions)
            {
                UserExamQuestion userExamQuestion = new UserExamQuestion(id, Convert.ToInt32(record["IdQuestion"]));
                userExamQuestion.QuestionSequence = Convert.ToInt32(record["QuestionSequence"]);
                questions.Add(userExamQuestion);
            }
        }
示例#3
0
 /// <summary>
 /// Creates an exam given the selected configuration, also locks said exam.
 /// </summary>
 /// <returns>NO_ERROR if created successfully.</returns>
 public int Create()
 {
     string sql = "INSERT INTO UserExam(IdUser, IdExam, Status) VALUES(" + IdUser + ", " + IdExam + ", " + UserExamStatus.PENDING + ")";
     Common.BDExecute(sql);
     IdUserExam = Common.GetBDNum("lastId", "SELECT MAX(IdUserExam) AS lastId FROM UserExam");
     Exam exam = new Exam(IdExam);
     foreach (ExamContent examContent in exam.examContents)
     {
         if (examContent.IdTheme != 0)
         {
             ExamTheme theme = new ExamTheme(examContent.IdTheme);
             List<int> selectedIds = Common.GetIdList("IdQuestion", "SELECT TOP " + examContent.QuestionCount + " IdQuestion FROM ExamQuestion WHERE IdTheme IN (" + theme.GetChildrenThemes(examContent.IdTheme.ToString()) + ") ORDER BY newid();");
             foreach (int selectedId in selectedIds)
             {
                 UserExamQuestion examQuestion = new UserExamQuestion(IdUserExam, selectedId);
                 examQuestion.Create();
             }
         }
         else if(examContent.IdQuestion != 0)
         {
             UserExamQuestion examQuestion = new UserExamQuestion(IdUserExam, examContent.IdQuestion);
             examQuestion.QuestionSequence = examContent.QuestionSequence;
             examQuestion.Create();
         }
     }
     return ErrorCode.NO_ERROR;
 }
示例#4
0
 /// <summary>
 /// Constructor private auxiliar function.
 /// </summary>
 /// <param name="id">IdUserExam</param>
 private void ExamSetup(int id)
 {
     List<Dictionary<string, string>> userExam = Common.GetRS("SELECT * FROM UserExam WHERE IdUserExam = " + id);
     foreach (Dictionary<string, string> record in userExam)
     {
         IdUserExam = id;
         IdUser = Convert.ToInt32(record["IdUser"]);
         IdExam = Convert.ToInt32(record["IdExam"]);
         Status = Convert.ToInt32(record["Status"]);
         try
         {
             DateComplete = Convert.ToDateTime(record["DateComplete"]);
         }
         catch (FormatException ex) { }
         Score = Convert.ToDouble(record["Score"]);
     }
     List<Dictionary<string, string>> userExamQuestions = Common.GetRS("SELECT * FROM UserExamQuestion WHERE IdUserExam = " + id);
     foreach (Dictionary<string, string> record in userExamQuestions)
     {
         UserExamQuestion userExamQuestion = new UserExamQuestion(id, Convert.ToInt32(record["IdQuestion"]));
         userExamQuestion.QuestionSequence = Convert.ToInt32(record["QuestionSequence"]);
         questions.Add(userExamQuestion);
     }
 }