Song.Site/Ajax/QuesRandom.ashx.cs

(完整代码) 2KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WeiSha.Common;
using Song.ServiceInterfaces;

namespace Song.Site.Ajax
{
    /// <summary>
    /// QuesRandom 的摘要说明
    /// </summary>
    public class QuesRandom : IHttpHandler
    {
        //专业id,题型,难度等级
        private int sbjid = WeiSha.Common.Request.QueryString["sbjid"].Int32 ?? 0;
        private int type = WeiSha.Common.Request.QueryString["type"].Int32 ?? 0;
        private int diff = WeiSha.Common.Request.QueryString["diff"].Int32 ?? 0;        
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Song.Entities.Questions[] ques = Business.Do<IQuestions>().QuesRandom(type, sbjid, -1, diff, diff, true, 1);
            string tm = "";
            if (ques.Length > 0)
            {
                Song.Entities.Questions q = Extend.Questions.TranText(ques[0]);
                tm = q.ToJson();
                //如果是单选题,或多选题
                if (q.Qus_Type == 1 || q.Qus_Type == 2 || q.Qus_Type == 5)
                    tm = getAnserJson(q.Qus_UID, tm);
            }

            context.Response.Write(tm);
            context.Response.End();
        }
        private string getAnserJson(string uid, string json)
        {
            //当前试题的答案
            Song.Entities.QuesAnswer[] ans = Business.Do<IQuestions>().QuestionsAnswer(uid, null);
            string ansStr = "[";
            for (int i = 0; i < ans.Length; i++)
            {
                ans[i] = Extend.Questions.TranText(ans[i]);
                ansStr += ans[i].ToJson();
                if (i < ans.Length - 1) ansStr += ",";
            }
            ansStr += "]";
            json = json.Replace("}", ",\"Answer\":" + ansStr + "}");
            return json;
        }        
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。