Ejemplo n.º 1
0
        public ActionResult Exam(int id)
        {
            if (getSid() == -1)
            {
                return Redirect("/Index/Index");
            }
            var model = new ExamModel();
            var exam = model.getExamById(id);
            if (exam == null || exam.ready == 0)
                return Redirect("/Index/Index");
            Session["exam_info"] = exam;
            var question = model.genExam(id);
            Session["exam"] = question;
            
            if (Session["end_time"] == null) 
            {
                var endTime = System.DateTime.Now.AddMinutes(exam.time);
                Session["end_time"] = endTime;
                Session["strat_time"] = DateTime.Now;
            }

            Session["remain_time"] =  (int) ( ( (DateTime)Session["end_time"] ).Subtract(DateTime.Now).TotalSeconds );
            ViewBag.reamin_time = Session["remain_time"];
            
            ViewBag.questions = question;
            ViewBag.exam = exam;
            return View();
        }
Ejemplo n.º 2
0
        public void TestModifyStatus()//注,当更新的值一样时不会执行更新操作,所以此测试只能通过一次
        {
            ExamModel model = new ExamModel();
            int i = model.modifyStatus(2, 1);
            Console.WriteLine(i);
            Assert.IsTrue(i == 1);

        }
Ejemplo n.º 3
0
        public void TestSetExamName2() //注,当更新的值一样时不会执行更新操作,所以此测试只能通过一次
        {
            ExamModel model = new ExamModel();
            int i = model.setExamName(1, "第一单元测试",2,2,2,2,2,2,90);
            //Console.WriteLine(i);
            Assert.IsTrue(i == 1);

        }
Ejemplo n.º 4
0
 public ActionResult Index()
 {
     if (loginStatus() == false)
     {
         return Redirect("Login");
     }
     ExamModel model = new ExamModel();
     List<ExamEntity> list = model.getAllExam();
     ViewBag.examList = list;
     return View();
 }
Ejemplo n.º 5
0
 public ActionResult Exam()
 {
     int sid = getSid();
     if (sid == -1)
     {
         return Redirect("/Index/Index");
     }
     ExamModel model = new ExamModel();
     ViewBag.data = model.getAvailableExam();
     assignTitle();
     return View();
 }
Ejemplo n.º 6
0
        public void TestGetAllExam()
        {
            ExamModel model = new ExamModel();
            List<ExamEntity> list = model.getAllExam();
            Assert.IsNotNull(list);
            
            foreach (ExamEntity exam in list)
            {
                Console.WriteLine(string.Format("id:{0},name:{1}",exam.id,exam.name));
            }


        }
Ejemplo n.º 7
0
        public ActionResult Index(int id)
        {
            if (getSid() == -1)
            {
                return Redirect("/Index/Index");
            }
            var model = new  ExamModel();
            var exam = model.getExamById(id);
            if(exam == null || exam.ready == 0)
                return Redirect("/Index/Index");

            ViewBag.exam = exam;
            return View();
        }
Ejemplo n.º 8
0
        public ActionResult Index()
        {
            int sid = getSid();
            if (sid == -1)
            {
                return Redirect("/Index/Index");
            }
            AnnouncementModel announceModel = new AnnouncementModel();
            ExamModel examModel = new ExamModel();
            FileModel fileModel = new FileModel();

            ViewBag.announcement = announceModel.getAnnouncements(0, 3);
            ViewBag.exam = examModel.getAvailableExam().Take(3);
            ViewBag.file = fileModel.getFiles(0, 3);
            assignTitle();
            return View();
        }
Ejemplo n.º 9
0
        public void TestParse()
        {
            ExamModel model = new ExamModel();
            ExamEntity exam = model.praseFromDoc("doc/chapter1.docx");
            Assert.IsNotNull(exam);
            Assert.AreEqual(20, exam.time);
            Assert.AreEqual(2, exam.tNumber);
            Assert.AreEqual(2, exam.tScore);
            Assert.AreEqual(1, exam.sNumber);
            Assert.AreEqual(3, exam.sScore);
            Assert.AreEqual(0, exam.mNumber);
            Assert.AreEqual(4, exam.mScore);

            Assert.AreEqual(3, exam.tf.Count);
            Assert.AreEqual(1, exam.sc.Count);
            Assert.AreEqual(0, exam.mc.Count);

            QuestionEntity tf0 = exam.tf[0] as QuestionEntity;
            QuestionEntity tf1 = exam.tf[1] as QuestionEntity;
            QuestionEntity tf2 = exam.tf[2] as QuestionEntity;

            
            Assert.AreEqual(tf0.ans, "F");
            Assert.AreEqual(tf1.ans, "T");
            Assert.AreEqual(tf2.ans, "T");
            System.Console.WriteLine (tf0.statement);
            System.Console.WriteLine (tf1.statement);
            System.Console.WriteLine (tf2.statement);

            Assert.IsNull(tf0.image);
            Assert.IsNotNull(tf1.image);
            Assert.IsNull(tf2.image);
            

            


            QuestionEntity sc0 = exam.sc[0] as QuestionEntity;
            Assert.AreEqual(sc0.ans, "A");
            System.Console.WriteLine(sc0.statement);
            foreach(String choice in sc0.choices)
            {
                System.Console.WriteLine(choice);
            }

        }
Ejemplo n.º 10
0
        public ActionResult Result()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            ViewBag.resultList = new List<ResultEntity>();
            try
            {
                int examid = int.Parse(Request["exam"]);
                ResultModel model = new ResultModel();
                ExamModel examModel = new ExamModel();
                ViewBag.resultList = model.getExamResultByExamId(examid);
                ViewBag.examInfo = examModel.getExamById(examid);
                
            }
            catch
            {

            }
            return View();
        }
Ejemplo n.º 11
0
        public ActionResult AddExam()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            Dictionary<string,String> ret = new Dictionary<string,string>();
            HttpPostedFileBase file =  Request.Files.Get("doc");
            if (file != null)
            {
                if (checkFileExt(file.FileName))
                {
                    ExamModel examModel= new ExamModel();
                    QuestionModel questionModel = new QuestionModel();
                    var docName = "~/upload/tmp.docx";
                    var examname = "";
                    file.SaveAs(Server.MapPath(docName));
                    try
                    {
                        ExamEntity examEntity = examModel.praseFromDoc(Server.MapPath(docName));
                        if (file.FileName.LastIndexOf('\\') != -1)
                        {
                            examname = file.FileName.Substring(file.FileName.LastIndexOf('\\') + 1, file.FileName.Length - 1 - file.FileName.LastIndexOf('\\'));
                        }
                        else
                        {
                            examname = file.FileName;
                        }
                        int examId = examModel.addExam(examEntity.time, examEntity.sNumber, examEntity.mNumber, examEntity.tNumber, examEntity.sScore, examEntity.mScore, examEntity.tScore, 0, examname.Substring(0, examname.Length - 5));
                        int type = -1;
                        int count = 1;
                        foreach (QuestionEntity q in examEntity.sc)
                        {
                            
                            switch (q.type)
                            {
                                case "SC":
                                    type = 0;
                                    break;
                                case "MC":
                                    type = 1;
                                    break;
                                case "TF":
                                    type = 2;
                                    break;
                            }
                             var imageDir = "";
                             var imageName = "";
                             if (q.image != null)
                             {
                                 imageName = string.Format("/{0}.jpg", count);
                                 imageDir = string.Format("~/upload/{0}/sc", examId, count);
                                 if(!Directory.Exists(Server.MapPath(imageDir)))
                                 {
                                     Directory.CreateDirectory(Server.MapPath(imageDir));
                                 }
                                
                                 q.image.Save(Server.MapPath(imageDir+imageName));
                                 count = count + 1;
                             }
                           
                            var choiceJson = new JavaScriptSerializer().Serialize(q.choices);
                            questionModel.addQuesiton(type, q.ans, choiceJson, imageDir+imageName, q.statement, examId);
                        }
                        count = 1;
                        foreach (QuestionEntity q in examEntity.mc)
                        {

                            switch (q.type)
                            {
                                case "SC":
                                    type = 0;
                                    break;
                                case "MC":
                                    type = 1;
                                    break;
                                case "TF":
                                    type = 2;
                                    break;
                            }
                             var imageDir = "";
                             var imageName = "";
                             if (q.image != null)
                             {
                                 imageName = string.Format("/{0}.jpg",count);
                                 imageDir = string.Format("~/upload/{0}/mc", examId, count);
                                 if(!Directory.Exists(Server.MapPath(imageDir)))
                                 {
                                     Directory.CreateDirectory(Server.MapPath(imageDir));
                                 }
                                
                                 q.image.Save(Server.MapPath(imageDir+imageName));
                                 count = count + 1;
                             }
                            
                            var choiceJson = new JavaScriptSerializer().Serialize(q.choices);
                            questionModel.addQuesiton(type, q.ans, choiceJson, imageDir+imageName, q.statement, examId);
                        }
                        count = 1;
                        foreach (QuestionEntity q in examEntity.tf)
                        {

                            switch (q.type)
                            {
                                case "SC":
                                    type = 0;
                                    break;
                                case "MC":
                                    type = 1;
                                    break;
                                case "TF":
                                    type = 2;
                                    break;
                            }
                             var imageDir = "";
                             var imageName = "";
                             if (q.image != null)
                             {
                                 imageName = string.Format("/{0}.jpg", count);
                                 imageDir = string.Format("~/upload/{0}/tf", examId, count);
                                 if(!Directory.Exists(Server.MapPath(imageDir)))
                                 {
                                     Directory.CreateDirectory(Server.MapPath(imageDir));
                                 }
                                
                                 q.image.Save(Server.MapPath(imageDir+imageName));
                                 count = count + 1;
                             }
                            
                            var choiceJson = new JavaScriptSerializer().Serialize(q.choices);
                            questionModel.addQuesiton(type, q.ans, choiceJson, imageDir+imageName, q.statement, examId);
                        }
                    

                    }
                    catch(Exception e)
                    {
                        System.IO.File.Delete(Server.MapPath(docName));
                        ret.Add("status", "failed");
                        ret.Add("error", "parse doc error");
                        return Json(ret);
                    }
                    System.IO.File.Delete(Server.MapPath(docName));
                    ret.Add("status", "success");
                    ret.Add("filename", examname);
                    return Json(ret);
                }
                else
                {
                    
                    ret.Add("status", "failed");
                    ret.Add("error", "file type not allowed");
                    return Json(ret);
                }
            }
            else
            {
              
                ret.Add("status", "failed");
                ret.Add("error", "no files");
                return Json(ret);
            }
           
        }
Ejemplo n.º 12
0
 public ActionResult DeleteExam()
 {
     if (loginStatus() == false)
     {
         return Redirect("Login");
     }
     Dictionary<string,string> response = new Dictionary<string,string>();
     ExamModel examModel = new ExamModel();
     QuestionModel questionModel = new QuestionModel();
     int id;
     try
     {
         id = int.Parse(Request["id"]);
         if (Directory.Exists(Server.MapPath(string.Format("~/upload/{0}", id))))
         {
             Directory.Delete(Server.MapPath(string.Format("~/upload/{0}", id)),true);
         }
         int questionCol = questionModel.deleteQuestionByExamId(id);
         int examCol = examModel.deleteExam(id);
         if (questionCol > 0 && examCol > 0)
         {
             response.Add("status", "success");
         }
         else
         {
             response.Add("status", "failed");
             response.Add("error", "something wrong when delete the record from database!");
         }
     }
     catch 
     {
         response.Add("status", "failed");
         response.Add("error", "bad id!");
     }
     return Json(response);
 }
Ejemplo n.º 13
0
        public ActionResult setExamName()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            Dictionary<string, string> response = new Dictionary<string, string>();
            ExamModel model = new ExamModel();
            try
            {
                //singleNum=" + singleNum + "&mutilNum=" + mutilNum + "&judgeNum=" + judgeNum + "&singleScore=" + singleScore + "&mutilScore=" + mutilScore + "&judgeScore=" + judgeScore + "&time=" + time,
                int id = int.Parse(Request["id"]);
                string name = Request["name"];
                int sNum = int.Parse(Request["singleNum"]);
                int mNum = int.Parse(Request["mutilNum"]);
                int tNum = int.Parse(Request["judgeNum"]);
                double sScore = double.Parse(Request["singleScore"]);
                double mScore = double.Parse(Request["mutilScore"]);
                double tScore = double.Parse(Request["judgeScore"]);
                int time = int.Parse(Request["time"]);

               // int row = model.setExamName(id, name);
                int row = model.setExamName(id, name, sNum, mNum, tNum, sScore, mScore, tScore, time);
                if (row > 0)
                {
                    response.Add("status", "success");

                }
                else
                {
                    response.Add("status", "failed");
                    response.Add("error", "update error!");
                }
            }
            catch
            {
                response.Add("status", "failed");
                response.Add("error", "bad param!");
            }
            return Json(response);
        }
Ejemplo n.º 14
0
        public ActionResult ModifyExamStatus()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            Dictionary<string, string> response = new Dictionary<string, string>();
            ExamModel examModel = new ExamModel();
            int id, status;
            try
            {
               id = int.Parse(Request["id"]);
                status = int.Parse(Request["status"]);
               int tmp = examModel.modifyStatus(id, status);
                if (tmp > 0)
                {
                   response.Add("status", "success");
 
               }
                else
                {
                    response.Add("status", "failed");
                    response.Add("error", "something wrong!");
                }
            }
            catch
            {
                response.Add("status", "failed");
                response.Add("error", "bad param!");
            }
            return Json(response);
       }