コード例 #1
0
        /// <summary>
        /// 小组按id选择话题.
        /// </summary>
        /// <param name="groupId">小组id</param>
        /// <param name="topicId">话题id</param>
        /// <returns>返回</returns>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        /// <exception cref="T:Xmu.Crms.Shared.Exceptions.GroupNotFoundException">未找到小组</exception>
        public long InsertTopicByGroupId(long groupId, long topicId)
        {
            //id <= 0
            if (groupId <= 0 || topicId <= 0)
            {
                throw new ArgumentException("id格式错误");
            }

            //未找到小组
            SeminarGroup _sg;

            if ((_sg = _db.SeminarGroup.Find(groupId)) == null)
            {
                throw new GroupNotFoundException();
            }

            //新建SeminarGroupTopic对象
            SeminarGroupTopic sgt = new SeminarGroupTopic();

            sgt.SeminarGroup = _sg;
            sgt.Topic        = _db.Topic.Find(topicId);

            _db.SeminarGroupTopic.Add(sgt);

            _db.SaveChanges();

            return(sgt.Id);
        }
コード例 #2
0
        //获取话题选取情况
        public int GetRestTopicById(long topicId, long classId)
        {
            int result = 0;
            int count  = 0;

            try
            {
                Topic topic = _topicDao.GetTopic(topicId);
                result = topic.GroupNumberLimit;
                IList <SeminarGroup> seminarGroup = _topicDao.GetSeminarGroupById(classId, topic.Seminar.Id);
                foreach (var s in seminarGroup)
                {
                    SeminarGroupTopic seminarGroupTopic = _topicDao.GetSeminarGroupTopic(topicId, s.Id);
                    if (seminarGroupTopic != null)
                    {
                        count++;
                    }
                }
            }
            catch (System.Exception e)
            {
                if (e.ToString().Equals("找不到该话题!"))
                {
                    throw e;
                }
            }
            result -= count;
            return(result);
        }
コード例 #3
0
        //得到SeminarGroupTopic表的记录
        public SeminarGroupTopic GetSeminarGroupTopic(long topicId, long groupId)
        {
            SeminarGroupTopic s = _db.SeminarGroupTopic.Include(t => t.Topic).Include(t => t.SeminarGroup).Where(t => t.Topic.Id == topicId && t.SeminarGroup.Id == groupId).SingleOrDefault();

            if (s == null)
            {
                throw new SeminarNotFoundException();
            }
            return(s);
        }
コード例 #4
0
 //先在seminarGroupTopic 和userinfo service查好,在这里传入实体对象seminarGroupTopic,userInfo
 public void InsertGroupGradeByUserId(SeminarGroupTopic seminarGroupTopic, UserInfo userInfo, int grade)
 {
     using (var scope = _db.Database.BeginTransaction())
     {
         try
         {
             StudentScoreGroup ssg = new StudentScoreGroup {
                 Student = userInfo, SeminarGroupTopic = seminarGroupTopic, Grade = grade
             };
             _db.StudentScoreGroup.Add(ssg);
             _db.SaveChanges();
         }
         catch
         {
             scope.Rollback();
             throw;
         }
     }
 }
コード例 #5
0
        public SeminarGroupTopic GetSeminarGroupTopicById(long topicId, long groupId)
        {
            if (groupId < 0)
            {
                throw new System.ArgumentException("Parameter format error", "groupId");
            }
            if (topicId < 0)
            {
                throw new System.ArgumentException("Parameter format error", "topicId");
            }

            SeminarGroupTopic groupTopic = new SeminarGroupTopic();

            var topic = _db.SeminarGroupTopic.Where(p => p.Topic.Id == topicId).Where(r => r.SeminarGroup.Id == groupId).SingleOrDefault();

            groupTopic.Id                = topic.Id;
            groupTopic.Topic             = topic.Topic;
            groupTopic.SeminarGroup      = topic.SeminarGroup;
            groupTopic.PresentationGrade = topic.PresentationGrade;

            return(groupTopic);
        }
コード例 #6
0
 //按topicId和小组Id删除SeminarGroupTopic
 public void DeleteSeminarGroupTopic(long topicId, long groupId)
 {
     using (var scope = _db.Database.BeginTransaction())
     {
         SeminarGroupTopic seminarGroupTopic = _db.SeminarGroupTopic.Where(s => s.Topic.Id == topicId && s.SeminarGroup.Id == groupId).SingleOrDefault <SeminarGroupTopic>();
         try
         {
             List <StudentScoreGroup> list = _db.StudentScoreGroup.Include(s => s.SeminarGroupTopic).Where(t => t.SeminarGroupTopic.Id == seminarGroupTopic.Id).ToList <StudentScoreGroup>();
             foreach (var l in list)
             {
                 _db.StudentScoreGroup.Remove(l);
             }
             _db.SeminarGroupTopic.Remove(seminarGroupTopic);
             _db.SaveChanges();
             scope.Commit();
         }
         catch (System.Exception e)
         {
             scope.Rollback();
             throw e;
         }
     }
 }
コード例 #7
0
 public void InsertGroupGradeByUserId(long topicId, long userId, long groupId, int grade)
 {
     try
     {
         //调用TopicService中GetSeminarGroupTopicById(long topicId, long groupId)方法
         SeminarGroupTopic seminarGroupTopic = _iTopicService.GetSeminarGroupTopicById(topicId, groupId);
         //调用UserService中的GetUserByUserId(long userId)方法
         UserInfo userInfo = _iUserService.GetUserByUserId(userId);
         //调用自己的dao
         _iGradeDao.InsertGroupGradeByUserId(seminarGroupTopic, userInfo, grade);
     }
     catch (GroupNotFoundException gre)
     {
         throw gre;
     }
     catch (UserNotFoundException ure)
     {
         throw ure;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #8
0
        /// <summary>
        /// 仅作为普通方法,被下面的定时器方法调用.
        /// 讨论课结束后计算展示得分.
        /// @author fengjinliu
        /// 条件: 讨论课已结束  *GradeService
        /// </summary>
        /// <param name="seminarId">讨论课id</param>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        public void CountPresentationGrade(long seminarId, IList <Topic> topicList)
        {
            foreach (var topic in topicList)
            {
                //通过seminarGroupId获得List<SeminarGroupTopic>
                //通过seminarGrouptopicId获得List<StudentScoreGroup>
                long[]   idList;
                double[] gradeList;

                //获取选择该topic的所有小组
                var seminarGroupTopicList = _db.SeminarGroupTopic.Include(u => u.SeminarGroup).Include(u => u.Topic).Where(u => u.Topic.Id == topic.Id).ToList();
                if (seminarGroupTopicList == null)
                {
                    throw new GroupNotFoundException();
                }
                else
                {
                    idList    = new long[seminarGroupTopicList.Count];
                    gradeList = new double[seminarGroupTopicList.Count];

                    int groupNumber = 0;

                    //计算一个小组的所有学生打分情况
                    foreach (var i in seminarGroupTopicList)
                    {
                        //List<StudentScoreGroup> studentScoreList = new List<StudentScoreGroup>();
                        //获取学生打分列表
                        var studentScoreList = _db.StudentScoreGroup.Where(u => u.SeminarGroupTopic.Id == i.Id).ToList();
                        if (studentScoreList == null)//该组没有被打分
                        {
                            seminarGroupTopicList.Remove(i);
                        }
                        int?grade = 0; int k = 0;
                        foreach (var g in studentScoreList)
                        {
                            grade += g.Grade;
                            k++;
                        }
                        double avg = (double)grade / k;

                        //将小组该讨论课平均分和Id保存
                        idList[groupNumber]    = i.Id;
                        gradeList[groupNumber] = avg;
                        groupNumber++;
                    }
                    //将小组成绩从大到小排序
                    QuickSort(idList, gradeList, 0, groupNumber - 1);

                    Seminar   seminar;
                    ClassInfo classInfo;
                    try
                    {
                        seminar = _db.Seminar.Include(u => u.Course).Where(u => u.Id == seminarId).SingleOrDefault();
                        if (seminar == null)
                        {
                            throw new SeminarNotFoundException();
                        }
                        classInfo = _db.ClassInfo.Where(u => u.Id == seminar.Course.Id).SingleOrDefault();
                        if (classInfo == null)
                        {
                            throw new ClassNotFoundException();
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    //各小组按比例给分
                    int Five  = Convert.ToInt32(groupNumber * classInfo.FivePointPercentage * 0.01);
                    int Four  = Convert.ToInt32(groupNumber * classInfo.FourPointPercentage * 0.01);
                    int Three = Convert.ToInt32(groupNumber * classInfo.ThreePointPercentage * 0.01);
                    for (int i = 0; i < groupNumber; i++)
                    {
                        SeminarGroupTopic seminarGroupTopic = _db.SeminarGroupTopic.SingleOrDefault(s => s.Id == idList[i]);
                        //如果找不到该组
                        if (seminarGroupTopic == null)
                        {
                            throw new GroupNotFoundException();
                        }
                        //更新报告分
                        if (i >= 0 && i < Five)
                        {
                            seminarGroupTopic.PresentationGrade = 5;
                        }
                        if (i >= Five && i < Four)
                        {
                            seminarGroupTopic.PresentationGrade = 4;
                        }
                        if (i >= Four && i < groupNumber)
                        {
                            seminarGroupTopic.PresentationGrade = 3;
                        }
                        _db.SaveChanges();
                    }
                } //if end
            }     //foreach topic end
        }
コード例 #9
0
        ///新增定时器方法.
        ///<p>随机分组情况下,签到结束后十分钟给没有选择话题的小组分配话题<br>
        ///@author qinlingyun
        /// @param seminarId 讨论课的id
        /// @param seminarGroupId 小组的id
        /// @exception IllegalArgumentException 信息不合法,id格式错误
        /// @exception SeminarNotFoundException 未找到讨论课
        ///@exception GroupNotFoundException 未找到小组
        public void AutomaticallyAllotTopic(long seminarId)
        {
            if (seminarId <= 0)
            {
                throw new System.ArgumentException("id格式错误");
            }

            if (_db.Seminar.Find(seminarId) == null)
            {
                throw new SeminarNotFoundException();//未找到讨论课
            }
            //还没有选题的小组列表
            List <SeminarGroup> grouplist_not_have_topic = new List <SeminarGroup>();

            //筛选出这堂讨论课的小组列表
            List <SeminarGroup> grouplist_this_seminar = _db.SeminarGroup
                                                         .Include(sg => sg.Seminar)
                                                         .Where(sg => sg.Seminar.Id == seminarId)
                                                         .ToList();

            //对每个SeminarGroup
            foreach (SeminarGroup sg in grouplist_this_seminar)
            {
                if (_db.SeminarGroupTopic
                    .Include(sgt => sgt.SeminarGroup)
                    //如果和它的Id相同的SeminarGroupTopic.SeminarGroup.Id行数为0
                    .Where(sgt => sg.Id == sgt.SeminarGroup.Id)
                    .Count() == 0)
                {
                    //说明该小组未选题记录,
                    //将其添加进没有选题的小组列表
                    grouplist_not_have_topic.Add(sg);
                }
            }

            //准备添加的SeminarGroupTopic表项
            SeminarGroupTopic new_sgt = new SeminarGroupTopic();

            //筛选出这堂讨论课的话题列表
            List <Topic> topiclist_this_seminar = _db.Topic
                                                  .Include(tp => tp.Seminar)
                                                  .Where(tp => tp.Seminar.Id == seminarId)
                                                  .ToList();

            foreach (SeminarGroup sg_to_allot_topic in grouplist_not_have_topic)
            {
                new_sgt.SeminarGroup = sg_to_allot_topic;

                //被选择最少的话题
                Topic topic_be_chosen_least = null;
                int   min_chosen_count      = int.MaxValue;

                //对话题表中的每个话题
                foreach (Topic tp in topiclist_this_seminar)
                {
                    //统计被选择次数
                    int chosen_count = _db.SeminarGroupTopic
                                       .Include(sgt => sgt.Topic)
                                       .Where(sgt => sgt.Topic.Id == tp.Id)
                                       .Count();

                    if (chosen_count < min_chosen_count)
                    {
                        min_chosen_count      = chosen_count;
                        topic_be_chosen_least = tp;
                    }
                }//循环完之后,就找出当前被选择最少的话题

                //新表项的话题就是这个最少话题
                new_sgt.Topic = topic_be_chosen_least;

                //添加新表项
                _db.SeminarGroupTopic.Add(new_sgt);

                _db.SaveChanges();
            }//为没有选题的小组列表中所有组分配完话题
        }