Beispiel #1
0
        int id = WeiSha.Common.Request.QueryString["id"].Int32 ?? 0;    //当前模拟考试的id
        protected override void InitPageTemplate(HttpContext context)
        {
            if (Request.ServerVariables["REQUEST_METHOD"] == "GET")
            {
                //当前试卷
                Song.Entities.TestPaper paper = null;
                paper = Business.Do <ITestPaper>().PagerSingle(id);
                if (paper != null)
                {
                    this.Document.SetValue("pager", paper);
                }
            }
            //此页面的ajax提交,全部采用了POST方式
            if (Request.ServerVariables["REQUEST_METHOD"] == "POST")
            {
                string action = WeiSha.Common.Request.Form["action"].String;
                switch (action)
                {
                case "delete":
                    delete();
                    break;

                case "list":
                    list();
                    break;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 随机出题
        /// </summary>
        /// <returns></returns>
        private string randomJson()
        {
            //取果是第一次打开,则随机生成试题,此为获取试卷
            Song.Entities.TestPaper tp = Business.Do <ITestPaper>().PagerSingle(tpid);
            //难度区间
            int diff1 = tp.Tp_Diff > tp.Tp_Diff2 ? (int)tp.Tp_Diff2 : (int)tp.Tp_Diff;
            int diff2 = tp.Tp_Diff > tp.Tp_Diff2 ? (int)tp.Tp_Diff : (int)tp.Tp_Diff2;

            //获取试题项
            Song.Entities.TestPaperItem[] tpi = Business.Do <ITestPaper>().GetItemForAll(tp);
            string json = "[";

            for (int i = 0; i < tpi.Length; i++)
            {
                Song.Entities.TestPaperItem pi = tpi[i];
                //类型,试题数目,该类型占多少分,
                int   type  = (int)pi.TPI_Type;
                int   count = (int)pi.TPI_Count;
                float num   = (float)pi.TPI_Number;
                if (count < 1)
                {
                    continue;
                }
                string quesObj = "{";
                quesObj += "'type':" + type + ",'count':" + count + ",'number':" + num + ",";
                //当前类型的试题
                Song.Entities.Questions[] ques = Business.Do <IQuestions>().QuesRandom(tp.Org_ID, (int)tp.Sbj_ID, -1, -1, type, diff1, diff2, true, count);
                ques     = clacScore(ques, num);
                quesObj += "'ques':[";
                for (int n = 0; n < ques.Length; n++)
                {
                    ques[n].Qus_Explain = "";
                    ques[n].Qus_Answer  = "";
                    ques[n]             = Extend.Questions.TranText(ques[n]);
                    string js = ques[n].ToJson();
                    //如果是单选题,或多选题,或填空题
                    if (ques[n].Qus_Type == 1 || ques[n].Qus_Type == 2 || ques[n].Qus_Type == 5)
                    {
                        quesObj += getAnserJson(ques[n], js);
                    }
                    else
                    {
                        quesObj += js;
                    }
                    if (n < ques.Length - 1)
                    {
                        quesObj += ",";
                    }
                }
                quesObj += "]";
                quesObj += "}";
                if (i < tpi.Length - 1)
                {
                    quesObj += ",";
                }
                json += quesObj;
            }
            json += "]";
            return(json.Replace("'", "\""));
        }
        /// <summary>
        /// 获取考试的试卷信息
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        protected Song.Entities.TestPaper getTestPaper(object[] para)
        {
            int tpid = 0;

            if (para.Length > 0 && para[0] is int)
            {
                int.TryParse(para[0].ToString(), out tpid);
            }
            Song.Entities.TestPaper tp = Business.Do <ITestPaper>().PagerSingle(tpid);
            return(tp);
        }
Beispiel #4
0
        /// <summary>
        /// 获取列表
        /// </summary>
        private void list()
        {
            //int id = WeiSha.Common.Request.QueryString["id"].Int32 ?? 0;    //当前模拟考试的id
            int size  = WeiSha.Common.Request.Form["size"].Int32 ?? 10;   //每页多少条
            int index = WeiSha.Common.Request.Form["index"].Int32 ?? 1;   //第几页
            //仅限的输出字段
            string onlyFeild = WeiSha.Common.Request.Form["only"].String; //输出哪些字段
            string wipeFeild = WeiSha.Common.Request.Form["wipe"].String; //哪些字段不输出

            //
            Song.Entities.Accounts st = Extend.LoginState.Accounts.CurrentUser;
            int stid = st.Ac_ID;   //当前学员

            Song.Entities.Course currCourse = Extend.LoginState.Accounts.Course();

            int sumcount = 0;

            Song.Entities.TestResults[] tps = Business.Do <ITestPaper>().ResultsPager(stid, id, size, index, out sumcount);
            string json = "{\"size\":" + size + ",\"index\":" + index + ",\"sumcount\":" + sumcount + ",";

            json += "\"items\":[";
            for (int n = 0; n < tps.Length; n++)
            {
                tps[n].Tp_Name = tps[n].Tp_Name.Replace("\r", "").Replace("\n", "").Replace("\t", "");
                //增加输出项
                Dictionary <string, object> addParas = new Dictionary <string, object>();
                Song.Entities.TestPaper     tp       = Business.Do <ITestPaper>().PagerSingle((int)tps[n].Tp_Id);
                if (tp != null)
                {
                    tp.Tp_Logo = string.IsNullOrWhiteSpace(tp.Tp_Logo) ? tp.Tp_Logo : Upload.Get["TestPaper"].Virtual + tp.Tp_Logo;
                    addParas.Add("Tp_Logo", tp.Tp_Logo);
                    addParas.Add("Tp_PassScore", tp.Tp_PassScore);
                }
                json += tps[n].ToJson(onlyFeild, wipeFeild, addParas) + ",";
            }
            if (json.EndsWith(","))
            {
                json = json.Substring(0, json.Length - 1);
            }
            json += "]}";
            Response.Write(json);
            Response.End();
        }
Beispiel #5
0
        protected override void InitPageTemplate(HttpContext context)
        {
            #region 判断是否登录
            state = new Examing_State(this.Document);
            //如果未登录
            if (!Extend.LoginState.Accounts.IsLogin || this.Account == null)
            {
                state.Set(false, -1);   //
                return;
            }
            #endregion

            #region 当前考试信息
            //当前考试的场次
            Song.Entities.Examination exam = Business.Do <IExamination>().ExamSingle(examid);
            if (exam == null || !exam.Exam_IsUse || exam.Exam_IsTheme)
            {
                state.Set(false, 0);    //没有考试,状态为0;
                return;
            }
            this.Document.SetValue("exam", exam);
            this.Document.SetValue("uid", exam.Exam_UID);
            //当前考试的主题
            Song.Entities.Examination theme = Business.Do <IExamination>().ExamSingle(exam.Exam_UID);
            this.Document.SetValue("theme", theme);
            //当前试卷
            Song.Entities.TestPaper pager = Business.Do <ITestPaper>().PagerSingle(exam.Tp_Id);
            this.Document.SetValue("pager", pager);
            #endregion

            #region 是否允许参加考试
            //当前考生是否可以参加该场考试
            bool isAllow = Business.Do <IExamination>().ExamIsForStudent(examid, Account.Ac_ID);
            if (!isAllow)
            {
                state.Set(false, 2);    //不需要参加考试,状态2
                return;
            }
            #endregion

            #region 判断是否开始、结束,是否交卷
            bool     isStart, isOver, isSubmit;
            DateTime startTime, overTime;
            //答题记录
            Song.Entities.ExamResults exr = Business.Do <IExamination>().ResultSingleForCache(examid, exam.Tp_Id, Account.Ac_ID);
            //判断是否已经开始、是否已经结束
            if (exam.Exam_DateType == 1)
            {
                //固定时间开始
                isStart   = exam.Exam_Date <= DateTime.Now;                           //是否开始
                isOver    = DateTime.Now > exam.Exam_Date.AddMinutes(exam.Exam_Span); //是否结束
                startTime = exam.Exam_Date;                                           //开始时间
                overTime  = exam.Exam_Date.AddMinutes(exam.Exam_Span);                //结束时间
                isSubmit  = exr != null ? exr.Exr_IsSubmit : false;                   //是否交卷
            }
            else
            {
                //按时间区间
                isStart   = DateTime.Now > exam.Exam_Date && DateTime.Now < exam.Exam_DateOver; //是否开始
                isOver    = DateTime.Now > exam.Exam_DateOver;                                  //是否结束
                startTime = exam.Exam_Date <= DateTime.Now ? DateTime.Now : exam.Exam_Date;     //开始时间
                overTime  = exam.Exam_DateOver.AddMinutes(exam.Exam_Span);                      //结束时间
                isSubmit  = exr != null ? exr.Exr_IsSubmit : false;                             //是否交卷
                if (exr != null && !string.IsNullOrWhiteSpace(exr.Exr_Results))
                {
                    XmlDocument resXml = new XmlDocument();
                    resXml.XmlResolver = null;
                    resXml.LoadXml(exr.Exr_Results, false);
                    XmlNode xn = resXml.LastChild;
                    //考试的开始与结束时间,防止学员刷新考试界面,导致时间重置
                    long lbegin, lover;
                    long.TryParse(xn.Attributes["begin"] != null ? xn.Attributes["begin"].Value : "0", out lbegin);
                    long.TryParse(xn.Attributes["overtime"] != null ? xn.Attributes["overtime"].Value : "0", out lover);
                    lbegin = lbegin * 10000;
                    lover  = lover * 10000;
                    DateTime dtStart   = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                    DateTime beginTime = dtStart.Add(new TimeSpan(lbegin));
                    overTime  = dtStart.Add(new TimeSpan(lover));                                     //得到转换后的结束时间
                    startTime = startTime = exam.Exam_Date <= beginTime ? beginTime : exam.Exam_Date; //开始时间;
                    isOver    = DateTime.Now > overTime;
                    isSubmit  = DateTime.Now > overTime || exr.Exr_IsSubmit;                          //是否交卷
                }
            }
            this.Document.SetValue("isStart", isStart.ToString().ToLower());
            this.Document.SetValue("isOver", isOver.ToString().ToLower());
            this.Document.SetValue("startTime", WeiSha.Common.Server.getTime(startTime));
            this.Document.SetValue("overTime", WeiSha.Common.Server.getTime(overTime));
            this.Document.SetValue("isSubmit", isSubmit.ToString().ToLower());
            if (!isStart)
            {
                state.Set(true, 4);            //还没有开始
            }
            if (isOver)
            {
                state.Set(false, 1);            //考试已经结束,状态为1;
            }
            if (isSubmit)
            {
                state.Set(false, 3);            //已经参加过考试
            }
            if (startTime <= DateTime.Now && overTime > DateTime.Now && !isSubmit)
            {
                state.Set(true, 5); //正在考试
            }
            #endregion

            //基本参数,uid,服务器端时间
            this.Document.SetValue("servertime", WeiSha.Common.Server.getTime()); //服务器端时间与格林威治时间(零时区)的时差,单位为小时
            this.Document.RegisterGlobalFunction(this.getSubjectPath);            //专业的上级专业等
        }