Example #1
0
        /// <summary>
        /// 竞赛添加页面
        /// </summary>
        /// <returns>操作后的结果</returns>
        public ActionResult Add()
        {
            DateTime now = DateTime.Today.AddHours(DateTime.Now.Hour + 1);
            ContestEntity entity = new ContestEntity()
            {
                StartTime = now,
                EndTime = now.AddHours(2)
            };

            ViewBag.AllSupportedLanguages = LanguageManager.GetAllLanguageNames();

            return View("Edit", entity);
        }
Example #2
0
        public ActionResult Add(FormCollection form)
        {
            ContestEntity entity = new ContestEntity()
            {
                Title = form["title"],
                ContestType = (ContestType)Byte.Parse(form["type"]),
                Description = form["description"],
                StartTime = DateTime.Parse(String.Format("{0} {1}:{2}:{3}", form["startdate"], form["starthour"], form["startminute"], form["startsecond"])),
                EndTime = DateTime.Parse(String.Format("{0} {1}:{2}:{3}", form["enddate"], form["endhour"], form["endminute"], form["endsecond"])),
                RegisterStartTime = String.IsNullOrEmpty(form["regstartdate"]) ? new Nullable<DateTime>() : DateTime.Parse(String.Format("{0} {1}:{2}:{3}", form["regstartdate"], form["regstarthour"], form["regstartminute"], form["regstartsecond"])),
                RegisterEndTime = String.IsNullOrEmpty(form["regenddate"]) ? new Nullable<DateTime>() : DateTime.Parse(String.Format("{0} {1}:{2}:{3}", form["regenddate"], form["regendhour"], form["regendminute"], form["regendsecond"])),
                SupportLanguage = form["supportlangs"]
            };

            return ResultToMessagePage(ContestManager.AdminInsertContest, entity, "Your have added contest successfully!");
        }
        /// <summary>
        /// 将竞赛结果导出为Excel
        /// </summary>
        /// <param name="contest">竞赛实体</param>
        /// <param name="problems">竞赛题目</param>
        /// <param name="rank">竞赛排名信息</param>
        /// <param name="userdict">用户名姓名对照表</param>
        /// <returns>Excel文件</returns>
        public static Byte[] ExportResultToExcel(ContestEntity contest, IList<ContestProblemEntity> problems, IList<RankItem> rank, Dictionary<String, String> userdict)
        {
            MemoryStream ms = new MemoryStream();

            //相关参数
            Int32 problemCount = (problems == null ? 0 : problems.Count);
            Int32 rankCount = (rank == null ? 0 : rank.Count);

            //新建表格
            HSSFWorkbook workBook = new HSSFWorkbook();
            ISheet sheet = workBook.CreateSheet("Contest Ranklist");

            //设置样式
            ICellStyle headerStyle = workBook.CreateCellStyle();
            IFont headerFont = workBook.CreateFont();
            headerFont.FontHeightInPoints = 20;
            headerFont.Boldweight = 700;
            headerStyle.Alignment = HorizontalAlignment.Center;
            headerStyle.SetFont(headerFont);

            //设置标题行
            IRow rowTitle = sheet.CreateRow(0);
            ICell cell = rowTitle.CreateCell(0);
            cell.SetCellValue(contest.Title);
            cell.CellStyle = headerStyle;

            CellRangeAddress range = new CellRangeAddress(0, 0, 0, 4 + problemCount - 1);
            sheet.AddMergedRegion(range);

            //设置头部
            IRow rowHeader = sheet.CreateRow(1);
            rowHeader.HeightInPoints = 15;
            rowHeader.CreateCell(0).SetCellValue("Rank");
            rowHeader.CreateCell(1).SetCellValue("User Name");
            rowHeader.CreateCell(2).SetCellValue("Solved");
            rowHeader.CreateCell(3).SetCellValue("Penalty");

            sheet.SetColumnWidth(0, GetExcelWidth(5));
            sheet.SetColumnWidth(1, GetExcelWidth(27));
            sheet.SetColumnWidth(2, GetExcelWidth(7));
            sheet.SetColumnWidth(3, GetExcelWidth(10));

            for (Int32 i = 0; i < problemCount; i++)
            {
                rowHeader.CreateCell(rowHeader.Cells.Count).SetCellValue(problems[i].ContestProblemID.ToString());
                sheet.SetColumnWidth(rowHeader.Cells.Count - 1, GetExcelWidth(14));
            }

            //录入数据
            IRow rowUser = null;

            for (Int32 i = 0; i < rankCount; i++)
            {
                rowUser = sheet.CreateRow(sheet.PhysicalNumberOfRows);
                rowUser.HeightInPoints = 15;

                rowUser.CreateCell(0).SetCellValue(i + 1);
                rowUser.CreateCell(1).SetCellValue(GetShowName(rank[i].UserName, userdict));
                rowUser.CreateCell(2).SetCellValue(rank[i].SolvedCount);
                rowUser.CreateCell(3).SetCellValue(rank[i].Penalty.ToString());

                for (Int32 j = 0; j < problemCount; j++)
                {
                    rowUser.CreateCell(rowUser.Cells.Count).SetCellValue(
                        (rank[i][problems[j].ContestProblemID].Penalty != TimeSpan.Zero ? rank[i][problems[j].ContestProblemID].Penalty.ToString() : "")
                        + (rank[i][problems[j].ContestProblemID].WrongCount > 0 ? "(-" + rank[i][problems[j].ContestProblemID].WrongCount.ToString() + ")" : ""));
                }
            }

            workBook.Write(ms);
            return ms.ToArray();
        }
Example #4
0
        /// <summary>
        /// 获取竞赛排行
        /// </summary>
        /// <param name="entity">竞赛实体</param>
        /// <returns>竞赛排行</returns>
        public static List<RankItem> GetContestRanklist(ContestEntity entity)
        {
            List<RankItem> list = ContestCache.GetContestRankCache(entity.ContestID);

            if (list == null)
            {
                list = new List<RankItem>();
                Dictionary<String, RankItem> rank = SolutionRepository.Instance.GetContestRanklist(entity.ContestID, entity.StartTime);

                foreach (RankItem userRank in rank.Values)
                {
                    list.Add(userRank);
                }

                list.Sort();

                ContestCache.SetContestRankCache(entity.ContestID, list);
            }

            return list;
        }
Example #5
0
        /// <summary>
        /// 更新竞赛信息
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateContest(ContestEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return MethodResult.FailedAndLog("Contest title cannot be NULL!");
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return MethodResult.FailedAndLog("Contest description cannot be NULL!");
            }

            if (entity.StartTime >= entity.EndTime)
            {
                return MethodResult.FailedAndLog("Start time must be less than end time!");
            }

            if (entity.ContestType == ContestType.RegisterPrivate || entity.ContestType == ContestType.RegisterPublic)
            {
                if (!entity.RegisterStartTime.HasValue || !entity.RegisterEndTime.HasValue)
                {
                    return MethodResult.FailedAndLog("Register time cannot be NULL!");
                }

                if (entity.RegisterStartTime >= entity.RegisterEndTime)
                {
                    return MethodResult.FailedAndLog("Register start time must be less than register end time!");
                }

                if (entity.RegisterEndTime >= entity.StartTime)
                {
                    return MethodResult.FailedAndLog("Register end time must be less than contest start time!");
                }
            }

            entity.LastDate = DateTime.Now;

            Boolean success = ContestRepository.Instance.UpdateEntity(entity) > 0;

            if (!success)
            {
                return MethodResult.FailedAndLog("No contest was updated!");
            }

            ContestCache.RemoveContestCache(entity.ContestID);//删除缓存
            ContestCache.RemoveContestListCountCache();//删除缓存

            return MethodResult.SuccessAndLog("Admin update contest, id = {0}", entity.ContestID.ToString());
        }
Example #6
0
 /// <summary>
 /// 向缓存中写入指定竞赛信息
 /// </summary>
 /// <param name="contest">指定竞赛信息</param>
 public static void SetContestCache(ContestEntity contest)
 {
     if (contest != null) CacheManager.Set(GetContestCacheKey(contest.ContestID), contest);
 }