示例#1
0
        /// <summary>
        /// 按章节抽题时,各章节题型数量
        /// </summary>
        /// <param name="tp">试卷对象</param>
        /// <param name="olid">章节id,如果小于1,则取所有</param>
        /// <returns></returns>
        public TestPaperItem[] GetItemForOlCount(TestPaper tp, int olid)
        {
            List <TestPaperItem> list = new List <TestPaperItem>();

            if (tp != null && !string.IsNullOrWhiteSpace(tp.Tp_FromConfig))
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(tp.Tp_FromConfig, false);
                XmlNodeList nodes = xmlDoc.SelectNodes("Config/Outline/Items/TestPaperItem");
                for (int i = 0; i < nodes.Count; i++)
                {
                    TestPaperItem tpi = new TestPaperItem();
                    tpi.FromXML(nodes[i].OuterXml);
                    if (olid <= 0)
                    {
                        list.Add(tpi);
                    }
                    if (olid > 0 && tpi.Ol_ID == olid)
                    {
                        list.Add(tpi);
                    }
                }
            }
            return(_getItemCoutomOrder(list.ToArray()));
        }
示例#2
0
 public int AddTestPaper(TestPaper testPaper)
 {
     try
     {
         if (testPaper.Id != 0)
         {
             TestPaper dbTestPaper = _myDbContext.TestPaper.FirstOrDefault(c => c.Id == testPaper.Id);
             if (dbTestPaper != null)
             {
                 dbTestPaper.SubjectId = testPaper.SubjectId;
                 dbTestPaper.Subtitle  = testPaper.Subtitle;
                 dbTestPaper.Title     = testPaper.Title;
                 dbTestPaper.IsFinish  = true;
                 _myDbContext.SaveChanges();
                 return(testPaper.Id);
             }
         }
         _myDbContext.TestPaper.Add(testPaper);
         _myDbContext.SaveChanges();
         return(testPaper.Id);
     }
     catch
     {
         return(-1);
     }
 }
示例#3
0
        private TestPaper GenerateTestPaper(int testId, string userId)
        {
            var examTest = _examTestRep.GetModelByTestId(testId);

            if (examTest == null)
            {
                throw new NullReferenceException();
            }

            var questions = new List <Question>();

            if (examTest.SingleCount > 0)
            {
                questions.AddRange(GenerateQuestions(examTest.DeptId, examTest.SubjectId, QuestionType.单选题, examTest.SingleCount));
            }

            if (examTest.MultiCount > 0)
            {
                questions.AddRange(GenerateQuestions(examTest.DeptId, examTest.SubjectId, QuestionType.多选题, examTest.MultiCount));
            }

            if (examTest.JudgeCount > 0)
            {
                questions.AddRange(GenerateQuestions(examTest.DeptId, examTest.SubjectId, QuestionType.判断题, examTest.JudgeCount));
            }

            var testPaper = new TestPaper(testId, userId, examTest.SubjectId, DateTime.Now, examTest.TestTime,
                                          examTest.SingleCount, examTest.SinglePer,
                                          examTest.MultiCount, examTest.MultiPer,
                                          examTest.JudgeCount, examTest.JudgePer, questions);

            SaveToCache(testId, userId, testPaper);
            return(testPaper);
        }
示例#4
0
        /// <summary>
        /// 返回试卷的大项,不管是按课程,还是按章节
        /// </summary>
        /// <param name="tp"></param>
        /// <returns></returns>
        public TestPaperItem[] GetItemForAny(TestPaper tp)
        {
            Song.Entities.TestPaperItem[] tpi  = null;
            List <TestPaperItem>          list = new List <TestPaperItem>();

            if (tp.Tp_FromType == 0)
            {
                tpi = this.GetItemForAll(tp);
                foreach (Song.Entities.TestPaperItem t in tpi)
                {
                    if (t.TPI_Count > 0)
                    {
                        list.Add(t);
                    }
                }
            }
            if (tp.Tp_FromType == 1)
            {
                tpi = this.GetItemForOlPercent(tp);
                foreach (Song.Entities.TestPaperItem t in tpi)
                {
                    if (t.TPI_Percent > 0)
                    {
                        list.Add(t);
                    }
                }
            }
            return(_getItemCoutomOrder(list.ToArray()));
        }
示例#5
0
        public void PagerSave(TestPaper entity)
        {
            entity.Tp_Lasttime = DateTime.Now;
            //相关联的课程名称
            Course cou = Gateway.Default.From <Course>().Where(Course._.Cou_ID == entity.Cou_ID).ToFirst <Course>();

            if (cou != null)
            {
                entity.Cou_Name = cou.Cou_Name;
            }
            using (DbTrans tran = Gateway.Default.BeginTrans())
            {
                try
                {
                    tran.Save <TestPaper>(entity);
                    tran.Update <Examination>(new Field[] { Examination._.Exam_PassScore, Examination._.Exam_Total },
                                              new object[] { entity.Tp_PassScore, entity.Tp_Total }, Examination._.Tp_Id == entity.Tp_Id);
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
                finally
                {
                    tran.Close();
                }
            }
        }
示例#6
0
        public string AutoAddTestPaper(TestPaper testPaper, double percent)
        {
            using (DbContextTransaction transaction = _myDbContext.Database.BeginTransaction())
            {
                try
                {
                    testPaper.IsFinish = true;
                    _myDbContext.TestPaper.Add(testPaper);
                    _myDbContext.SaveChanges();
                    int QuestionTypenumber = (int)((percent * 10) / 2);

                    List <QuestionType> questionType = new List <QuestionType>();
                    foreach (var qi in _myDbContext.QuestionType.Include(c => c.ExaminationQuestions).ToArray())
                    {
                        if (qi.ExaminationQuestions.Count() > 0)
                        {
                            questionType.Add(qi);
                        }
                    }
                    int    percentNum = questionType.Count();
                    Random rd         = new Random();
                    List <ExaminationQuestion> examinationQuestions = _myDbContext.ExaminationQuestion.Where(c => c.SubjectId == testPaper.SubjectId).ToList();
                    if (examinationQuestions.Count() == 0)
                    {
                        return("该科目题库没有题目");
                    }
                    for (int i = 0; i < 3; i++)
                    {
                        int questionTypeNumber = rd.Next(0, 3);
                        PaperQuestionType paperQuestionType = new PaperQuestionType()
                        {
                            PaperQuestionTitle = questionType[questionTypeNumber].QuestionTypeName,
                            QuestionTypeId     = questionType[questionTypeNumber].Id,
                            TestPaperId        = testPaper.Id
                        };
                        _myDbContext.PaperQuestionType.Add(paperQuestionType);
                        _myDbContext.SaveChanges();
                        for (int j = 0; j < 5; j++)
                        {
                            ExaminationQuestion examinationQuestion = GetRandomExaminationQuestion(examinationQuestions, questionType[questionTypeNumber].Id, percentNum);
                            _myDbContext.ExaminationQuestionPaperType.Add(new ExaminationQuestionPaperType()
                            {
                                PaperQuestionTypeId   = paperQuestionType.Id,
                                ExaminationQuestionId = examinationQuestion.Id
                            });
                        }
                    }
                    _myDbContext.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                }
            }
            return("生成成功");
        }
示例#7
0
        public bool TestIsExit(TestPaper newTest)
        {
            var isExists = _repository.Project <TestPaper, bool>(
                tests => (from t in tests
                          where t.Title == newTest.Title && t.ClassId == newTest.ClassId
                          select t).Any());

            return(isExists);
        }
示例#8
0
        public void AutoAddTemplateTestPaper()
        {
            if (string.IsNullOrEmpty(TestPaper.Subtitle) || string.IsNullOrEmpty(TestPaper.Title))
            {
                PUMessageBox.ShowDialog("内容不能为空");
                return;
            }

            PUMessageBox.ShowDialog(_examinationPaperBusiness.AutoAddTemplateTestPaper(TestPaper, ProgressPercent));
            TestPaper = new TestPaper();
        }
示例#9
0
 /// <summary>
 /// 出卷,输出试卷内容
 /// </summary>
 /// <param name="tp">试卷对象</param>
 /// <returns></returns>
 public Dictionary <TestPaperItem, Questions[]> Putout(TestPaper tp)
 {
     if (tp.Tp_FromType == 1)
     {
         return(_putout_1(tp));
     }
     else
     {
         return(_putout_0(tp));
     }
 }
 public void DeleteTestPaper()
 {
     if (TestPaper == null)
     {
         PUMessageBox.ShowDialog("请选择试卷");
         return;
     }
     _examinationPaperBusiness.DeleteTestPaper(TestPaper.Id);
     TestPaper = new TestPaper();
     Init();
 }
示例#11
0
 void InitializeTestPaper()
 {
     totalNum           = GetTotalNum();
     currentNum         = 0;
     leftNum            = totalNum - currentNum;
     wrongNum           = 0;
     testPaper          = new TestPaper(totalNum, GetRange(), GetLength(), GetIsRandom()); //初始化从entry里取值string to int怎么搞。
     currentArithmetic  = testPaper.papers[currentNum];
     BindingContext     = testPaper;                                                       //实际没用上,还不会用binding
     labelTotalNum.Text = "Total Number: " + totalNum.ToString();
     RefleshStatus();
 }
示例#12
0
 public ActionResult Index(TestPaper paper)
 {
     if (ModelState.IsValid)
     {
         paper.IsActive  = true;
         paper.CreatedOn = DateTime.Now;
         ctx.TestPapers.Add(paper);
         ctx.SaveChanges();
         return(RedirectToAction("ViewAllTestPapers"));
     }
     return(View(paper));
 }
示例#13
0
        public bool DeleteTestPaper(int id)
        {
            TestPaper dbTestPaper = _myDbContext.TestPaper.FirstOrDefault(c => c.Id == id);

            if (dbTestPaper == null)
            {
                return(false);
            }
            _myDbContext.TestPaper.Remove(dbTestPaper);
            _myDbContext.SaveChanges();
            return(true);
        }
示例#14
0
        public void SaveToCache(int testId, string userId, TestPaper testPaper)
        {
            //SaveToRedis
            string key     = "TestPaper_" + testId;
            string dataKey = testId + "-" + userId;

            if (_redis.HashExists(key, dataKey))
            {
                _redis.HashDelete(key, dataKey);
            }

            _redis.HashSet <TestPaper>(key, dataKey, testPaper);
        }
示例#15
0
 public void AddTestPaper()
 {
     if (_examinationPaperBusiness.AddTestPaper(TestPaper) != 1)
     {
         PUMessageBox.ShowDialog("添加成功");
         TestPaper         = new TestPaper();
         QuestionTableList = new BindableCollection <ExaminationQuestionModel>();
     }
     else
     {
         PUMessageBox.ShowDialog("添加失败");
     }
     ;
 }
示例#16
0
        public bool SaveTestPaper(TestPaper testPaper)
        {
            TestPaper dbTestPaper = _myDbContext.TestPaper.FirstOrDefault(c => c.Id == testPaper.Id);

            if (dbTestPaper == null)
            {
                return(false);
            }
            dbTestPaper.SubjectId          = testPaper.SubjectId;
            dbTestPaper.Subtitle           = testPaper.Subtitle;
            dbTestPaper.Title              = testPaper.Title;
            dbTestPaper.PaperQuestionTypes = testPaper.PaperQuestionTypes;
            _myDbContext.SaveChanges();
            return(true);
        }
示例#17
0
        public int PagerAdd(TestPaper entity)
        {
            Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent();
            if (org != null)
            {
                entity.Org_ID   = org.Org_ID;
                entity.Org_Name = org.Org_Name;
            }
            entity.Tp_CrtTime = DateTime.Now;
            //相关联的课程名称
            Course cou = Gateway.Default.From <Course>().Where(Course._.Cou_ID == entity.Cou_ID).ToFirst <Course>();

            if (cou != null)
            {
                entity.Cou_Name = cou.Cou_Name;
            }
            Gateway.Default.Save <TestPaper>(entity);
            return(entity.Tp_Id);
            //if (items == null)
            //{
            //    return Gateway.Default.Save<TestPaper>(entity);
            //}
            //int id = -1;
            //using (DbTrans tran = Gateway.Default.BeginTrans())
            //    try
            //    {
            //        int sumCount = 0;
            //        foreach (TestPaperItem tpi in items)
            //        {
            //            tpi.Tp_UID = entity.Tp_UID;
            //            tran.Save<TestPaperItem>(tpi);
            //            sumCount += (int)tpi.TPI_Count;
            //        }
            //        entity.Tp_Count = sumCount;
            //        id = tran.Save<TestPaper>(entity);
            //        tran.Commit();
            //        return id;
            //    }
            //    catch (Exception ex)
            //    {
            //        tran.Rollback();
            //        throw ex;
            //    }
            //    finally
            //    {
            //        tran.Close();
            //    }
        }
示例#18
0
 /// <summary>
 /// 按章节抽题时,各题型占比
 /// </summary>
 /// <param name="tp">试卷对象</param>
 /// <returns></returns>
 public TestPaperItem[] GetItemForOlPercent(TestPaper tp)
 {
     TestPaperItem[] tpi = null;
     if (tp != null && !string.IsNullOrWhiteSpace(tp.Tp_FromConfig))
     {
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.LoadXml(tp.Tp_FromConfig, false);
         XmlNodeList nodes = xmlDoc.SelectNodes("Config/Outline/Percent/TestPaperItem");
         tpi = new TestPaperItem[nodes.Count];
         for (int i = 0; i < nodes.Count; i++)
         {
             tpi[i] = new TestPaperItem();
             tpi[i].FromXML(nodes[i].OuterXml);
         }
     }
     return(_getItemCoutomOrder(tpi));
 }
        public JsonResult saveQuestion(TestPaperViewModel viewModel)
        {
            CMSResult cmsResult = new CMSResult();
            TestPaper testPaper = new TestPaper
            {
                ClassId = viewModel.ClassId,
                Title   = viewModel.Title
            };
            var subjects   = _subjectService.GetAllSubjects().Where(x => x.ClassId == viewModel.ClassId).Select(x => new { x.SubjectId, x.Name });
            var result     = subjects.Count() != 0 ? _testPaperService.TestIsExit(testPaper) : false;
            var tId        = result != false ? 0 : 1;
            var returnData = new
            {
                Data     = tId.ToString(),
                Subjects = subjects
            };

            return(Json(returnData, JsonRequestBehavior.AllowGet));
        }
示例#20
0
        public TestPaper GetTestPaperById(int id)
        {
            TestPaper result = _myDbContext.TestPaper.Include(c => c.Subject).Include(c => c.PaperQuestionTypes).First(c => c.Id == id);

            if (result.PaperQuestionTypes != null)
            {
                foreach (var paperQuestionType in result.PaperQuestionTypes)
                {
                    paperQuestionType.QuestionType = _myDbContext.QuestionType.FirstOrDefault(c => c.Id == paperQuestionType.QuestionTypeId);
                    paperQuestionType.ExaminationQuestionPaperTypes = _myDbContext.ExaminationQuestionPaperType.Include(c => c.ExaminationQuestion).Where(c => c.PaperQuestionTypeId == paperQuestionType.Id).ToArray();
                    foreach (var exa in paperQuestionType.ExaminationQuestionPaperTypes)
                    {
                        exa.ExaminationQuestion.OptionItems = _myDbContext.OptionItem.Where(c => c.ExaminationQuestionsId == exa.ExaminationQuestion.Id).ToArray();
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// 发布试卷
        /// </summary>
        /// <returns></returns>
        public ActionResult CreatSendPaper()
        {
            int stubaseTestPaperId = Convert.ToInt32(Request["stubaseTestPaperId"]);
            int stuClassId         = Convert.ToInt32(Request["stuClassId"]);
            int stuCourseId        = Convert.ToInt32(Request["stuCourseId"]);

            DateTime StartTime = DateTime.Parse(Request["StartTime"]);
            DateTime EndTime   = DateTime.Parse(Request["EndTime"]);

            //找到该班级下面的所有学生Id
            int[] stuIds = studentService.GetAllStudentIdByClassId(stuClassId);
            //为该班级下的每个学生发布试题
            bool b = false;

            for (int i = 0; i < stuIds.Length; i++)
            {
                TestPaper testPaper = new TestPaper()
                {
                    TestPaperStartTime = StartTime,
                    TestPaperEndTime   = EndTime,
                };
                testPaper.Course        = courseService.GetModelById(stuCourseId);
                testPaper.Student       = studentService.GetModelById(stuIds[i]);
                testPaper.BaseTestPaper = baseTestPaperService.GetModelById(stubaseTestPaperId);
                if (testPaperService.Add(testPaper))
                {
                    b = true;
                }
                else
                {
                    b = false;
                }
            }
            if (b == true)
            {
                return(Content("ok"));
            }
            else
            {
                return(Content("no"));
            }
        }
示例#22
0
        public CMSResult Save(TestPaper newTest)
        {
            CMSResult cmsresult = new CMSResult();
            var       isExists  = _repository.Project <TestPaper, bool>(
                tests => (from t in tests
                          where t.Title == newTest.Title && t.ClassId == newTest.ClassId
                          select t).Any());

            if (isExists)
            {
                cmsresult.Results.Add(new Result("Title already exists!", false));
            }
            else
            {
                _repository.Add(newTest);
                _repository.CommitChanges();
                cmsresult.Results.Add(new Result("Test paper added successfully!", true));
            }
            return(cmsresult);
        }
示例#23
0
        public CMSResult Update(TestPaper oldTest)
        {
            CMSResult cmsresult = new CMSResult();
            var       result    = new Result();
            var       testPaper = _repository.Load <TestPaper>(x => x.TestPaperId == oldTest.TestPaperId);

            if (testPaper == null)
            {
                result.IsSuccessful = false;
                result.Message      = "Test paper not exist!";
            }
            else
            {
                var isExists = _repository.Project <TestPaper, bool>(
                    tests => (from t in tests
                              where t.Title == oldTest.Title &&
                              t.TestPaperId != oldTest.TestPaperId
                              select t).Any());

                if (isExists)
                {
                    result.IsSuccessful = false;
                    result.Message      = string.Format("Test paper {0} already exists!", oldTest.Title);
                }
                else
                {
                    testPaper.ClassId = oldTest.ClassId;
                    testPaper.DelimitedQuestionIds = oldTest.DelimitedQuestionIds;
                    testPaper.TestType             = oldTest.TestType;
                    testPaper.Title = oldTest.Title;
                    testPaper.DelimitedChapterIds = oldTest.DelimitedChapterIds;
                    testPaper.QuestionCount       = oldTest.QuestionCount;
                    _repository.Update(testPaper);

                    result.IsSuccessful = true;
                    result.Message      = string.Format("Test paper added successfully!");
                }
            }
            cmsresult.Results.Add(result);
            return(cmsresult);
        }
        public JsonResult Save(TestPaperViewModel viewModel)
        {
            TestPaper testPaper = new TestPaper
            {
                ClassId = viewModel.ClassId,
                DelimitedQuestionIds = viewModel.DelimitedQuestionIds,
                TestType             = viewModel.TestType,
                Title = viewModel.Title,
                DelimitedChapterIds = viewModel.DelimitedChapterIds,
                SubjectName         = viewModel.SubjectName,
                QuestionCount       = viewModel.QuestionCount
            };
            var result     = _testPaperService.Save(testPaper);
            var tId        = result != null ? testPaper.TestPaperId : 0;
            var returnData = new
            {
                Data = tId.ToString(),
            };

            return(Json(returnData, JsonRequestBehavior.AllowGet));
        }
示例#25
0
        /// <summary>
        /// 按课程抽题组卷
        /// </summary>
        /// <param name="tp"></param>
        /// <returns></returns>
        private Dictionary <TestPaperItem, Questions[]> _putout_0(TestPaper tp)
        {
            //获取试题项,例如单选题、多选题
            Song.Entities.TestPaperItem[] tpi  = this.GetItemForAll(tp);
            List <TestPaperItem>          list = new List <TestPaperItem>();

            foreach (Song.Entities.TestPaperItem t in tpi)
            {
                if (t.TPI_Count > 0)
                {
                    list.Add(t);
                }
            }
            tpi = _getItemCoutomOrder(list.ToArray());
            //开始出卷
            Dictionary <TestPaperItem, Questions[]> dic = new Dictionary <TestPaperItem, Questions[]>();

            foreach (Song.Entities.TestPaperItem t in tpi)
            {
                int   type  = (int)t.TPI_Type;
                int   count = (int)t.TPI_Count;    //当前题型的试题数
                float num   = (float)t.TPI_Number; //当前题型占的分数
                if (count < 1)
                {
                    continue;
                }
                //当前类型的试题
                Song.Entities.Questions[] ques = Business.Do <IQuestions>().QuesRandom(tp.Org_ID, (int)tp.Sbj_ID, tp.Cou_ID, -1, type, tp.Tp_Diff, tp.Tp_Diff2, true, count);
                if (ques.Length < 1)
                {
                    continue;
                }
                ques = clacScore(ques, num);
                dic.Add(t, ques);
            }
            return(dic);
        }
示例#26
0
 public TestPaperItem[] GetItemForAll(TestPaper tp)
 {
     TestPaperItem[] tpi = null;
     if (tp != null && !string.IsNullOrWhiteSpace(tp.Tp_FromConfig))
     {
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.LoadXml(tp.Tp_FromConfig, false);
         XmlNodeList nodes = xmlDoc.SelectNodes("Config/All/Items/TestPaperItem");
         tpi = new TestPaperItem[nodes.Count];
         for (int i = 0; i < nodes.Count; i++)
         {
             tpi[i] = new TestPaperItem();
             tpi[i].FromXML(nodes[i].OuterXml);
         }
     }
     if (tpi == null)
     {
         tpi = Gateway.Default.From <TestPaperItem>()
               .Where(TestPaperItem._.Tp_UID == tp.Tp_UID && TestPaperItem._.TPI_Count > 0)
               .OrderBy(TestPaperItem._.TPI_Type.Asc)
               .ToArray <TestPaperItem>();
     }
     return(_getItemCoutomOrder(tpi));
 }
示例#27
0
        /// <summary>
        /// 按章节抽题组卷
        /// </summary>
        /// <param name="tp"></param>
        /// <returns></returns>
        private Dictionary <TestPaperItem, Questions[]> _putout_1(TestPaper tp)
        {
            //获取试题项,例如单选题、多选题
            Song.Entities.TestPaperItem[] tpi  = this.GetItemForOlPercent(tp);
            List <TestPaperItem>          list = new List <TestPaperItem>();

            foreach (Song.Entities.TestPaperItem t in tpi)
            {
                if (t.TPI_Percent > 0)
                {
                    list.Add(t);
                }
            }
            tpi = _getItemCoutomOrder(list.ToArray());
            //***************  开始抽取试题
            List <Questions> listQus = new List <Questions>();

            //1、获取章节
            Outline[] outlines = Gateway.Default.From <Outline>().Where(Outline._.Cou_ID == tp.Cou_ID && Outline._.Ol_PID == 0).ToArray <Outline>();
            foreach (Outline ol in outlines)
            {
                //2、取当前章节的各题型数量
                TestPaperItem[] tpols = this.GetItemForOlCount(tp, ol.Ol_ID);
                foreach (TestPaperItem it in tpols)
                {
                    if (it.TPI_Count < 1)
                    {
                        continue;
                    }
                    bool isExist = false;
                    foreach (TestPaperItem t in tpi)
                    {
                        if (it.TPI_Type == t.TPI_Type)
                        {
                            isExist = true;
                            continue;
                        }
                    }
                    if (!isExist)
                    {
                        continue;
                    }
                    //3、抽取试题,并将抽到题汇集到一起,即到listQus列表中去
                    Questions[] ques = Business.Do <IQuestions>().QuesRandom(tp.Org_ID, -1, tp.Cou_ID, ol.Ol_ID, it.TPI_Type, -1, -1, true, it.TPI_Count);
                    foreach (Questions q in ques)
                    {
                        listQus.Add(q);
                    }
                }
            }
            //****************  开始出卷
            Dictionary <TestPaperItem, Questions[]> dic = new Dictionary <TestPaperItem, Questions[]>();

            foreach (Song.Entities.TestPaperItem t in tpi)
            {
                float            num   = (float)t.TPI_Number; //当前题型占的分数
                List <Questions> qusTm = new List <Questions>();
                //当前类型的试题
                foreach (Questions q in listQus)
                {
                    if (q.Qus_Type == t.TPI_Type)
                    {
                        qusTm.Add(q);
                    }
                }
                if (qusTm.Count < 1)
                {
                    continue;
                }
                Questions[] ques = clacScore(qusTm.ToArray(), num);
                dic.Add(t, ques);
            }
            return(dic);
        }
示例#28
0
        public string AutoAddTemplateTestPaper(TestPaper testPaper, double percent)
        {
            using (DbContextTransaction transaction = _myDbContext.Database.BeginTransaction())
            {
                try
                {
                    testPaper.IsFinish = true;
                    _myDbContext.TestPaper.Add(testPaper);
                    _myDbContext.SaveChanges();
                    int percentNum = (int)((percent * 10));
                    List <QuestionType> questionTypes = new List <QuestionType>();
                    foreach (var qt in _myDbContext.QuestionType.Include(c => c.ExaminationQuestions).ToList())
                    {
                        int count = qt.ExaminationQuestions.Where(c => c.SubjectId == testPaper.SubjectId).Count();
                        if (count >= 10)
                        {
                            questionTypes.Add(qt);
                        }
                    }
                    ;


                    if (questionTypes.Count() < 3)
                    {
                        return("题目类型不足");
                    }

                    List <ExaminationQuestion> examinationQuestions = _myDbContext.ExaminationQuestion.Where(c => c.SubjectId == testPaper.SubjectId).ToList();

                    #region 添加非选择题
                    QuestionType questionType2 = questionTypes.FirstOrDefault(c => !c.HasOption);
                    if (questionType2 == null)
                    {
                        transaction.Rollback();
                        return("题目类型不足");
                    }
                    else
                    {
                        questionTypes.Remove(questionType2);
                    }
                    PaperQuestionType paperQuestionType2 = new PaperQuestionType()
                    {
                        PaperQuestionTitle = questionType2.QuestionTypeName,
                        QuestionTypeId     = questionType2.Id,
                        TestPaperId        = testPaper.Id
                    };
                    _myDbContext.PaperQuestionType.Add(paperQuestionType2);
                    _myDbContext.SaveChanges();
                    for (int j = 0; j < 10; j++)
                    {
                        ExaminationQuestion examinationQuestion = GetRandomExaminationQuestion(examinationQuestions, questionType2.Id, percentNum);
                        if (examinationQuestion == null)
                        {
                            transaction.Rollback();
                            return("该科目题库题目数量不足");
                        }
                        examinationQuestions.Remove(examinationQuestion);
                        _myDbContext.ExaminationQuestionPaperType.Add(new ExaminationQuestionPaperType()
                        {
                            PaperQuestionTypeId   = paperQuestionType2.Id,
                            ExaminationQuestionId = examinationQuestion.Id
                        });
                    }

                    #endregion
                    #region 添加非选择题
                    QuestionType questionType3 = questionTypes.FirstOrDefault(c => !c.HasOption);
                    if (questionType3 == null)
                    {
                        transaction.Rollback();
                        return("题目类型不足");
                    }
                    else
                    {
                        questionTypes.Remove(questionType3);
                    }
                    PaperQuestionType paperQuestionType3 = new PaperQuestionType()
                    {
                        PaperQuestionTitle = questionType3.QuestionTypeName,
                        QuestionTypeId     = questionType3.Id,
                        TestPaperId        = testPaper.Id
                    };
                    _myDbContext.PaperQuestionType.Add(paperQuestionType3);
                    _myDbContext.SaveChanges();
                    for (int j = 0; j < 5; j++)
                    {
                        ExaminationQuestion examinationQuestion = GetRandomExaminationQuestion(examinationQuestions, questionType3.Id, percentNum);
                        if (examinationQuestion == null)
                        {
                            transaction.Rollback();
                            return("该科目题库题目数量不足");
                        }
                        examinationQuestions.Remove(examinationQuestion);
                        _myDbContext.ExaminationQuestionPaperType.Add(new ExaminationQuestionPaperType()
                        {
                            PaperQuestionTypeId   = paperQuestionType3.Id,
                            ExaminationQuestionId = examinationQuestion.Id
                        });
                    }

                    #endregion

                    #region 添加选择题
                    QuestionType questionType = questionTypes.FirstOrDefault(c => c.HasOption);
                    if (questionType == null)
                    {
                        return("题目类型不足");
                    }
                    else
                    {
                        questionTypes.Remove(questionType);
                    }
                    if (examinationQuestions.Count() == 0)
                    {
                        return("该科目题库没有题目");
                    }
                    if (examinationQuestions.Count() < 20)
                    {
                        return("该科目题库题目数量不足");
                    }
                    PaperQuestionType paperQuestionType = new PaperQuestionType()
                    {
                        PaperQuestionTitle = questionType.QuestionTypeName,
                        QuestionTypeId     = questionType.Id,
                        TestPaperId        = testPaper.Id
                    };
                    _myDbContext.PaperQuestionType.Add(paperQuestionType);
                    _myDbContext.SaveChanges();
                    for (int j = 0; j < 10; j++)
                    {
                        ExaminationQuestion examinationQuestion = GetRandomExaminationQuestion(examinationQuestions, questionType.Id, percentNum);
                        if (examinationQuestion == null)
                        {
                            transaction.Rollback();
                            return("该科目题库题目数量不足");
                        }
                        examinationQuestions.Remove(examinationQuestion);
                        _myDbContext.ExaminationQuestionPaperType.Add(new ExaminationQuestionPaperType()
                        {
                            PaperQuestionTypeId   = paperQuestionType.Id,
                            ExaminationQuestionId = examinationQuestion.Id
                        });
                    }

                    #endregion
                    _myDbContext.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return(e.Message);
                }
            }
            return("生成成功");
        }
示例#29
0
        public async static void CreateTestPaperWord(TestPaper testPaper)
        {
            object path;                              //文件路径变量
            string strContent;                        //文本内容变量

            MSWord.Application wordApp;               //Word应用程序变量
            MSWord.Document    wordDoc;               //Word文档变量
            string             pathStr = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\QBM\";

            Directory.CreateDirectory(pathStr);
            wordApp         = new MSWord.Application(); //初始化
            pathStr         = pathStr + "TestPaper" + testPaper.Id + ".doc";
            wordApp.Visible = false;                    //使文档可见
            path            = pathStr;
            //如果已存在,则删除
            if (!File.Exists((string)path))
            {
                //由于使用的是COM库,因此有许多变量需要用Missing.Value代替
                Object Nothing = Missing.Value;
                wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                #region 页面设置、页眉图片和文字设置,最后跳出页眉设置
                //页面设置
                wordDoc.PageSetup.PaperSize      = MSWord.WdPaperSize.wdPaperA4;          //设置纸张样式为A4纸
                wordDoc.PageSetup.Orientation    = MSWord.WdOrientation.wdOrientPortrait; //排列方式为垂直方向
                wordDoc.PageSetup.TopMargin      = 57.0f;
                wordDoc.PageSetup.BottomMargin   = 57.0f;
                wordDoc.PageSetup.LeftMargin     = 57.0f;
                wordDoc.PageSetup.RightMargin    = 57.0f;
                wordDoc.PageSetup.HeaderDistance = 30.0f;//页眉位置
                #endregion

                #region 页码设置并添加页码
                //为当前页添加页码
                MSWord.PageNumbers pns = wordApp.Selection.Sections[1].Headers[MSWord.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers; //获取当前页的号码
                pns.NumberStyle               = MSWord.WdPageNumberStyle.wdPageNumberStyleNumberInDash;                                         //设置页码的风格,是Dash形还是圆形的
                pns.HeadingLevelForChapter    = 0;
                pns.IncludeChapterNumber      = false;
                pns.RestartNumberingAtSection = false;
                pns.StartingNumber            = 1;                                         //开始页页码
                object pagenmbetal = MSWord.WdPageNumberAlignment.wdAlignPageNumberCenter; //将号码设置在中间
                object first       = true;
                wordApp.Selection.Sections[1].Footers[MSWord.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers.Add(ref pagenmbetal, ref first);
                #endregion
                wordApp.Selection.ParagraphFormat.LineSpacing     = 16f; //设置文档的行间距
                wordApp.Selection.ParagraphFormat.FirstLineIndent = 30;  //首行缩进的长度
                wordApp.Selection.ParagraphFormat.Alignment       = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
                object unite = MSWord.WdUnits.wdStory;
                wordApp.Selection.EndKey(ref unite, ref Nothing);
                strContent = testPaper.Title + "\n";
                wordDoc.Paragraphs.Last.Range.Font.Size = 20;
                wordDoc.Paragraphs.Last.Range.Font.Name = "黑体";
                wordDoc.Paragraphs.Last.Range.Text      = strContent;
                wordApp.Selection.EndKey(ref unite, ref Nothing);
                wordDoc.Paragraphs.Last.Range.Font.Size = 16;
                strContent = testPaper.Subtitle + "\n";
                wordDoc.Paragraphs.Last.Range.Font.Underline = MSWord.WdUnderline.wdUnderlineThick;
                wordDoc.Paragraphs.Last.Range.Text           = strContent;
                int paperQuestionTypeNumber = 1;
                wordApp.Selection.EndKey(ref unite, ref Nothing);
                wordDoc.Paragraphs.Last.Range.Font.Underline = MSWord.WdUnderline.wdUnderlineNone;
                foreach (var paperQuestionType in testPaper.PaperQuestionTypes)
                {
                    wordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphLeft;
                    strContent = paperQuestionTypeNumber + "、" + paperQuestionType.PaperQuestionTitle + "\n";
                    bool hasOption = paperQuestionType.QuestionType.HasOption;
                    wordApp.Selection.EndKey(ref unite, ref Nothing);
                    wordDoc.Paragraphs.Last.Range.Font.Size = 14;
                    wordDoc.Paragraphs.Last.Range.Font.Name = "黑体";
                    wordDoc.Paragraphs.Last.Range.Text      = strContent;
                    int examinationQuestionNumber = 1;
                    foreach (var examinationQuestion in paperQuestionType.ExaminationQuestionPaperTypes)
                    {
                        strContent = examinationQuestionNumber + "、" + examinationQuestion.ExaminationQuestion.Content + "\n";
                        wordApp.Selection.EndKey(ref unite, ref Nothing);
                        wordDoc.Paragraphs.Last.Range.Font.Size = 12;
                        wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
                        if (hasOption)
                        {
                            wordDoc.Paragraphs.Last.Range.Text = strContent;
                            wordApp.Selection.EndKey(ref unite, ref Nothing);
                            OptionItem[] optionItems = examinationQuestion.ExaminationQuestion.OptionItems.ToArray();
                            wordDoc.Paragraphs.Last.Range.Font.Size = 10;
                            if (optionItems[0].OptionContent.Length > 45 || optionItems[1].OptionContent.Length > 45 || optionItems[2].OptionContent.Length > 45 || optionItems[3].OptionContent.Length > 45)
                            {
                                wordDoc.Paragraphs.Last.Range.Text = String.Format(OptionTemplate3, optionItems[0].OptionContent, optionItems[1].OptionContent, optionItems[2].OptionContent, optionItems[3].OptionContent);
                            }
                            else if (optionItems[0].OptionContent.Length > 15 || optionItems[1].OptionContent.Length > 15 || optionItems[2].OptionContent.Length > 15 || optionItems[3].OptionContent.Length > 15)
                            {
                                wordDoc.Paragraphs.Last.Range.Text = String.Format(OptionTemplate2, optionItems[0].OptionContent, optionItems[1].OptionContent, optionItems[2].OptionContent, optionItems[3].OptionContent);
                            }
                            else
                            {
                                wordDoc.Paragraphs.Last.Range.Text = String.Format(OptionTemplate, optionItems[0].OptionContent, optionItems[1].OptionContent, optionItems[2].OptionContent, optionItems[3].OptionContent);
                            }
                        }
                        else
                        {
                            wordDoc.Paragraphs.Last.Range.Text = strContent;
                        }

                        examinationQuestionNumber++;
                    }
                    paperQuestionTypeNumber++;
                }
                object format = MSWord.WdSaveFormat.wdFormatDocument; // office 2007就是wdFormatDocumentDefault
                                                                      //将wordDoc文档对象的内容保存为DOCX文档
                wordDoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
                //关闭wordApp组件对象
                wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
            }
            OpenWord(path);
        }
示例#30
0
        public TestPaper PagerSingle(int identify)
        {
            TestPaper pager = Gateway.Default.From <TestPaper>().Where(TestPaper._.Tp_Id == identify).ToFirst <TestPaper>();

            return(pager);
        }