public static Guid 随机生成试卷(取题条件 getProblemCondition, out int 试题充足情况)
        {
            试题充足情况 = 0;
            LoveKaoExamEntities db = new LoveKaoExamEntities();
            if (getProblemCondition.取题题型及数量集合.Count > 15)
            {
                throw new Exception("试卷题型不能超过15个!");
            }
            foreach (取题题型及数量 typeNum in getProblemCondition.取题题型及数量集合)
            {
                if (typeNum.数量 > 200)
                {
                    throw new Exception("每个题型下的题目不能超过200道!");
                }
            }
            试卷外部信息 outside = new 试卷外部信息();
            outside.ID = Guid.NewGuid();
            outside.爱考网ID = outside.ID;
            outside.创建人ID = 用户信息.CurrentUser.用户ID;
            outside.名称 = getProblemCondition.试卷名称;
            outside.说明 = "";
            outside.分类列表 = new List<string>();
            //给试卷内容赋值
            试卷内容 test = new 试卷内容();
            test.ID = Guid.NewGuid();
            test.名称 = getProblemCondition.试卷名称;
            test.说明 = "";
            test.提交人ID = outside.创建人ID;
            test.提交备注 = "";
            test.试卷外部信息ID = outside.ID;
            if (getProblemCondition.网站分类集合 == null || getProblemCondition.网站分类集合 == "")
            {
                throw new Exception("您还没选择分类,请先选择!");
            }
            if (getProblemCondition.网站分类集合 != null && getProblemCondition.网站分类集合 != "")
            {
                string[] sortList = getProblemCondition.网站分类集合.Split(",".ToCharArray());
                if (sortList.Length > 10)
                {
                    throw new Exception("分类选择不能超过10个!");
                }
                foreach (string sortName in sortList)
                {
                    outside.分类列表.Add(sortName);
                }
            }
            test.试卷中大题集合 = new List<试卷中大题>();
            decimal totalScore = 0;
            //遍历题型数量,并赋值
            for (int i = 0; i < getProblemCondition.取题题型及数量集合.Count; i++)
            {
                getProblemCondition.取题题型及数量集合[0] = getProblemCondition.取题题型及数量集合[i];
                List<试题外部信息表> listOutside = 试题外部信息.判断取题条件(getProblemCondition).ToList();
                totalScore += getProblemCondition.取题题型及数量集合[i].每小题分值 * getProblemCondition.取题题型及数量集合[i].数量;
                试卷中大题 type = new 试卷中大题();
                type.ID = Guid.NewGuid();
                type.名称 = getProblemCondition.取题题型及数量集合[i].题型名称;
                type.说明 = "";
                //随机取到的试题内容ID集合
                if (getProblemCondition.取题题型及数量集合[i].数量 != 0)
                {
                    List<Guid> listProblemId = 试题外部信息.随机取题(getProblemCondition.取题题型及数量集合[i].题型Enum,
                        getProblemCondition.取题题型及数量集合[i].数量, listOutside, 用户信息.CurrentUser.用户ID);
                    if (listProblemId.Count < getProblemCondition.取题题型及数量集合[i].数量)
                    {
                        试题充足情况 = 2;
                    }

                    type.试卷大题中试题集合 = new List<试卷大题中试题>();
                    //遍历题目数量,并赋值
                    for (int j = 0; j < listProblemId.Count; j++)
                    {

                        试卷大题中试题 testProblem = new 试卷大题中试题();
                        testProblem.ID = Guid.NewGuid();
                        testProblem.试题内容ID = listProblemId[j];
                        testProblem.每小题分值 = getProblemCondition.取题题型及数量集合[i].每小题分值;
                        testProblem.顺序 = Convert.ToByte(j);
                        type.试卷大题中试题集合.Add(testProblem);
                    }
                    //是复合题和多题干共选项题时给子集赋值
                    if (getProblemCondition.取题题型及数量集合[i].题型Enum > 39 && getProblemCondition.取题题型及数量集合[i].题型Enum < 50 ||
                        getProblemCondition.取题题型及数量集合[i].题型Enum == 80)
                    {
                        List<试题内容表> listSubContent = db.试题内容表.Where(a => listProblemId.Contains(a.父试题内容ID.Value)).ToList();
                        var groupSubContent = listSubContent.GroupBy(a => a.父试题内容ID).ToList();
                        foreach (试卷大题中试题 testProblem in type.试卷大题中试题集合)
                        {
                            testProblem.子小题集合 = new List<试卷大题中试题>();
                            var subContent = groupSubContent.Where(a => a.Key == testProblem.试题内容ID).First();
                            foreach (var sub in subContent)
                            {
                                试卷大题中试题 subTestProblem = new 试卷大题中试题();
                                subTestProblem.ID = Guid.NewGuid();
                                subTestProblem.每小题分值 = getProblemCondition.取题题型及数量集合[i].每小题分值 / subContent.Count();
                                subTestProblem.试题内容ID = sub.ID;
                                testProblem.子小题集合.Add(subTestProblem);
                            }
                        }
                    }
                }
                test.试卷中大题集合.Add(type);
            }
            test.总分 = Convert.ToInt32(totalScore);
            outside.当前试卷内容 = test;
            outside.试卷内容ID = test.ID;
            outside.总分 = Convert.ToInt32(totalScore);
            //加入缓存
            MemoryCache.Default.Add("" + outside.ID + "", outside, cacheRandomTest);
            if (试题充足情况 != 2)
            {
                试题充足情况 = 1;
            }
            return outside.ID;
        }
 public static IQueryable<试题外部信息表> 判断取题条件(取题条件 getProblemCondition)
 {
     LoveKaoExamEntities db = new LoveKaoExamEntities();
     IQueryable<试题外部信息表> query = db.试题外部信息表.Where(a => a.试题状态Enum == 0&&a.创建人ID==用户信息.CurrentUser.用户ID);
     //按题干搜索
     if (getProblemCondition.题干关键字 != null && getProblemCondition.题干关键字 != "")
     {
         //去掉前后空格
         getProblemCondition.题干关键字 = getProblemCondition.题干关键字.TrimStart();
         getProblemCondition.题干关键字 = getProblemCondition.题干关键字.TrimEnd();
         if (getProblemCondition.题干关键字 != "")
         {
             query = query.Where(a => a.试题查询内容.Contains(getProblemCondition.题干关键字));
         }
     }
     //题型
     if (getProblemCondition.取题题型及数量集合 != null)
     {
         if (getProblemCondition.取题题型及数量集合[0].题型Enum != 0)
         {
             byte 题型Enum=getProblemCondition.取题题型及数量集合[0].题型Enum;
             query = query.Where(a => a.小题型Enum == 题型Enum);
         }
     }
     //网站标签分类
     if (!string.IsNullOrEmpty(getProblemCondition.网站分类集合))
     {
         query =取分类下的试题(getProblemCondition.网站分类集合, query, db);
     }
     return query;
 }
        public static List<试题外部信息> 手工出卷查询题目(取题条件 getProblemCondition, int 第几页, int 页的大小, out int 返回总条数)
        {
            if (getProblemCondition.网站分类集合 != null && getProblemCondition.网站分类集合 != "")
            {
                string[] sortList = getProblemCondition.网站分类集合.Split(",".ToCharArray());
                if (sortList.Length > 10)
                {
                    throw new Exception("分类选择不能超过10个!");
                }
                //判断分类是否是已存在的分类
                List<string> listSort = sortList.ToList();
                int count = 分类.分类查询.Where(a => listSort.Contains(a.分类名称)).Count();
                if (listSort.Count != count)
                {
                    throw new Exception("您选择的分类不存在,请选择已有分类!");
                }
            }
            IQueryable<试题外部信息表> query = 判断取题条件(getProblemCondition);
            返回总条数 = query.Distinct().Count();
            if (返回总条数 == 0)
            {
                throw new Exception("没有找到符合条件的试题!");
            }
            List<试题外部信息表> list = query.Distinct().OrderByDescending(a => a.创建时间)
                .Skip(第几页 * 页的大小).Take(页的大小).ToList();
            List<试题外部信息> listOutside = 把试题外部信息表集合转化为试题外部信息集合(list);
            //查找对应的试题内容并赋值
            List<Guid> listContentId = list.Select(a => a.试题内容ID).ToList();
            List<试题内容> listContent = 试题内容.试题内容查询.Where(a => listContentId.Contains(a.ID)).ToList();
            foreach (试题外部信息 outside in listOutside)
            {
                foreach (试题内容 content in listContent)
                {
                    if (outside.试题内容ID == content.ID)
                    {
                        outside.当前试题内容 = content;
                        break;
                    }
                }
            }

            给试题外部信息列表赋值创建人属性(listOutside);
            给试题外部信息列表赋值分类列表属性(listOutside);
            return listOutside;
        }
        public JsonResult FindSubject(查找试题 m查找试题)
        {
            try
            {
                string strSubType = LKExamURLQueryKey.GetString("subType[]");
                string strSort = LKExamURLQueryKey.GetString("sortJson[]");
                int pageIndex = LKExamURLQueryKey.GetInt32("pageIndex");
                int pageSize = LKExamURLQueryKey.GetInt32("pageSize");
                Guid guid = LKExamURLQueryKey.GetGuid("userID");

                取题条件 getSubItem = new 取题条件();
                getSubItem.题干关键字 = m查找试题.subContent;
                getSubItem.会员ID = m查找试题.userID;
                getSubItem.网站分类集合 = strSort;
                if (!string.IsNullOrEmpty(strSubType))
                {
                    取题题型及数量 listSubType = new 取题题型及数量();
                    listSubType.题型Enum = Convert.ToByte(strSubType);
                    getSubItem.取题题型及数量集合 = new List<取题题型及数量>();
                    getSubItem.取题题型及数量集合.Add(listSubType);
                }

                int count = 0;
                if (!Convert.IsDBNull(getSubItem))
                {

                    List<试题外部信息> subData = 试题外部信息.手工出卷查询题目(getSubItem, pageIndex, pageSize, out count);
                    StringBuilder sb = new StringBuilder();
                    sb.Append("[");
                    foreach (试题外部信息 item in subData)
                    {

                        sb.Append(试题内容.转化成预览试题Json字符串带答案(item.当前试题内容, item) + ",");

                    }

                    int len = sb.Length;

                    string jsonText = len > 1 ? sb.ToString(0, len - 1) + "]" : "[]";
                    return LKPageJsonResult.GetData(new { result = true, subData = jsonText, count = count });

                }
                else
                {
                    return LKPageJsonResult.Failure();
                }
            }
            catch (Exception ex)
            {

                return LKPageJsonResult.Exception(ex);
            }
        }