예제 #1
0
        //计算排名、击败人数
        private void CalculationRank(TimeSpan StudyTime, int Count, int userId)
        {
            //所有用户的学习时间
            List <TimeSpan> spanList = new List <TimeSpan>();
            //所有用户的学习次数
            List <int> countList = new List <int>();
            //记录每个用户的学习时间
            TimeSpan spanTemp = new TimeSpan();
            //获取所有用户
            var userList = Entity.UserInfo.Where(a => true).ToList();

            foreach (var item in userList)
            {
                //获取每个用户的学习记录
                var seatDetail = Entity.SeatDetail.Where(a => a.UserId == item.Id).ToList();
                //计算每个用户的学习时间
                if (userId == item.Id)
                {
                    spanTemp = StudyTime;
                }
                else
                {
                    spanTemp = CommonTool.CalculationStudyTime(seatDetail);
                }
                //记录每个有用户的学习时间和次数
                spanList.Add(spanTemp);
                countList.Add(seatDetail.Count);
            }
            //顺序排序
            spanList.Sort();
            countList.Sort();
            //倒序排序
            countList.Reverse();
            spanList.Reverse();
            int selfSpanRank  = spanList.IndexOf(StudyTime) + 1;
            int selfCountRank = countList.IndexOf(Count) + 1;

            ViewData["SpanRank"]  = selfSpanRank;  //时间排名
            ViewData["CountRank"] = selfCountRank; //次数排名

            //时间击败百分比
            double spanPercent = Convert.ToDouble(selfSpanRank) / Convert.ToDouble(spanList.Count);

            ViewData["SpanPercent"] = string.Format("{0:0.00%}", 1 - spanPercent);
            //次数击败百分比
            double countPercent = Convert.ToDouble(selfCountRank) / Convert.ToDouble(countList.Count);

            ViewData["CountPercent"] = string.Format("{0:0.00%}", 1 - countPercent);
            //次数击败%
            ViewData["Rank"] = countList.Count - selfCountRank; //排名击败人数
        }
예제 #2
0
        //计算第一名
        private void CalculationRank()
        {
            //统计学习记录
            List <Study> studyList = new List <Study>();
            //设置分页
            int pageIndex = Request.QueryString["pageIndex"] != null?int.Parse(Request.QueryString["pageIndex"]) : 1;

            int pageSize = 2;//页面记录数

            //获取所有用户
            var      userList    = Entity.UserInfo.Where(a => true).ToList();
            UserInfo user        = new UserInfo();
            TimeSpan maxTimeSpan = new TimeSpan();
            Study    study       = null;

            //查询第一名
            foreach (var item in userList)
            {
                study          = new Study();
                study.UserInfo = item;
                if (item.SeatDetail != null && item.SeatDetail.Count > 0)
                {
                    TimeSpan span = CommonTool.CalculationStudyTime(item.SeatDetail.ToList());//获取学习时间
                    if (span > maxTimeSpan)
                    {
                        maxTimeSpan = span;
                        user        = item;
                    }
                    study.Count           = item.SeatDetail.Count;
                    study.TimeSpan        = span;
                    study.FormartTimeSpan = CommonTool.SetStudyTimeFormat(span).ToString();
                }
                studyList.Add(study);
            }
            ViewData["UserName"] = user.Name;
            StringBuilder sb = CommonTool.SetStudyTimeFormat(maxTimeSpan);

            ViewData["MaxTimeSpan"] = sb.ToString();
            ViewData["MaxCount"]    = user.SeatDetail.Count;

            //生成导航条
            string strBar = PageBarHelper.GetPagaBar(pageIndex, studyList.Count, pageSize);

            //设置每页展示指定的记录
            studyList = studyList.Where(a => true).OrderBy(a => a.UserInfo.Id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList <Study>();

            ViewData["List"] = studyList;
            ViewData["Bar"]  = strBar;
        }
예제 #3
0
        //管理员主页
        public ActionResult Index()
        {
            //获取学习记录
            var seatDetail = Entity.SeatDetail.Where(a => true).ToList();
            //计算总的学习时间
            TimeSpan span = CommonTool.CalculationStudyTime(seatDetail);
            //设置时间格式
            StringBuilder sb = CommonTool.SetStudyTimeFormat(span);

            ViewData["StudyTime"] = sb.ToString();
            //计算总的学习次数
            ViewData["Count"] = seatDetail.Count;
            //获取第一名
            CalculationRank();
            return(View());
        }
예제 #4
0
        //个人主页
        public ActionResult Index()
        {
            int userId   = Convert.ToInt32(Session["UserId"]);
            var userInfo = Entity.UserInfo.FirstOrDefault(a => a.Id == userId);
            //获取学习记录
            var seatDetail = Entity.SeatDetail.Where(a => a.UserId == userId).ToList();
            //计算总的学习时间
            TimeSpan span = CommonTool.CalculationStudyTime(seatDetail);
            //设置时间格式
            StringBuilder sb = CommonTool.SetStudyTimeFormat(span);

            ViewData["StudyTime"] = sb.ToString();
            //计算总的学习次数
            ViewData["Count"] = seatDetail.Count;
            //计算排名、击败次数
            CalculationRank(span, seatDetail.Count, userId);
            return(View(userInfo));
        }