Exemple #1
0
        /// <summary>
        /// 创建该场考试的问题列表
        /// </summary>
        /// <param name="examid"></param>
        /// <returns></returns>
        public static Dictionary <int, List <string> > CreateQuestion(int examid)
        {
            var examTopics = db.FP_Exam_ExamTopic.Where(t => t.examid == examid).ToList();

            if (examTopics.Count() == 0)
            {
                return(null);
            }
            Dictionary <int, List <string> > question_dic = new Dictionary <int, List <string> >();
            List <string> question_strs = new List <string>();

            foreach (FP_Exam_ExamTopic examtopic in examTopics)
            {
                question_strs.Clear();
                if (examtopic.randomsort != "")
                {
                    string[] sort_strs  = examtopic.randomsort.Split(',');
                    string[] count_strs = examtopic.randomcount.Split(',');
                    for (int i = 0; i < sort_strs.Count(); i++)
                    {
                        int sortid = int.Parse(sort_strs[i].Split('_')[0]);
                        int count  = int.Parse(count_strs[i]);
                        FP_Exam_SortQuestion sortQuestion    = db.FP_Exam_SortQuestion.SingleOrDefault(t => t.sortid == sortid & t.type == examtopic.type);
                        string[]             questionlist    = sortQuestion.questionlist.Split(',');
                        List <string>        randomQuestions = getRandomQuestion(questionlist, count);
                        question_strs.AddRange(randomQuestions);
                    }
                    question_strs = ListRandom(question_strs);
                }
                else
                {
                    List <FP_Exam_SortQuestion> sortQuestions = db.FP_Exam_SortQuestion.Where(t => t.type == examtopic.type & t.counts > 0).ToList();
                    List <string[]>             questionlists = new List <string[]>();
                    int len = 0;
                    for (int i = 0; i < sortQuestions.Count(); i++)
                    {
                        string[] questionlist = sortQuestions[i].questionlist.Split(',');
                        questionlists.Add(questionlist);
                        len += questionlist.Length;
                    }
                    string[] waitquestions = new string[len];
                    int      cnd           = 0;
                    for (int i = 0; i < questionlists.Count(); i++)
                    {
                        questionlists[i].CopyTo(waitquestions, cnd);
                        cnd += questionlists[i].Length;
                    }
                    List <string> randomQuestions = getRandomQuestion(waitquestions, examtopic.questions.Value);
                    question_strs.AddRange(randomQuestions);
                }
                List <string> strs = new List <string>();
                for (int i = 0; i < question_strs.Count(); i++)
                {
                    strs.Add(question_strs[i]);
                }
                question_dic.Add(examtopic.id, strs);
            }

            return(question_dic);
        }
Exemple #2
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);
     }
 }