示例#1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try {
                int QID = getQuestionsOfExam.ElementAt(i).QustCode;
                if ((i + 2) == QCounter)
                {
                    next.Content = "Submit";
                }
                double Degree = (from d in contect3.exam_qusetion
                                 where d.Question_Id == QID && d.Exam_Id == selectedExamId
                                 select d.Grade).FirstOrDefault();
                //to submit the current answer of question
                if (CurrentQuestion == "text")
                {
                    string Answer      = studentTextAswer.Text;
                    string ModelAnswer = (from m in contect3.textquestions
                                          where m.QustCode == QID
                                          select m.ModelAnswer).FirstOrDefault();
                    rel_student_qusetion_exam submitQues = new rel_student_qusetion_exam();
                    submitQues.QustCode    = getQuestionsOfExam.ElementAt(i).QustCode;
                    submitQues.ExamCode    = selectedExamId;
                    submitQues.StudentId   = userID;
                    submitQues.Answer      = Answer;
                    submitQues.ModelAnswer = ModelAnswer;
                    if (ModelAnswer == Answer)
                    {
                        submitQues.DegreeMark = Degree;
                    }
                    else
                    {
                        submitQues.DegreeMark = 0;
                    }
                    contect3.rel_student_qusetion_exam.Add(submitQues);
                }
                else if (CurrentQuestion == "mcq")
                {
                    bool          right       = false;
                    List <string> Answer      = new List <string>();
                    List <string> ModelAnswer = (from m in contect3.multichoices
                                                 join v in contect3.msqmultivalues
                                                 on m.MCQCode equals v.MCQCode
                                                 where m.QustCode == QID
                                                 select v.ModelAnswer).ToList();
                    if (A.IsChecked == true)
                    {
                        Answer.Add(A.Content.ToString());
                    }
                    if (B.IsChecked == true)
                    {
                        Answer.Add(B.Content.ToString());
                    }
                    if (C.IsChecked == true)
                    {
                        Answer.Add(C.Content.ToString());
                    }
                    if (D.IsChecked == true)
                    {
                        Answer.Add(D.Content.ToString());
                    }
                    if (ModelAnswer.Count == Answer.Count)
                    {
                        int j = 0;
                        if (ModelAnswer.Contains(Answer.ElementAt(j)))
                        {
                            j++;
                            right = true;
                        }
                        else
                        {
                            right = false;
                        }
                    }
                    rel_student_qusetion_exam submitQues = new rel_student_qusetion_exam();
                    submitQues.QustCode  = getQuestionsOfExam.ElementAt(i).QustCode;
                    submitQues.ExamCode  = selectedExamId;
                    submitQues.StudentId = userID;
                    foreach (var item in Answer)
                    {
                        submitQues.Answer += item + ",";
                    }
                    foreach (var item in ModelAnswer)
                    {
                        submitQues.ModelAnswer += item + ",";
                    }
                    if (right == true)
                    {
                        submitQues.DegreeMark = Degree;
                    }
                    if (right == false)
                    {
                        submitQues.DegreeMark = 0;
                    }
                    contect3.rel_student_qusetion_exam.Add(submitQues);
                }
                else if (CurrentQuestion == "tf")
                {
                    string Answer;
                    string ModelAnswer = (from m in contect3.qtruefalses
                                          where m.QustCode == QID
                                          select m.ModelAnswer).FirstOrDefault();
                    if (T.IsChecked == true)
                    {
                        Answer = "true";
                    }
                    else
                    {
                        Answer = "false";
                    }
                    rel_student_qusetion_exam submitQues = new rel_student_qusetion_exam();
                    submitQues.QustCode    = getQuestionsOfExam.ElementAt(i).QustCode;
                    submitQues.ExamCode    = selectedExamId;
                    submitQues.StudentId   = userID;
                    submitQues.Answer      = Answer;
                    submitQues.ModelAnswer = ModelAnswer;
                    if (ModelAnswer == Answer)
                    {
                        submitQues.DegreeMark = Degree;
                    }
                    else
                    {
                        submitQues.DegreeMark = 0;
                    }
                    contect3.rel_student_qusetion_exam.Add(submitQues);
                }
                contect3.SaveChanges();



                i++;
                if (i + 1 > QCounter)
                {
                    CurrentQuestion = "theEnd";
                    Canvas.SetZIndex(ExamSubmit, ++z);
                    getStuentExamListView();
                }
                else
                {
                    try
                    {
                        //to get the next question
                        question questionIndex   = getQuestionsOfExam.ElementAt(i);
                        string   QuestionContent = "";
                        if (questionIndex.type == "text")
                        {
                            var Question = (from qs in contect3.textquestions
                                            where qs.QustCode == questionIndex.QustCode
                                            select qs).FirstOrDefault();
                            QuestionContent = Question.question;
                            CurrentQuestion = "text";
                            Canvas.SetZIndex(textAnswer, ++z);
                        }
                        if (questionIndex.type == "MSQ")
                        {
                            QuestionContent = (from qs in contect3.multichoices
                                               where qs.QustCode == questionIndex.QustCode
                                               select qs.question).FirstOrDefault();
                            List <string> choise = (from choisse in contect3.msqmultivalues
                                                    where choisse.MCQCode == (from qs in contect3.multichoices
                                                                              where qs.QustCode == questionIndex.QustCode
                                                                              select qs.MCQCode).FirstOrDefault()
                                                    select choisse.ModelAnswer).ToList();
                            A.Content       = choise.ElementAt(0);
                            B.Content       = choise.ElementAt(1);
                            C.Content       = choise.ElementAt(2);
                            D.Content       = choise.ElementAt(3);
                            CurrentQuestion = "mcq";
                            Canvas.SetZIndex(msqAnswer, ++z);
                        }
                        if (questionIndex.type == "true&false")
                        {
                            QuestionContent = (from qs in contect3.qtruefalses
                                               where qs.QustCode == questionIndex.QustCode
                                               select qs.question).FirstOrDefault();
                            CurrentQuestion = "tf";
                            Canvas.SetZIndex(tfAnswer, ++z);
                        }
                        question.Content = QuestionContent;
                    }
                    catch (Exception h)
                    {
                    }
                }
            }
            catch (Exception f)
            {
                MessageBox.Show("invalid inputs");
            }
        }
示例#2
0
        private void submit_exam(object sender, RoutedEventArgs e)
        {
            try
            {
                CourseNName = IstuctorCourse.SelectedItem.ToString();
                DateTime dateofExam = ExamDate.DisplayDate;
                int      munites    = 0;
                string[] number     = ExamTime.Text.Split(':', ',');
                if (number.Length == 1)
                {
                    munites = 0;
                }
                else if (number.Length > 1)
                {
                    munites = int.Parse(number[1]);
                }
                else
                {
                    MessageBox.Show("please enter the time of exam");
                }
                var      hour = int.Parse(number[0]) + int.Parse(duration.Text.ToString());
                DateTime examDateTimeBegin = new DateTime(dateofExam.Year, dateofExam.Month, dateofExam.Day, int.Parse(number[0]), munites, 0);
                //TimeSpan examDateTimeBegin = new TimeSpan(examDateTime.Day, int.Parse(number[0]), munites, 0);
                DateTime examDateTimeEnd = new DateTime(examDateTimeBegin.Year, examDateTimeBegin.Month, examDateTimeBegin.Day, hour, munites, 0);

                if (int.Parse(sumOfQuestionGrades.Text) == ExamDegree && examDateTimeBegin != null &&
                    SelectedQuestionsss.Count > 0 && int.Parse(duration.Text.ToString()) > 0)
                {
                    //the questions that selected to the exam
                    List <Quesition> questions = new List <Quesition>();
                    questions.AddRange(QuestionWithGrades.Where(r => SelectedQuestionsss.Contains(r.IDeas)));

                    //this list to match from question in class i made to put to the class
                    //the entity framework has made (the elements is added in the foreach t7t)
                    List <exam_qusetion> Exams_questions = new List <exam_qusetion>();

                    //the course of the question
                    //List<course_question> course_qus = new List<course_question>();
                    //course_qus.Add(new course_question { Course_ID = 1, Qust_codr = 4 });

                    //getting the course ID of the selected course
                    var courseId =
                        (from courseID in context2.courses
                         where courseID.Name == CourseNName
                         select courseID.CourseId).FirstOrDefault();

                    List <question>      DBquestions = new List <question>();
                    List <exam_qusetion> DBquesRel   = new List <exam_qusetion>();

                    foreach (var item in questions)
                    {
                        question qus = new question
                        {
                            QustCode = item.IDeas,
                            type     = item.Type
                        };
                        //DBquestions.Add(qus);
                        exam_qusetion rel = new exam_qusetion
                        {
                            Grade    = item.Degree,
                            question = qus
                        };
                        //DBquesRel.Add(rel);
                        Exams_questions.Add(rel);
                    }

                    List <course_exam> courseOfExam = new List <course_exam>();

                    var exams = new exam()
                    {
                        Name          = CourseNName,
                        Type          = comboBoxofexamType.SelectedItem.ToString(), //must be exam of corrective
                        Date          = examDateTimeBegin,
                        EndTime       = examDateTimeEnd,
                        MaxDegree     = (short)ExamDegree,
                        course_exam   = courseOfExam,
                        exam_qusetion = Exams_questions,
                    };
                    context2.exams.Add(exams);

                    context2.course_exam.Add(new course_exam {
                        Course_Id = courseId, exam = exams
                    });

                    context2.SaveChanges();


                    MessageBox.Show("Exam Has been Added");

                    /* ExamDegree // this is the degree of the exam
                     * IstuctorCourse // this is the course of the exam
                     * comboBoxofexamType // this combo box is the
                     * Exams_questions // this is the list of quetions
                     * examDateTimeBegin // this is the begin time for exam
                     * examDateTimeEnd //this is the end time for the exam */
                }
                else
                {
                    totalQgrade.Visibility = Visibility.Visible;
                }
            }
            catch (Exception eee)
            {
                MessageBox.Show(eee.ToString());
            }
        }
示例#3
0
 private void take_exam(object sender, RoutedEventArgs e)
 {
     try {
         if (selectedExamId > 0)
         {
             rel_exam_student ess = (from es in contect3.rel_exam_student
                                     where es.ExamCode == selectedExamId && es.StuId == userID
                                     select es).First();
             ess.Taken = true;
             contect3.SaveChanges();
             getQuestionsOfExam = (from Q in contect3.questions
                                   join E in contect3.exam_qusetion
                                   on Q.QustCode equals E.Question_Id
                                   where E.Exam_Id == selectedExamId
                                   select Q).ToList();
             QCounter = getQuestionsOfExam.Count();
             // getting the first question
             question questionIndex   = getQuestionsOfExam.ElementAt(i);
             string   QuestionContent = "";
             if (questionIndex.type == "text")
             {
                 MessageBox.Show(questionIndex.QustCode.ToString());
                 var Question = (from qs in contect3.textquestions
                                 where qs.QustCode == questionIndex.QustCode
                                 select qs).FirstOrDefault();
                 QuestionContent = Question.question;
                 CurrentQuestion = "text";
                 Canvas.SetZIndex(textAnswer, ++z);
             }
             if (questionIndex.type == "MSQ")
             {
                 QuestionContent = (from qs in contect3.multichoices
                                    where qs.QustCode == questionIndex.QustCode
                                    select qs.question).FirstOrDefault();
                 List <string> choise = (from choisse in contect3.msqmultivalues
                                         where choisse.MCQCode == (from qs in contect3.multichoices
                                                                   where qs.QustCode == questionIndex.QustCode
                                                                   select qs.MCQCode).FirstOrDefault()
                                         select choisse.ModelAnswer).ToList();
                 A.Content       = choise.ElementAt(0);
                 B.Content       = choise.ElementAt(1);
                 C.Content       = choise.ElementAt(2);
                 D.Content       = choise.ElementAt(3);
                 CurrentQuestion = "mcq";
                 Canvas.SetZIndex(msqAnswer, ++z);
             }
             if (questionIndex.type == "true&false")
             {
                 QuestionContent = (from qs in contect3.qtruefalses
                                    where qs.QustCode == questionIndex.QustCode
                                    select qs.question).FirstOrDefault();
                 CurrentQuestion = "tf";
                 Canvas.SetZIndex(tfAnswer, ++z);
             }
             question.Content = QuestionContent;
             Canvas.SetZIndex(stuQuestion, ++z);
         }
         else
         {
             MessageBox.Show("Get Out");
         }
     }
     catch (Exception f)
     {
         MessageBox.Show("invalid inputs");
     }
 }
示例#4
0
        private void msq_save_Click(object sender, RoutedEventArgs e)
        {
            var course_id =
                (from Idcourse in context2.courses
                 where Idcourse.Name == CourseNName
                 select Idcourse.CourseId).FirstOrDefault();
            // MessageBox.Show(course_id.ToString());

            var q = new question()
            {
                type   = "MCQ",
                Degree = double.Parse(qDegree1.Text),
            };

            q = context2.questions.Add(q);
            //context2.SaveChanges();

            var courses = new course_question()
            {
                Qust_codr = q.QustCode,
                Course_ID = course_id
            };

            courses = context2.course_question.Add(courses);
            //context2.SaveChanges();

            var ques = new multichoice()
            {
                question1 = q,
                question  = qText1.Text,
            };

            ques = context2.multichoices.Add(ques);
            //context2.SaveChanges();
            bool A, B, C, D;

            if (checkboxA.IsChecked == true)
            {
                A = true;
            }
            else
            {
                A = false;
            }
            if (checkboxB.IsChecked == true)
            {
                B = true;
            }
            else
            {
                B = false;
            }
            if (checkboxC.IsChecked == true)
            {
                C = true;
            }
            else
            {
                C = false;
            }
            if (checkboxD.IsChecked == true)
            {
                D = true;
            }
            else
            {
                D = false;
            }
            var multi1 = new msqmultivalue()
            {
                MCQCode     = ques.MCQCode,
                ModelAnswer = textA.Text,
                correct     = A
            };
            var multi2 = new msqmultivalue()
            {
                MCQCode     = ques.MCQCode,
                ModelAnswer = textB.Text,
                correct     = B
            };
            var multi3 = new msqmultivalue()
            {
                MCQCode     = ques.MCQCode,
                ModelAnswer = textC.Text,
                correct     = C
            };
            var multi4 = new msqmultivalue()
            {
                MCQCode     = ques.MCQCode,
                ModelAnswer = textD.Text,
                correct     = D
            };

            if (multi1.correct == true || multi2.correct == true || multi3.correct == true || multi4.correct == true)
            {
                context2.msqmultivalues.Add(multi1);
                context2.msqmultivalues.Add(multi2);
                context2.msqmultivalues.Add(multi3);
                context2.msqmultivalues.Add(multi4);
                context2.SaveChanges();
                questionss.Items.Add(ques);
                MessageBox.Show("Done");
            }
        }