public ActionResult BrowseQuestion() { Response.Expires = 0; string ids = Request.QueryString["ids"]; //基础信息 List <tbQuestion> baseInfor = EQuestionBL.GetQuestionList(ids.Substring(1, ids.Length - 2)); //知识点分类字典 Dictionary <int, tbKnowledgeKey> konwDic = KnowBL.GetAllQuestionSortDictionary(); var listQuestion = new List <MQuestionShow>(); foreach (tbQuestion item in baseInfor) { var mq = new MQuestionShow { QuestionContent = item.QuestionContent, QuestionKey = konwDic[item.QuestionKey].KeyName, QuestionType = item.QuestionType, QuestionTypeStr = ((QuestionType)item.QuestionType).ToString(), QuestionAnswerKeys = item.QuestionAnswerKeys, QuestionAnalysis = item.QuestionAnalysis, QuestionAnswer = item.QuestionAnswer, FileUpload = (item.FileUpload == null || item.FileUpload.Count == 0) ? new List <FileUpload>() : item.FileUpload }; listQuestion.Add(mq); } // ViewData["model"] = listQuestion; ViewBag.model = listQuestion; return(View()); }
public JsonResult GetAllQuestion(int pageSize = 10, int pageIndex = 1) { int sortID = Convert.ToInt32(Request.QueryString["sortID"]); int qType = Request.QueryString["type"].StringToInt32(); int qlevel = Request.QueryString["level"].StringToInt32(); string qKey = Request.QueryString["key"]; string qContent = Request.QueryString["content"]; //要补全 int totalCount = 0; //获取所有的试题 List <tbQuestion> qList = EQuestionBL.GetListByQuery(ref totalCount, sortID, "", qKey, int.MaxValue, 1, qType, qlevel); qList = qList.Where(p => HttpUtility.HtmlDecode(p.QuestionContent).NoHtml().Contains(qContent)).ToList(); totalCount = qList.Count; qList = qList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); //获取所有的人员信息 List <Sys_User> userList = UserBL.GetList("1=1"); //获取所有试卷 List <tbExampaper> paperlist = PaperBL.GetAllExampaperList(); //知识点分类字典 Dictionary <int, tbKnowledgeKey> konwDic = KnowBL.GetAllQuestionSortDictionary(); var ListQuestion = new List <MQuestionShow>(); foreach (tbQuestion item in qList) { //调用次数 int count = 0; paperlist.ForEach(p => { if (p.QuestionList.Count(subp => subp.Qid == item._id) > 0) { count++; } }); var Question = new MQuestionShow(); Question.id = item._id; Question.QuestionContent = item.QuestionContent.NoHtml(); Question.QuestionTypeStr = ((QuestionType)item.QuestionType).ToString(); Question.QuestionLevelStr = ((QuestionLevel)item.QuestionLevel).ToString(); Question.QuestionKey = konwDic.Keys.Contains(item.QuestionKey) ? konwDic[item.QuestionKey].KeyName : ""; Question.VoidTimes = count; Question.Creater = (userList.Count == 0 || item.UserID == 0 || userList.All(p => p.UserId != item.UserID)) ? "管理员" : userList.FirstOrDefault(p => p.UserId == item.UserID).Realname; Question.CreatLocalTime = item.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); ListQuestion.Add(Question); } return(Json(new { dataList = ListQuestion, recordCount = totalCount }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 用于选择试题 /// </summary> /// <returns></returns> public JsonResult GetSelectQuestion(int sortID, int type, int level, string content, int pageSize = 10, int pageIndex = 1) { string OrderByCreateTime = "desc"; //发布时间排序规则 int total = 0; //获取所有的试题 List <tbQuestion> qList = EQuestionBL.GetListByQuery(ref total, CurrentTenant.TenantId, sortID, "", int.MaxValue, 0, type, level, null, null, 99, 0, null); qList = qList.Where(p => ((p.UserID == CurrentUser.UserId) || (p.UserID != CurrentUser.UserId && p.QuestionOpen == 0)) && p.QuestionAvailable == 0).ToList(); if (OrderByCreateTime == "asc") { qList = qList.OrderBy(q => q.CreateTime).ToList(); } else { qList = qList.OrderByDescending(q => q.CreateTime).ToList(); } qList = qList.Where(p => p.QuestionContent.NoHtml().HtmlDecode().ToLower().Contains(content.ToLower())).ToList(); total = qList.Count; qList = qList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); //获取所有分类 List <tbQuestionSort> sortlist = ESortBL.GetAllQuestionSortList(CurrentTenant.TenantId); //获取所有试卷 List <tbExampaper> paperlist = PaperBL.GetAllExampaperList(CurrentTenant.TenantId); //根据公司ID获取所有考试 List <tbExamination> examinationsList = ExaminationBL.GetAllExaminationByTenantId(CurrentTenant.TenantId); var ListQuestion = new List <MQuestionShow>(); foreach (tbQuestion item in qList) { var Question = new MQuestionShow(); Question.id = item._id; Question.QuestionContent = item.QuestionContent.NoHtml().HtmlDecode(); Question.QuestionTypeStr = EnumsLanguage.GetString(((QuestionType)item.QuestionType).ToString()); Question.QuestionLevelStr = EnumsLanguage.GetString(((QuestionLevel)item.QuestionLevel).ToString()); Question.QuestionAvailableStr = EnumsLanguage.GetString(((QuestionAvailable)item.QuestionAvailable).ToString()); Question.QuestionOpenStr = EnumsLanguage.GetString(((QuestionOpen)item.QuestionOpen).ToString()); Question.QuestionKey = ""; Question.CreatLocalTime = item.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); Question.LastUpdateTimeStr = item.LastUpdateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); //Question.SortName = (sortlist.Count() == 0 || item.QuestionSortID == 0 || sortlist.All(p => p._id != item.QuestionSortID)) ? "无" : sortlist.FirstOrDefault(p => p._id == item.QuestionSortID).Title; Question.SortName = (sortlist.Count() == 0 || item.QuestionSortID == 0 || sortlist.All(p => p._id != item.QuestionSortID)) ? "无" : sortlist.FirstOrDefault(p => p._id == item.QuestionSortID).LevelPath; ListQuestion.Add(Question); } return(Json(new { dataList = ListQuestion, recordCount = total }, JsonRequestBehavior.AllowGet)); }
//试题 public ActionResult QuestionManager() { int total = 0; var questionlist = new QuestionManager().GetListByQuery(ref total, CurrentTenant.TenantId, 0, "", 5, 1, 0, 0, null, null, 99, 99); var sortList = new QuestionSortManager().GetAllQuestionSortDictionary(CurrentTenant.TenantId); var dataList = new List <MQuestionShow>(); foreach (var item in questionlist) { var question = new MQuestionShow(); question.id = item._id; question.QuestionContent = item.QuestionContent.NoHtml().HtmlDecode(); question.CreatLocalTime = item.CreateTime.ToLocalTime().ToString("yyyy-MM-dd"); question.SortName = sortList[item.QuestionSortID].LevelPath; dataList.Add(question); } ViewBag.total = total; return(View(dataList)); }
public ActionResult BrowseQuestion(int flag = 0) { Response.Expires = 0; string ids = Request.QueryString["ids"]; //基础信息 List <tbQuestion> baseInfor = EQuestionBL.GetQuestionList(ids.Substring(1, ids.Length - 2).GetArray()); var listQuestion = new List <MQuestionShow>(); foreach (tbQuestion item in baseInfor) { var mq = new MQuestionShow { QuestionContent = item.QuestionContent.NoHtml(), //QuestionKey = konwDic[item.QuestionKey].KeyName, QuestionType = item.QuestionType, QuestionTypeStr = EnumsLanguage.GetString(((QuestionType)item.QuestionType).ToString()), QuestionAnswerKeys = item.QuestionAnswerKeys, QuestionAnalysis = item.QuestionAnalysis, QuestionAnswer = item.QuestionAnswer, FileUpload = (item.FileUpload == null || item.FileUpload.Count == 0) ? new List <FileUpload>() : item.FileUpload }; listQuestion.Add(mq); } // ViewData["model"] = listQuestion; ViewBag.model = listQuestion; ViewBag.backUrl = Url.RetechAction("QuestionList", "Question"); if (flag == 1) { ViewBag.backUrl = Url.RetechAction("QuestionManage", "Question"); } return(View()); }
/// <summary> /// 导入试题 /// </summary> /// <param name="sortID">分类ID</param> /// <param name="ds">试题DataSet</param> /// <param name="message">错误信息</param> /// <param name="count">错误数目</param> /// <param name="totalCount">导入的总题数</param> /// <returns></returns> public List <MQuestionShow> ImportQuestion(int sortID, int key, DataTable dt, ref string message, ref int count, ref int totalCount) { var newlist = new List <MQuestionShow>(); var questionList = new List <tbQuestion>(); var question = new tbQuestion(); var rowList = new List <int>(); int rowCount = 0; //记录行号 Dictionary <int, tbQuestionSort> dicsort = ESortBL.GetAllQuestionSortDictionary(); foreach (DataRow dr in dt.Rows) { rowCount++; //如果是空行跳过 //if (dr[1].ToString() == "") //{ // message += message == "" ? (rowCount + 1).ToString() : ("、" + (rowCount + 1).ToString()); // continue; //} //为空的时候是答案 if (dr[3].ToString() == string.Empty && dr[1].ToString() != "") { if (question.QuestionType > 0) { questionList[questionList.Count - 1].QuestionAnswer.Add(new QuestionAnswer { Answer = (question.QuestionType == 4 ? (dr[1].ToString() == "正确" ? "0" : "1") : dr[1].ToString().Trim()), AnswerFlag = dr[2].ToString() == "是" ? 1 : 0, }); } } //保存试题,初始化model else { if ((dr[3].ToString() == "问答题" || dr[3].ToString() == "填空题") && dr[6].ToString() == "") { message += message == "" ? (rowCount + 1).ToString() : ("、" + (rowCount + 1).ToString()); } else { if (dr[1].ToString() != "" && dr[3].ToString() != "" && dr[4].ToString() != "") { question = new tbQuestion { QuestionAnswer = new List <QuestionAnswer>(), QuestionKey = key, QuestionAnswerKeys = dr[6].ToString(), QuestionAnalysis = dr[5].ToString(), QuestionContent = dr[1].ToString() .Replace("(", "(") .Replace("(", "(") .Replace("(", "(") .Replace(")", ")") .Replace(")", ")") .Replace(")", ")"), QuestionLevel = (int)((QuestionLevel)Enum.Parse(typeof(QuestionLevel), dr[4].ToString())), QuestionType = (int)((QuestionType)Enum.Parse(typeof(QuestionType), dr[3].ToString())), Status = 0, LastUpdateTime = DateTime.Now, CreateTime = DateTime.Now, QuestionSortID = sortID, UserID = CurrentUser.UserId, FileUpload = new List <FileUpload>(), }; questionList.Add(question); rowList.Add(rowCount + 1); } else { message += message == "" ? (rowCount + 1).ToString() : ("、" + (rowCount + 1).ToString()); } } } } int quCount = 0; foreach (tbQuestion qu in questionList) { quCount++; int qID = 0; if ((qu.QuestionType == 1 && qu.QuestionAnswer.Count == 1) //问答 || (qu.QuestionType == 2 && qu.QuestionAnswer.Count > 1 && qu.QuestionAnswer.Count < 27 && qu.QuestionAnswer.Where(p => p.AnswerFlag == 1).Count() == 1) //单选 || (qu.QuestionType == 3 && qu.QuestionAnswer.Count > 1 && qu.QuestionAnswer.Count < 27 && qu.QuestionAnswer.Where(p => p.AnswerFlag == 1).Count() > 0) //多选 || (qu.QuestionType == 4 && qu.QuestionAnswer.Count == 2 && qu.QuestionAnswer.Where(p => p.AnswerFlag == 1).Count() == 1) //判断 ) { int c = 0; qu.QuestionAnswer.ForEach(pz => { pz.Order = ++c; }); qID = EQuestionBL.Insert(qu); var newQu = new MQuestionShow(); newQu.FileUpload = new List <FileUpload>(); newQu.QuestionAnswer = qu.QuestionAnswer; newQu.QuestionContent = qu.QuestionContent; newQu.id = qu._id; newQu.QuestionLevelStr = ((QuestionLevel)qu.QuestionLevel).ToString(); newQu.QuestionTypeStr = ((QuestionType)qu.QuestionType).ToString(); newQu.QuestionType = qu.QuestionType; newQu.QuestionLevel = qu.QuestionLevel; newQu.SortName = dicsort[sortID].Title; newlist.Add(newQu); } else if (qu.QuestionType == 5) { //判断()的个数和答案数是否一致, var answerNumber = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Length - 1; if (qu.QuestionAnswer.Count == answerNumber) { //关键词的个数是否一样 if (qu.QuestionAnswerKeys.Split(' ').Length == answerNumber) { string anStr = ""; qu.QuestionAnswer.ForEach(p => { anStr += anStr == "" ? p.Answer : ("!!%%!!" + p.Answer); }); var answer = new QuestionAnswer { Answer = anStr, AnswerFlag = qu.QuestionAnswer[0].AnswerFlag }; var list = new List <QuestionAnswer>(); list.Add(answer); qu.QuestionAnswer = list; qID = EQuestionBL.Insert(qu); var newQu = new MQuestionShow(); newQu.FileUpload = new List <FileUpload>(); newQu.QuestionAnswer = qu.QuestionAnswer; newQu.QuestionContent = qu.QuestionContent; newQu.id = qu._id; newQu.QuestionLevelStr = ((QuestionLevel)qu.QuestionLevel).ToString(); newQu.QuestionTypeStr = ((QuestionType)qu.QuestionType).ToString(); newQu.QuestionType = qu.QuestionType; newQu.QuestionLevel = qu.QuestionLevel; newQu.SortName = dicsort[sortID].Title; newQu.Creater = CurrentUser.Realname; newlist.Add(newQu); } else { count++; message += message == "" ? ((rowList[quCount - 1]).ToString()) : ("、" + (rowList[quCount - 1]).ToString()); } } else { count++; message += message == "" ? ((rowList[quCount - 1] + 1).ToString()) : ("、" + (rowList[quCount - 1] + 1).ToString()); } } else { count++; message += message == "" ? ((rowList[quCount - 1] + 1).ToString()) : ("、" + (rowList[quCount - 1] + 1).ToString()); } totalCount++; } return(newlist); }
public JsonResult GetAllQuestion(int sortId, int type, int level, string content, DateTime?start, DateTime?end, int open = 99, int available = 99, string creater = "", int showMy = 99, int pageSize = 10, int pageIndex = 1) { SearchCondtion["QuestionList/sortId"] = sortId.ToString(); SearchCondtion["QuestionList/type"] = type.ToString(); SearchCondtion["QuestionList/level"] = level.ToString(); SearchCondtion["QuestionList/content"] = content; SearchCondtion["QuestionList/start"] = start.ToString(); SearchCondtion["QuestionList/end"] = end.ToString(); SearchCondtion["QuestionList/open"] = open.ToString(); SearchCondtion["QuestionList/available"] = available.ToString(); SearchCondtion["QuestionList/creater"] = creater; SearchCondtion["QuestionList/showMy"] = showMy.ToString(); SearchCondtion["QuestionList/pageSize"] = pageSize.ToString(); SearchCondtion["QuestionList/pageIndex"] = pageIndex.ToString(); string OrderByCreateTime = "desc"; //发布时间排序规则 int total = 0; //获取所有的人员信息 string userWhere = string.Format(" Sys_Users.Status = 0 and Sys_Users.TenantId = {0} and Sys_Users.Realname LIKE '%{1}%'", CurrentTenant.TenantId, creater.ReplaceSql()); var userList = UserBL.GetAllUsers(out total, userWhere, 0, int.MaxValue); int[] userIds; if (showMy == 99) { userIds = userList.Select(p => p.UserId).Distinct().ToArray(); } else if (showMy == 0) { userIds = new int[1] { CurrentUser.UserId } } ; else { userIds = userList.Where(p => p.UserId != CurrentUser.UserId).Select(p => p.UserId).Distinct().ToArray(); } //获取所有的试题 List <tbQuestion> qList = new List <tbQuestion>(); if (userIds.Length > 0) { qList = EQuestionBL.GetListByQuery(ref total, CurrentTenant.TenantId, sortId, "", int.MaxValue, 1, type, level, start, end, open, available, userIds); } if (OrderByCreateTime == "asc") { qList = qList.OrderBy(q => q.CreateTime).ToList(); } else { qList = qList.OrderByDescending(q => q.CreateTime).ToList(); } qList = qList.Where(p => (p.QuestionContent.NoHtml().HtmlDecode().ToLower()).Contains(content.ToLower())).ToList(); total = qList.Count; qList = qList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); //获取所有分类 List <tbQuestionSort> sortlist = ESortBL.GetAllQuestionSortList(CurrentTenant.TenantId); //获取所有试卷 List <tbExampaper> paperlist = PaperBL.GetAllExampaperList(CurrentTenant.TenantId); //根据公司ID获取所有考试 List <tbExamination> examinationsList = ExaminationBL.GetAllExaminationByTenantId(CurrentTenant.TenantId); var ListQuestion = new List <MQuestionShow>(); foreach (tbQuestion item in qList) { var Question = new MQuestionShow(); Question.id = item._id; Question.QuestionContent = item.QuestionContent.NoHtml().HtmlDecode(); Question.QuestionTypeStr = EnumsLanguage.GetString(((QuestionType)item.QuestionType).ToString()); Question.QuestionLevelStr = EnumsLanguage.GetString(((QuestionLevel)item.QuestionLevel).ToString()); Question.QuestionAvailableStr = EnumsLanguage.GetString(((QuestionAvailable)item.QuestionAvailable).ToString()); Question.QuestionOpenStr = EnumsLanguage.GetString(((QuestionOpen)item.QuestionOpen).ToString()); Question.QuestionKey = ""; //Question.VoidTimes = count; Question.Creater = (userList.Count() == 0 || item.UserID == 0 || userList.All(p => p.UserId != item.UserID)) ? "无" : userList.FirstOrDefault(p => p.UserId == item.UserID).Realname; Question.CreatLocalTime = item.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); Question.LastUpdateTimeStr = item.LastUpdateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); //Question.SortName = (sortlist.Count() == 0 || item.QuestionSortID == 0 || sortlist.All(p => p._id != item.QuestionSortID)) ? "无" : sortlist.FirstOrDefault(p => p._id == item.QuestionSortID).Title; Question.SortName = (sortlist.Count() == 0 || item.QuestionSortID == 0 || sortlist.All(p => p._id != item.QuestionSortID)) ? "无" : sortlist.FirstOrDefault(p => p._id == item.QuestionSortID).LevelPath; //Question.ExaminationCount = examinationCount; ListQuestion.Add(Question); } return(Json(new { dataList = ListQuestion, recordCount = total }, JsonRequestBehavior.AllowGet)); }