/// <summary> /// 将xls转为题目列表 /// </summary> public static List <FP_Exam_ExamQuestion> GetQuestionsFromXls(string filepath, int uid) { DataTable dt = ExcelHelp.InputFromExcel(filepath, "sheet1"); List <FP_Exam_ExamQuestion> result = new List <FP_Exam_ExamQuestion>(); foreach (DataRow row in dt.Rows) { FP_Exam_ExamQuestion question = new FP_Exam_ExamQuestion(); question.kid = Guid.NewGuid().ToString(); question.parentid = ""; question.uid = uid; question.channelid = 0; question.sortid = 0; question.typelist = ""; question.type = row["type"].ToString(); question.display = 1; question.title = row["title"].ToString(); string content = ""; int optionSum = 0; foreach (string option in ExcelHelp.optionList) { if (row[option].ToString() != "") { content += row[option].ToString() + specialSym; optionSum++; } } if (optionSum == 0) { continue; } content = content.Substring(0, content.Length - 1); question.content = content; question.answer = row["answer"].ToString(); question.upperflg = 0; question.orderflg = 0; question.answerkey = row["answerkey"].ToString(); question.ascount = optionSum; question.explain = row["explain"].ToString(); int difficulty = 0; try { difficulty = int.Parse(row["difficulty"].ToString()); } catch (Exception) { difficulty = -1; } question.difficulty = difficulty; question.postdatetime = DateTime.Now; question.attachid = FPRandom.CreateCode(20); question.exams = 0; question.wrongs = 0; question.status = 1; result.Add(question); } return(result); }
/// <summary> /// 创建examresult和examresultopic /// </summary> /// <param name="userid"></param> /// <param name="examInfo"></param> /// <returns></returns> public static int CreateExam(int userid, FP_Exam_ExamInfo examInfo) { Dictionary <int, List <string> > question_strs = CreateQuestion(examInfo.id); if (question_strs == null) { return(-2); } if (question_strs.Count() == 0) { return(-1); } //创建新的examresult对象 FP_Exam_ExamResult new_exam = new FP_Exam_ExamResult(); new_exam.uid = userid; new_exam.channelid = examInfo.channelid; new_exam.sortid = examInfo.sortid; new_exam.departid = null; new_exam.examid = examInfo.id; new_exam.examname = examInfo.name; new_exam.examtime = examInfo.examtime; new_exam.examtype = examInfo.examtype; new_exam.showanswer = 1; new_exam.allowdelete = 0; new_exam.total = examInfo.total; new_exam.passmark = examInfo.passmark; new_exam.score1 = 0; new_exam.score2 = 0; new_exam.score = 0; new_exam.utime = 0; new_exam.islimit = 0; new_exam.starttime = DateTime.Now; new_exam.endtime = new_exam.starttime.Value.AddMinutes(examInfo.examtime.Value); new_exam.examdatetime = new_exam.starttime; new_exam.credits = 0; int question_sum = 0; foreach (int key in question_strs.Keys) { question_sum += question_strs[key].Count(); } new_exam.questions = question_sum; new_exam.wrongs = 0; new_exam.unanswer = 0; new_exam.exp = 0; new_exam.getcredits = 0; new_exam.exnote = ""; new_exam.attachid = FPRandom.CreateCode(30); new_exam.status = 0; new_exam.paper = 1; new_exam.ip = GetLocalIP(); new_exam.mac = "00-00-00-00-00-00"; new_exam.isvideo = 0; new_exam.client = "mobile"; new_exam.papertype = 0; new_exam.title = examInfo.name; new_exam.address = ""; db.FP_Exam_ExamResult.Add(new_exam); db.SaveChanges(); //创建新的examresultopic对象 List <FP_Exam_ExamTopic> examtopics = db.FP_Exam_ExamTopic.Where(t => t.examid == new_exam.examid).ToList(); for (int i = 0; i < examtopics.Count(); i++) { FP_Exam_ExamResultTopic new_examresultopic = new FP_Exam_ExamResultTopic(); new_examresultopic.resultid = new_exam.id; new_examresultopic.type = examtopics[i].type; new_examresultopic.title = examtopics[i].title; new_examresultopic.display = examtopics[i].display; new_examresultopic.perscore = examtopics[i].perscore; new_examresultopic.score = 0; new_examresultopic.questions = examtopics[i].questions; new_examresultopic.wrongs = 0; List <string> questionlist = question_strs[examtopics[i].id]; string questionlist_str = ""; for (int j = 0; j < questionlist.Count(); j++) { questionlist_str += questionlist[j]; if (j < (questionlist.Count() - 1)) { questionlist_str += ","; } } new_examresultopic.questionlist = questionlist_str; new_examresultopic.answerlist = ""; new_examresultopic.scorelist = ""; new_examresultopic.correctlist = ""; new_examresultopic.paper = null; db.FP_Exam_ExamResultTopic.Add(new_examresultopic); } db.SaveChanges(); return(new_exam.id); }
/// <summary> /// 添加题库 /// </summary> /// <param name="questionres"></param> public static int AddQuestionRes(QuestionResModel request) { try { var channalInfo = db.FP_WMS_ChannelInfo.SingleOrDefault(t => t.id == request.channalid); FP_WMS_SortInfo sortinfo = new FP_WMS_SortInfo(); sortinfo.channelid = request.channalid; sortinfo.appid = int.Parse(channalInfo.sortapps); sortinfo.display = request.display; sortinfo.parentid = request.parentid; List <int> parents = new List <int>(); int cnd = request.parentid; while (cnd != 0) { parents.Add(cnd); cnd = db.FP_WMS_SortInfo.SingleOrDefault(t => t.id == cnd).parentid.Value; } parents.Add(cnd); string parentlist = ""; for (int i = 0; i < parents.Count(); i++) { parentlist += parents[parents.Count() - i - 1]; if (i < (parents.Count() - 1)) { parentlist += ","; } } sortinfo.parentlist = parentlist; sortinfo.name = request.name; sortinfo.markup = request.markup; sortinfo.pagesize = request.pagesize; sortinfo.description = request.description; sortinfo.icon = ""; sortinfo.attach_icon = ""; sortinfo.img = ""; sortinfo.attach_img = FPRandom.CreateCode(20); sortinfo.subcounts = 0; sortinfo.types = ""; sortinfo.showtype = request.showtype; sortinfo.otherurl = ""; sortinfo.posts = 0; db.FP_WMS_SortInfo.Add(sortinfo); db.SaveChanges(); sortinfo.parentlist += "," + sortinfo.id; db.SaveChanges(); foreach (QuestionType qt in Enum.GetValues(typeof(QuestionType))) { FP_Exam_SortQuestion sortQuestion = new FP_Exam_SortQuestion(); sortQuestion.channelid = sortinfo.channelid; sortQuestion.sortid = sortinfo.id; sortQuestion.type = qt.ToString(); sortQuestion.typeid = 0; sortQuestion.counts = 0; sortQuestion.questionlist = ""; db.FP_Exam_SortQuestion.Add(sortQuestion); db.SaveChanges(); } return(1); } catch (Exception) { return(0); } }