You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

502 lines
19 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using VM;
namespace Web.BLL
{
/// <summary>
/// 考试Cache扩展帮助类
/// </summary>
public class ExamCacheHelper
{
/// <summary>
/// 公共试卷缓存
/// </summary>
private PaperVM cache = null;
/// <summary>
/// 个人使用试卷缓存
/// </summary>
private PaperVM cache2 = null;
public ExamCacheHelper(PaperVM cache, PaperVM cache2)
{
this.cache = cache;
this.cache2 = cache2;
}
/// <summary>
/// 获取第一个问题类型问题ID
/// </summary>
/// <returns></returns>
public KeyValue GetFirstQuestionType()
{
KeyValue model = new KeyValue();
List<PaperDetailVM> list = cache.Details.ToList();
list.ForEach(x =>
{
if (ExamCaches.QuestionCache.ContainsKey(x.QuesionId))
{
x.StructType = ExamCaches.QuestionCache[x.QuesionId].StructType;
x.StructTypeId = ExamCaches.QuestionCache[x.QuesionId].CharpterID;
}
});
var scorlist = GetTheoryQuestionType();
List<PaperDetailVM> list2 = new List<PaperDetailVM>();
string[] strAn = scorlist[0].strIdList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int an = 0; an < strAn.Length; an++)
{
list2.AddRange(list.Where(a => a.StructTypeId == Convert.ToInt32(strAn[an])).OrderBy(x => x.QuesionId).ToList());
}
list2 = list2.OrderBy(x => x.QuesionId).ToList();
int StructType = 0;
int questionId = 0;
if (list2.Count > 0)
{
StructType = list2[0].StructType;
questionId = list2[0].QuesionId;
}
model.Key = StructType;
model.Value = questionId;
return model;
}
/// <summary>
/// 获取当前问题在试卷中排第几个
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns></returns>
public int GetCurrentIndex(int questionType, int questionId)
{
int index = 0;
var model = ExamCaches.QuestionCache.Values.Where(x => x.Id == questionId).FirstOrDefault();
//获取本题在list中的位置
index = cache.Details.Where(x => x.QuesionId == questionId).Select(x => x.QuesionId).ToList().IndexOf(questionId);
return index;
}
/// <summary>
/// 返回排序后的题型最小值(及就是排在第一个单选题)
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns></returns>
public KeyValue GetCharpterIdIndex()
{
var paix = GetTheoryQuestionType();
KeyValue model = new KeyValue();
model.Key = paix[0].Id;
model.Value = paix[0].strIdList;
return model;
}
/// <summary>
/// 获取题型列表
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns></returns>
public List<TheoryQuestionTypeVM> GetTheoryQuestionType()
{
//准备存放容器
List<TheoryQuestionTypeVM> TheoryQuestionType = new List<TheoryQuestionTypeVM>();
var scorlist = cache.ScoreInfo.ToList();
for (int f = 0; f < scorlist.Count; f++)
{
List<int> QuestionType = scorlist[f].CharpterID.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(x => Convert.ToInt32(x)).ToList();
string key = scorlist[f].CharpterID;
int value = QuestionType.Min();
TheoryQuestionTypeVM type = new TheoryQuestionTypeVM();
type.Id = value;
type.strIdList = key;
if (TrainingCaches.TheoryQuestionTypeCache.ContainsKey(value))
{
type.TypeName = TrainingCaches.TheoryQuestionTypeCache[value].TypeName;
}
//题型Id
int ty = 0;
for (int a = 0; a<QuestionType.Count;a++ )
{
ty = ExamCaches.QuestionCache.Values.Where(x => x.CharpterID == QuestionType[a]).Select(x => x.StructType).FirstOrDefault();
if(ty!=0){
break;
}
}
if (ty != 5)
{
type.Sort = ty;
}
else
{
if (type.TypeName == "简答题")
{
type.Sort = 6;
}
else if (type.TypeName == "论述题")
{
type.Sort = 7;
}
else
{
type.Sort = 8;
}
}
TheoryQuestionType.Add(type);
}
//TheoryQuestionType = TheoryQuestionType.OrderBy(x => x.Id).ToList();
TheoryQuestionType = TheoryQuestionType.OrderBy(x => x.Sort).ToList();
return TheoryQuestionType;
}
/// <summary>
/// 获取题型列表下所有题目
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns></returns>
public List<PaperDetailVM> GetPaperDetail()
{
//准备存放容器
List<PaperDetailVM> list = cache.Details.ToList();
list.ForEach(x =>
{
x.StructTypeId = ExamCaches.QuestionCache.Where(a => a.Value.Id == x.QuesionId).Select(a => a.Value.CharpterID).FirstOrDefault();
});
List<PaperDetailVM> list2 = new List<PaperDetailVM>();
var questionType = GetTheoryQuestionType();
foreach (var item in questionType)
{
string[] strAn = item.strIdList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
List<PaperDetailVM> l = new List<PaperDetailVM>();
for (int an = 0; an < strAn.Length; an++)
{
l.AddRange(list.Where(a => a.StructTypeId == Convert.ToInt32(strAn[an])).OrderBy(x => x.QuesionId).ToList());
}
l = l.OrderBy(x => x.QuesionId).ToList();
list2.AddRange(l);
}
return list2;
}
/// <summary>
/// 根据当前问题位置,获取问题(问题类型问题ID)
/// </summary>
/// <param name="index">位置</param>
/// <returns>问题(问题类型问题ID)</returns>
public KeyValue GetKeyValueByIndex(int index, int PaperId, int? type, int LibraryId)
{
KeyValue model = new KeyValue();
// var papercont = ExamCaches.PaperCache.Where(x => x.Value.Id == PaperId ).FirstOrDefault();
PaperVM papercont = null;
if (LibraryId == 23)
{
//认证考试
papercont = MvcHelper.User.ExamInfo.Where(x => x.Value.Id == PaperId).Select(x => x.Value).FirstOrDefault();
}
else
{
//理论考试
papercont = ExamCaches.PaperCache.Where(x => x.Value.Id == PaperId).Select(x => x.Value).FirstOrDefault();
}
//准备数据
List<PaperDetailVM> list = papercont.Details.ToList();
list.ForEach(x =>
{
if (ExamCaches.QuestionCache.ContainsKey(x.QuesionId))
{
x.StructType = ExamCaches.QuestionCache[x.QuesionId].StructType;
x.StructTypeId = ExamCaches.QuestionCache[x.QuesionId].CharpterID;
}
});
List<PaperDetailVM> list2 = new List<PaperDetailVM>();
var charpter2 = GetTheoryQuestionType();
string strcharpter2 = null;
for (int a = 0; a < charpter2.Count; a++)
{
string[] An = charpter2[a].strIdList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int b = 0; b < An.Length; b++)
{
if (An[b] == type.ToString())
{
strcharpter2 = charpter2[a].strIdList;
break;
}
}
}
string[] strAn = strcharpter2.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int an = 0; an < strAn.Length; an++)
{
list2.AddRange(list.Where(a => a.StructTypeId == Convert.ToInt32(strAn[an])).OrderBy(x => x.QuesionId).ToList());
}
list2 = list2.OrderBy(x => x.QuesionId).ToList();
model.Key = list2[index].StructType;
model.Value = list2[index].QuesionId;
return model;
}
/// <summary>
/// 获取用户填写的答案
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns>答案</returns>
public List<int> GetUserAnswers(int questionType, int questionId)
{
int userId = MvcHelper.User.Id;
List<int> answer = null;
if (cache2.UserAnswer != null && cache2.UserAnswer.Count > 0)
{
if (questionType == (int)StructType.SelectRadio || questionType == (int)StructType.SelectCheckBox || questionType == (int)StructType.Determine)
{
var myAnswers = cache2.UserAnswer.Where(x => x.QuesionId == questionId && x.UserId == userId).Select(x => x.Answer1).ToList();
if (myAnswers != null && myAnswers.Count > 0)
{
answer = new List<int>();
foreach (var item in myAnswers)
{
if (item.HasValue)
{
answer.Add(item.Value);
}
}
}
}
}
return answer;
}
/// <summary>
/// 获取用户填写的答案
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns>答案</returns>
public List<string> GetUserAnswers2(int questionType, int questionId)
{
int userId = MvcHelper.User.Id;
List<string> answer = null;
if (cache2.UserAnswer != null && cache2.UserAnswer.Count > 0)
{
answer = cache2.UserAnswer.Where(x => x.QuesionId == questionId && x.UserId == userId).Select(x => x.Answer2).ToList();
}
return answer;
}
/// <summary>
/// 获取用户填写的答案
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns>答案</returns>
public List<string> GetUserAnswers3(int questionType, int questionId)
{
int userId = MvcHelper.User.Id;
List<string> answer = null;
if (cache2.UserAnswer != null && cache2.UserAnswer.Count > 0)
{
answer = cache2.UserAnswer.Where(x => x.QuesionId == questionId && x.UserId == userId).Select(x => x.Answer3).ToList();
}
return answer;
}
/// <summary>
/// 获取问题标记
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns>是否被标记</returns>
public bool GetIsMark(int questionType, int questionId)
{
var bo = false;
if (cache2.UserAnswerResult != null && cache2.UserAnswerResult.Count > 0)
{
var model = cache2.UserAnswerResult.Where(x => x.QuesionId == questionId && x.UserId == MvcHelper.User.Id).FirstOrDefault();
if (model != null)
{
bo = model.IsMark;
}
}
return bo;
}
/// <summary>
/// 获取展示信息
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns>展示信息</returns>
public string GetInfoShow(int questionType, int questionId, int PaperId)
{
StringBuilder sb = new StringBuilder();
//准备存放容器
List<PaperDetailVM> list = cache.Details.ToList();
list.ForEach(x =>
{
if (ExamCaches.QuestionCache.ContainsKey(x.QuesionId))
{
x.StructTypeId = ExamCaches.QuestionCache[x.QuesionId].CharpterID;
}
});
List<PaperDetailVM> list2 = new List<PaperDetailVM>();
var qType = GetTheoryQuestionType();
string[] qTypes = null;
for (int ag = 0; ag < qType.Count; ag++)
{
string[] strAn2 = qType[ag].strIdList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int g = 0; g < strAn2.Length; g++)
{
if (strAn2[g] == questionType.ToString())
{
qTypes = qType[ag].strIdList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
}
}
}
foreach (var item in qTypes)
{
string[] strAn = item.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
List<PaperDetailVM> l = new List<PaperDetailVM>();
for (int an = 0; an < strAn.Length; an++)
{
l.AddRange(list.Where(a => a.StructTypeId == Convert.ToInt32(strAn[an])).OrderBy(x => x.QuesionId).ToList());
}
list2.AddRange(l);
}
list2 = list2.OrderBy(x => x.QuesionId).ToList();
var qId = cache.Details.First(x => x.QuesionId == questionId);
var typeName = TrainingCaches.TheoryQuestionTypeCache.Where(x => x.Value.Id == questionType).Select(x => x.Value.TypeName).FirstOrDefault();
var Score = cache.ScoreInfo.Where(x => x.CharpterID.Contains(questionType.ToString())).FirstOrDefault();
decimal RadioScore = Score.Score;
sb.Append(typeName);
sb.Append("(共").Append(list2.Count).Append("题,");
sb.Append("每题").Append(RadioScore.ToString("0.0")).Append("分,");
sb.Append("共").Append((list2.Count * RadioScore).ToString("0.0")).Append("分)");
sb.Append(", 当前为第<strong>").Append(list2.IndexOf(qId) + 1).Append("</strong>题");
return sb.ToString();
}
/// <summary>
/// 获取主题干
/// </summary>
/// <param name="questionType">问题类型</param>
/// <param name="questionId">问题ID</param>
/// <returns>主题干</returns>
public string GetTopic(int questionType, int questionId, int PaperId)
{
//准备数据
List<PaperDetailVM> list = cache.Details.Where(x => x.ExamPaperId == PaperId).Distinct().ToList();
list.ForEach(x =>
{
if (ExamCaches.QuestionCache.ContainsKey(x.QuesionId))
{
x.StructTypeId = ExamCaches.QuestionCache[x.QuesionId].CharpterID;
}
});
StringBuilder sb = new StringBuilder();
var charpter = GetTheoryQuestionType();
List<int> strcharpter = null;
for (int a = 0; a < charpter.Count; a++)
{
string[] An = charpter[a].strIdList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int b = 0; b < An.Length; b++)
{
if (An[b] == questionType.ToString())
{
strcharpter = charpter[a].strIdList.Split(',').ToList().ConvertAll<int>(y => int.Parse(y));
}
}
}
//准备数据
list = list.Where(a => strcharpter.Contains(a.StructTypeId)).ToList();
var qId = cache.Details.First(x => x.QuesionId == questionId);
var mo1 = ExamCaches.QuestionCache.Where(x => x.Value.Id == questionId).FirstOrDefault();
var typeName = TrainingCaches.TheoryQuestionTypeCache.Where(x => x.Value.Id == questionType).Select(x => x.Value.TypeName).FirstOrDefault();
//拼接
sb.Append(" <div style='margin-left:35px;'><div style='font-size:16px;float:left;height:80px;'>" + typeName + "&nbsp;" + (list.IndexOf(qId) + 1) + "&nbsp;:&nbsp;</div><div style='margin-left:5px;'>&nbsp;" + mo1.Value.Context + " </div></div>");
return sb.ToString();
}
/// <summary>
/// 获取选项
/// </summary>
/// <param name="questionId"></param>
/// <returns></returns>
public List<QuestionOptionVM> OptionList(int questionId)
{
List<QuestionOptionVM> option = new List<QuestionOptionVM>();
var detail = ExamCaches.QuestionCache.Where(x => x.Value.Id == questionId).FirstOrDefault();
option = detail.Value.OptionList;
return option;
}
/// <summary>
/// 获取附件
/// </summary>
/// <param name="questionId"></param>
/// <returns></returns>
public List<QuestionAttachmentsVM> Attachments(int questionId)
{
List<QuestionAttachmentsVM> option = new List<QuestionAttachmentsVM>();
var detail = ExamCaches.QuestionCache.Where(x => x.Value.Id == questionId).FirstOrDefault();
if (detail.Value.AttachmentList != null)
{
option = detail.Value.AttachmentList;
}
return option;
}
}
}