Пример #1
0
 public ActionResult CreateUser(UserRegModel userReg)
 {
     try
     {
         var user = db.FP_WMS_UserInfo.SingleOrDefault(t => t.username == userReg.username);
         if (user != null)
         {
             return(Json(new { Status = 0, Content = "用户已存在" }));
         }
         FP_WMS_UserInfo new_user = new FP_WMS_UserInfo();
         new_user.roleid       = 3;
         new_user.roles        = "";
         new_user.departid     = 0;
         new_user.departname   = "";
         new_user.departlist   = "";
         new_user.departs      = "";
         new_user.display      = 0;
         new_user.gradeid      = 0;
         new_user.types        = "";
         new_user.username     = userReg.username;
         new_user.password     = FPUtils.MD5(userReg.password);
         new_user.password2    = "";
         new_user.email        = "";
         new_user.isemail      = 0;
         new_user.mobile       = userReg.phonenumber;
         new_user.ismobile     = 0;
         new_user.realname     = userReg.truename;
         new_user.cardtype     = "";
         new_user.idcard       = "";
         new_user.isreal       = 0;
         new_user.usercode     = "";
         new_user.nickname     = "";
         new_user.avatar       = "";
         new_user.sex          = "";
         new_user.exp          = 0;
         new_user.credits      = 0;
         new_user.regip        = CreateExamHelp.GetLocalIP();
         new_user.joindatetime = DateTime.Now;
         new_user.sumlogin     = 0;
         new_user.lastip       = "";
         new_user.lastvisit    = new_user.joindatetime;
         new_user.secques      = "";
         new_user.authstr      = "";
         new_user.authtime     = new_user.joindatetime;
         new_user.authflag     = 1;
         new_user.vipdate      = "";
         new_user.state        = 1;
         new_user.issso        = 0;
         new_user.extend       = "{}";
         db.FP_WMS_UserInfo.Add(new_user);
         db.SaveChanges();
         return(Json(new { Status = 1, Content = "注册成功,请等待管理员审核" }));
     }
     catch (Exception e)
     {
         return(Json(new { Status = 0, Content = "注册失败出现异常" }));
     }
 }
Пример #2
0
 /// <summary>
 /// 试卷提交方法
 /// </summary>
 /// <param name="resultid"></param>
 /// <returns></returns>
 public SubmitPaperModel SubmitPapers(int resultid)
 {
     try
     {
         var examresult      = db.FP_Exam_ExamResult.SingleOrDefault(t => t.id == resultid);
         var examresultopics = db.FP_Exam_ExamResultTopic.Where(t => t.resultid == resultid).ToList();
         int finalscore      = 0;
         int finalwrong_sum  = 0;
         foreach (var examresultopic in examresultopics)
         {
             int score    = 0;
             int wrongsum = 0;
             if (examresultopic.questionlist == "")
             {
                 continue;
             }
             string[] questions = examresultopic.questionlist.Split(',');
             string[] answers   = examresultopic.answerlist.Split('§');
             for (int i = 0; i < questions.Length; i++)
             {
                 int q_id     = int.Parse(questions[i]);
                 var question = db.FP_Exam_ExamQuestion.SingleOrDefault(t => t.id == q_id);
                 if (answers.Length < (i + 1))
                 {
                     examresultopic.correctlist += "0";
                     examresultopic.scorelist   += "0";
                     question.wrongs            += 1;
                     wrongsum++;
                 }
                 else
                 {
                     if (answers[i] == question.answer)
                     {
                         examresultopic.correctlist += "1";
                         examresultopic.scorelist   += examresultopic.perscore;
                         score += (int)examresultopic.perscore.Value;
                     }
                     else
                     {
                         examresultopic.correctlist += "0";
                         examresultopic.scorelist   += "0";
                         question.wrongs            += 1;
                         wrongsum++;
                     }
                 }
                 if (i < (questions.Length - 1))
                 {
                     examresultopic.correctlist += "|";
                     examresultopic.scorelist   += "|";
                 }
                 //题目考试次数加一
                 question.exams += 1;
                 db.SaveChanges();
             }
             examresultopic.score  = score;
             examresultopic.wrongs = wrongsum;
             finalscore           += score;
             finalwrong_sum       += wrongsum;
         }
         examresult.score  = finalscore;
         examresult.score1 = finalscore;
         examresult.wrongs = finalwrong_sum;
         examresult.status = 1;
         db.SaveChanges();
         string backurl = domainPath + "/Announce/Index?content=提交成功,成绩为:" + finalscore + "分&buttonContent=返回首页&backUrl=" + domainPath + "/Exam/Index&type=1";
         return(new SubmitPaperModel()
         {
             Status = 1, score = finalscore, backUrl = backurl
         });
     }
     catch (Exception e)
     {
         return(new SubmitPaperModel()
         {
             Status = 0, score = 0
         });
     }
 }
Пример #3
0
 /// <summary>
 /// 添加题库
 /// </summary>
 /// <param name="questionres"></param>
 public static int AddQuestionRes(QuestionResModel request)
 {
     try
     {
         var             channalInfo = db.FP_WMS_ChannelInfo.SingleOrDefault(t => t.id == request.channalid);
         FP_WMS_SortInfo sortinfo    = new FP_WMS_SortInfo();
         sortinfo.channelid = request.channalid;
         sortinfo.appid     = int.Parse(channalInfo.sortapps);
         sortinfo.display   = request.display;
         sortinfo.parentid  = request.parentid;
         List <int> parents = new List <int>();
         int        cnd     = request.parentid;
         while (cnd != 0)
         {
             parents.Add(cnd);
             cnd = db.FP_WMS_SortInfo.SingleOrDefault(t => t.id == cnd).parentid.Value;
         }
         parents.Add(cnd);
         string parentlist = "";
         for (int i = 0; i < parents.Count(); i++)
         {
             parentlist += parents[parents.Count() - i - 1];
             if (i < (parents.Count() - 1))
             {
                 parentlist += ",";
             }
         }
         sortinfo.parentlist  = parentlist;
         sortinfo.name        = request.name;
         sortinfo.markup      = request.markup;
         sortinfo.pagesize    = request.pagesize;
         sortinfo.description = request.description;
         sortinfo.icon        = "";
         sortinfo.attach_icon = "";
         sortinfo.img         = "";
         sortinfo.attach_img  = FPRandom.CreateCode(20);
         sortinfo.subcounts   = 0;
         sortinfo.types       = "";
         sortinfo.showtype    = request.showtype;
         sortinfo.otherurl    = "";
         sortinfo.posts       = 0;
         db.FP_WMS_SortInfo.Add(sortinfo);
         db.SaveChanges();
         sortinfo.parentlist += "," + sortinfo.id;
         db.SaveChanges();
         foreach (QuestionType qt in Enum.GetValues(typeof(QuestionType)))
         {
             FP_Exam_SortQuestion sortQuestion = new FP_Exam_SortQuestion();
             sortQuestion.channelid    = sortinfo.channelid;
             sortQuestion.sortid       = sortinfo.id;
             sortQuestion.type         = qt.ToString();
             sortQuestion.typeid       = 0;
             sortQuestion.counts       = 0;
             sortQuestion.questionlist = "";
             db.FP_Exam_SortQuestion.Add(sortQuestion);
             db.SaveChanges();
         }
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Пример #4
0
        /// <summary>
        /// 创建examresult和examresultopic
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="examInfo"></param>
        /// <returns></returns>
        public static int CreateExam(int userid, FP_Exam_ExamInfo examInfo)
        {
            Dictionary <int, List <string> > question_strs = CreateQuestion(examInfo.id);

            if (question_strs == null)
            {
                return(-2);
            }
            if (question_strs.Count() == 0)
            {
                return(-1);
            }
            //创建新的examresult对象
            FP_Exam_ExamResult new_exam = new FP_Exam_ExamResult();

            new_exam.uid          = userid;
            new_exam.channelid    = examInfo.channelid;
            new_exam.sortid       = examInfo.sortid;
            new_exam.departid     = null;
            new_exam.examid       = examInfo.id;
            new_exam.examname     = examInfo.name;
            new_exam.examtime     = examInfo.examtime;
            new_exam.examtype     = examInfo.examtype;
            new_exam.showanswer   = 1;
            new_exam.allowdelete  = 0;
            new_exam.total        = examInfo.total;
            new_exam.passmark     = examInfo.passmark;
            new_exam.score1       = 0;
            new_exam.score2       = 0;
            new_exam.score        = 0;
            new_exam.utime        = 0;
            new_exam.islimit      = 0;
            new_exam.starttime    = DateTime.Now;
            new_exam.endtime      = new_exam.starttime.Value.AddMinutes(examInfo.examtime.Value);
            new_exam.examdatetime = new_exam.starttime;
            new_exam.credits      = 0;
            int question_sum = 0;

            foreach (int key in question_strs.Keys)
            {
                question_sum += question_strs[key].Count();
            }
            new_exam.questions  = question_sum;
            new_exam.wrongs     = 0;
            new_exam.unanswer   = 0;
            new_exam.exp        = 0;
            new_exam.getcredits = 0;
            new_exam.exnote     = "";
            new_exam.attachid   = FPRandom.CreateCode(30);
            new_exam.status     = 0;
            new_exam.paper      = 1;
            new_exam.ip         = GetLocalIP();
            new_exam.mac        = "00-00-00-00-00-00";
            new_exam.isvideo    = 0;
            new_exam.client     = "mobile";
            new_exam.papertype  = 0;
            new_exam.title      = examInfo.name;
            new_exam.address    = "";
            db.FP_Exam_ExamResult.Add(new_exam);
            db.SaveChanges();
            //创建新的examresultopic对象
            List <FP_Exam_ExamTopic> examtopics = db.FP_Exam_ExamTopic.Where(t => t.examid == new_exam.examid).ToList();

            for (int i = 0; i < examtopics.Count(); i++)
            {
                FP_Exam_ExamResultTopic new_examresultopic = new FP_Exam_ExamResultTopic();
                new_examresultopic.resultid  = new_exam.id;
                new_examresultopic.type      = examtopics[i].type;
                new_examresultopic.title     = examtopics[i].title;
                new_examresultopic.display   = examtopics[i].display;
                new_examresultopic.perscore  = examtopics[i].perscore;
                new_examresultopic.score     = 0;
                new_examresultopic.questions = examtopics[i].questions;
                new_examresultopic.wrongs    = 0;
                List <string> questionlist     = question_strs[examtopics[i].id];
                string        questionlist_str = "";
                for (int j = 0; j < questionlist.Count(); j++)
                {
                    questionlist_str += questionlist[j];
                    if (j < (questionlist.Count() - 1))
                    {
                        questionlist_str += ",";
                    }
                }
                new_examresultopic.questionlist = questionlist_str;
                new_examresultopic.answerlist   = "";
                new_examresultopic.scorelist    = "";
                new_examresultopic.correctlist  = "";
                new_examresultopic.paper        = null;
                db.FP_Exam_ExamResultTopic.Add(new_examresultopic);
            }
            db.SaveChanges();
            return(new_exam.id);
        }
Пример #5
0
        /// <summary>
        /// 考试页
        /// </summary>
        /// <param name="resultid"></param>
        /// <returns></returns>
        public ActionResult Examing(int resultid)
        {
            var examresult      = db.FP_Exam_ExamResult.SingleOrDefault(t => t.id == resultid);
            var examresultopics = db.FP_Exam_ExamResultTopic.Where(t => t.resultid == resultid).ToList();

            //添加判断当前考试是否还在正常进行的条件
            //考试不存在
            if (examresult == null)
            {
                return(RedirectToAction("Index", "Announce", new { content = "当前考试不存在", buttonContent = "返回首页", backUrl = ExamingHelp.domainPath + "Exam/Index", type = AnnounceType.FAIL }));
            }
            //考试不属于当前用户
            var user = Session["FP_WAPLOGIN"] as FP_WMS_UserInfo;

            if (examresult.uid != user.id)
            {
                return(RedirectToAction("Index", "Announce", new { content = "当前考试不属于您", buttonContent = "返回首页", backUrl = ExamingHelp.domainPath + "/Exam/Index", type = AnnounceType.FAIL }));
            }
            //考试结束
            if (examresult.status == 1)
            {
                return(RedirectToAction("Index", "Announce", new { content = "当前考试已经结束", buttonContent = "返回首页", backUrl = ExamingHelp.domainPath + "/Exam/Index", type = AnnounceType.FAIL }));
            }
            //只能在手机端进行手机端创建的考试
            if (examresult.client != "mobile")
            {
                return(RedirectToAction("Index", "Announce", new { content = "请在电脑端完成考试", buttonContent = "返回首页", backUrl = ExamingHelp.domainPath + "/Exam/Index", type = AnnounceType.FAIL }));
            }
            Dictionary <FP_Exam_ExamResultTopic, List <QuestionModel> > questionDic = new Dictionary <FP_Exam_ExamResultTopic, List <QuestionModel> >();
            int answeredSum = 0;

            for (int i = 0; i < examresultopics.Count(); i++)
            {
                List <QuestionModel> questions = new List <QuestionModel>();
                if (examresultopics[i].questionlist.Contains(","))
                {
                    string[] question_strs = examresultopics[i].questionlist.Split(',');
                    string[] answer_strs   = null;
                    if (examresultopics[i].answerlist != "")
                    {
                        answer_strs = examresultopics[i].answerlist.Split('§');
                    }
                    int cnd = 1;
                    foreach (string question_str in question_strs)
                    {
                        try
                        {
                            int           qid      = int.Parse(question_str);
                            var           question = db.FP_Exam_ExamQuestion.SingleOrDefault(t => t.id == qid);
                            QuestionModel new_q    = new QuestionModel();
                            new_q.SortId = cnd++;
                            new_q.Title  = question.title.Replace("<br />", "");
                            List <string> options     = new List <string>();
                            string[]      option_strs = question.content.Split('§');
                            foreach (string value in option_strs)
                            {
                                options.Add(value);
                            }
                            new_q.options = options;
                            if (answer_strs != null && answer_strs[cnd - 2] != "")
                            {
                                new_q.now_option = ((int)answer_strs[cnd - 2][0]) - 64;
                                answeredSum++;
                            }
                            else
                            {
                                new_q.now_option = 0;
                            }
                            new_q.Id = qid;
                            questions.Add(new_q);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }
                questionDic.Add(examresultopics[i], questions);
            }
            examresult.client = "mobile";
            db.SaveChanges();
            ViewBag.questionDic = questionDic;
            ViewBag.examname    = examresult.examname;
            ViewBag.resultid    = resultid;
            ViewBag.answeredSum = answeredSum;
            ViewBag.useTime     = examresult.utime;
            ViewBag.channal     = examresult.channelid;
            double stime = (examresult.endtime.Value - DateTime.Now).TotalSeconds;
            int    mm    = (int)stime / 60;
            int    ss    = (int)stime - (mm * 60);

            if (mm < 0)
            {
                mm = 0;
            }
            if (ss < 0)
            {
                ss = 0;
            }
            ViewBag.sTime = (mm >= 10 ? mm + "" : ("0" + mm)) + ":" + (ss >= 10 ? ss + "" : ("0" + ss));
            return(View());
        }