private void take_exam(object sender, RoutedEventArgs e)
 {
     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")
         {
             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");
     }
 }
Exemple #2
0
        private void submit_exam(object sender, RoutedEventArgs e)
        {
            try
            {
                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>();
                    foreach (var item in questions)
                    {
                        question qus = new question
                        {
                            QustCode = item.IDeas,
                            type     = item.Type
                        };
                        DBquestions.Add(qus);
                        Exams_questions.Add(new exam_qusetion
                        {
                            Question_Id = item.IDeas,
                            Grade       = item.Degree
                        });
                    }

                    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
                    });
                    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("Please Enter a valid Information");
            }
        }
Exemple #3
0
        private void addcourse_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                corseadd newcourse = new corseadd();

                newcourse.Name = coursename.Text.ToString();

                newcourse.MaxDegree = 100;

                newcourse.instructorName = instructorcourse.SelectedItem.ToString();

                instructor newins = context3.instructors.Where(em => em.FirstName == newcourse.instructorName).FirstOrDefault();

                rel_instructor_cource newcourseinstructor = new rel_instructor_cource();


                course newCourseAdd = new course();
                newCourseAdd.Name        = coursename.Text.ToString();
                newCourseAdd.MinDegree   = 50;
                newCourseAdd.MaxDegree   = 100;
                newCourseAdd.Description = coursename.Text.ToString() + "is important";
                context3.courses.Add(newCourseAdd);
                context3.SaveChanges();
                newcourseinstructor.CourseId = newCourseAdd.CourseId;
                newcourseinstructor.InsId    = newins.InsId;
                newcourseinstructor.Year     = DateTime.Now;

                context3.rel_instructor_cource.Add(newcourseinstructor);
                context3.SaveChanges();
                coursess.Items.Add(newcourse);
            }
            catch (Exception f)
            {
                MessageBox.Show("Invalid Inputs");
            }
        }