/// <summary> /// 读取判断题题库模板数据 /// </summary> /// <param name="adminDTO">管理员对象</param> /// <param name="courseID">课程主键ID</param> /// <param name="fileName">Excel文件路径名称</param> /// <param name="isFirstRowTitle">第一行是否为标题</param> public static List<JudgeItem> ReadJudgeTemplate(AgencyAdminDTO adminDTO, int courseID, string fileName, bool isFirstRowTitle) { List<JudgeItem> judges = new List<JudgeItem>(); // 获取所有章节 ServiceInvokeDTO<List<Chapter>> chaptersResult = ServiceFactory.Instance.ItemDataService.GetAgencyChapters(courseID); if (chaptersResult.Code == InvokeCode.SYS_INVOKE_SUCCESS && chaptersResult.Data != null && chaptersResult.Data.Count > 0) { List<Chapter> chapters = chaptersResult.Data; using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { // 默认读取第一张表 IWorkbook workBook = WorkbookFactory.Create(fs); ISheet sheet = workBook.GetSheetAt(0); int startRowIndex = 0; if (isFirstRowTitle && sheet.LastRowNum >= 1) { startRowIndex = 1; } for (int index = startRowIndex; index <= sheet.LastRowNum; index++) { IRow row = sheet.GetRow(index); if (row != null) { // 题库类型 ICell isVipItemCell = row.GetCell(0); if (isVipItemCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); } string isVipItem = isVipItemCell.ToString().Trim(); if (!isVipItem.Equals(IS_VIP_ITEM_NO) && !isVipItem.Equals(IS_VIP_ITEM_YES)) { throw new ArgumentException(IS_VIP_ITEM_ERROR); } // 所属章节 ICell chapterCell = row.GetCell(1); if (chapterCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); } string chapterName = chapterCell.ToString().Trim(); int chapterID = 0; foreach (var chapter in chapters) { if (chapterName.Equals(chapter.Name)) { chapterID = chapter.ID; break; } } if (chapterID == 0) { throw new ArgumentException(CHAPTER_ID_ERROR); } ICell titleCell = row.GetCell(2); if (titleCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); } // 答案 ICell amswerCell = row.GetCell(3); if (amswerCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); } string answerString = amswerCell.ToString().Trim().ToUpper(); if (!answerString.Equals(ANSWER_CORRECT) && !answerString.Equals(ANSWER_ERROR)) { throw new ArgumentException(ANSWER_ARG_ERROR); } // 试题难易度 ICell difficltyCell = row.GetCell(5); if (difficltyCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); } string difficltyString = difficltyCell.ToString().Trim(); int difficulty = 0; if (int.TryParse(difficltyString, out difficulty)) { if (difficulty < DIFFICULTY_MIN || difficulty > DIFFICULTY_MAX) { throw new ArgumentException(DIFFICULTY_ARG_ERROR); } } else { throw new ArgumentException(DIFFICULTY_ARG_ERROR); } JudgeItem judge = new JudgeItem(); judge.AgencyID = adminDTO.Agency.ID; judge.ChapterID = chapterID; judge.IsVipItem = isVipItem.Equals(IS_VIP_ITEM_YES) ? 1 : 0; judge.Title = titleCell.ToString(); judge.Answer = answerString.Equals(ANSWER_CORRECT) ? 1 : 0; judge.Annotation = row.GetCell(4) == null ? string.Empty : row.GetCell(4).ToString(); judge.Difficulty = difficulty; judge.AddPerson = adminDTO.ChineseName; judges.Add(judge); } } } } else { throw new ArgumentException(CHAPTER_ID_ERROR); } return judges; }
/// <summary> /// 培训机构管理员登录 /// </summary> public ServiceInvokeDTO<AgencyAdminDTO> AdminLogin(string userName, string password) { log.Debug(Constant.DEBUG_START); ServiceInvokeDTO<AgencyAdminDTO> result = null; try { AgencyAdmin dbAdmin = agencyAdminDAL.GetByAccount(userName); if (dbAdmin != null) { // 校验机构状态 Agency agency = agencyDAL.GetByID(dbAdmin.AgencyID); if (agency != null && agency.State == AgencyState.Normal) { string saltPassword = SecurityUtil.MD5(password + Constant.ADMIN_SALT_KEY); if (saltPassword.Equals(dbAdmin.Password)) { // 拼装DTO AgencyConfig config = agencyConfigDAL.GetByAgencyID(dbAdmin.AgencyID); int creatorID = agencyCreatorDAL.GetCreatorIDByAgencyID(dbAdmin.AgencyID); AgencyDTO agencyDto = new AgencyDTO(agency, config, creatorID); AgencyAdminDTO adminDTO = new AgencyAdminDTO(dbAdmin, agencyDto); result = new ServiceInvokeDTO<AgencyAdminDTO>(InvokeCode.SYS_INVOKE_SUCCESS, adminDTO); } else { result = new ServiceInvokeDTO<AgencyAdminDTO>(InvokeCode.ACCOUNT_AGENCY_ADMIN_LOGIN_ERROR); } } else { result = new ServiceInvokeDTO<AgencyAdminDTO>(InvokeCode.ACCOUNT_AGENCY_STATE_ERROR); } } else { result = new ServiceInvokeDTO<AgencyAdminDTO>(InvokeCode.ACCOUNT_AGENCY_ADMIN_LOGIN_ERROR); } } catch (Exception ex) { log.Error(ex); throw ex; } log.Debug(Constant.DEBUG_END); return result; }