public JsonResult GetCourseList(int categoryId = 0, string courseCode = "", string courseName = "", decimal priceStart = 0, decimal priceEnd = 0, int courseType = 99, string jsRenderSortField = "CourseId DESC", int pageSize = 20, int pageIndex = 1) { SearchCondtion["course/categoryId"] = categoryId.ToString(CultureInfo.InvariantCulture); SearchCondtion["course/courseCode"] = courseCode; SearchCondtion["course/courseName"] = courseName; SearchCondtion["course/priceStart"] = priceStart.ToString(CultureInfo.InvariantCulture); SearchCondtion["course/priceEnd"] = priceEnd.ToString(CultureInfo.InvariantCulture); SearchCondtion["course/pageSize"] = pageSize.ToString(CultureInfo.InvariantCulture); SearchCondtion["course/pageIndex"] = pageIndex.ToString(CultureInfo.InvariantCulture); int total; IEnumerable <CourseList> list = _courseManager.GetCourseList(out total, CurrentTenant.TenantId, categoryId, courseCode, courseName, priceStart, priceEnd, courseType, pageIndex, pageSize, jsRenderSortField); var dataList = list.Select(p => new { p.CourseId, p.CourseCode, p.CourseName, p.Price, CourseType = EnumsLanguage.GetString(((Enums.CourseType)p.CourseType).ToString()), LevelDesc = string.IsNullOrEmpty(p.LevelDesc) ? CurrentTenant.TenantName : p.LevelDesc }); return(Json(new { dataList, recordCount = total }, 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 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, DataSet ds, 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(CurrentTenant.TenantId); foreach (DataRow dr in ds.Tables[0].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, AnswerType = question.QuestionType == 1 ? 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() != "") { try { 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>(), TenantId = CurrentTenant.TenantId }; questionList.Add(question); rowList.Add(rowCount + 1); } catch { message += message == "" ? (rowCount + 1).ToString() : ("、" + (rowCount + 1).ToString()); } } else { message += message == "" ? (rowCount + 1).ToString() : ("、" + (rowCount + 1).ToString()); } } } } int quCount = 0; foreach (tbQuestion qu in questionList) { qu.QuestionOpen = 1; 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.Count(p => p.AnswerFlag == 1) == 1) //单选 || (qu.QuestionType == 3 && qu.QuestionAnswer.Count > 1 && qu.QuestionAnswer.Count < 27 && qu.QuestionAnswer.Any(p => p.AnswerFlag == 1)) //多选 || (qu.QuestionType == 4 && qu.QuestionAnswer.Count == 2 && qu.QuestionAnswer.Count(p => p.AnswerFlag == 1) == 1) //判断 ) { int c = 0; qu.QuestionAnswer.ForEach(pz => { pz.Order = ++c; }); if (qu.QuestionType == 4) { qu.QuestionAnswer = qu.QuestionAnswer.FindAll(p => p.AnswerFlag == 1); } 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 = EnumsLanguage.GetString(((QuestionLevel)qu.QuestionLevel).ToString()); newQu.QuestionTypeStr = EnumsLanguage.GetString(((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 = EnumsLanguage.GetString(((QuestionLevel)qu.QuestionLevel).ToString()); newQu.QuestionTypeStr = EnumsLanguage.GetString(((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)); }