/// <summary> /// 插入试题信息 /// </summary> /// <param name="s">试题实体</param> public static int InsertQuestion(QuestionInfo s) { ExamDbDataContext dc = DataAccess.CreateDBContext(); dc.QuestionInfo.InsertOnSubmit(s); dc.SubmitChanges(); // PurgeCacheItems("AllSubjects_" + s.DepartmentID.ToString()); return s.QuestionID; }
public static bool InsertQuestionsByExcleFile(string filePath) { ExamDbDataContext dc = DataAccess.CreateDBContext(); string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""; if (filePath.EndsWith("xlsx")) strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\""; OleDbConnection myConn = new OleDbConnection(strConn); string strCom = " SELECT * FROM [Sheet1$]"; OleDbCommand cmd = new OleDbCommand(strCom, myConn); OleDbDataReader dr = null; IList<QuestionInfo> questions = new List<QuestionInfo>(); IList<ChoiceItemInfo> choiceitems = new List<ChoiceItemInfo>(); try { myConn.Open(); dr = cmd.ExecuteReader(); while (dr.Read())//在此处逐条输入试题信息 { string questionTypeName = dr["题型"].ToString(); if (string.IsNullOrEmpty(questionTypeName)) continue; QuestionInfo q = new QuestionInfo(); q.Title=dr["题目内容"].ToString(); q.RefAnswer=dr["参考答案"].ToString(); string sAnswers = ""; switch (questionTypeName) { case "选择": SelectChoiceInfo s = new SelectChoiceInfo(); s.Title = dr["题目内容"].ToString(); sAnswers = dr["参考答案"].ToString(); if (sAnswers.Length == 1) s.IsSingleSelect = true; else s.IsSingleSelect = false; s.ChoiceCount = 4; s.CourseID = BLLBase.ReturnID(BLLBase.GetCourseDic(), dr["课程"].ToString()); s.ChapterID = BLLBase.ReturnID(BLLBase.GetChapterDic(), dr["章节"].ToString()); int choiceID= Choice.InsertSelectChoice(s); string[] choiceNames = { "A", "B", "C", "D" }; for (int i = 0; i < 4; i++) { string m= choiceNames[i]; ChoiceItemInfo c = new ChoiceItemInfo(); c.Title= dr[m].ToString(); if (sAnswers.Contains(m)) c.IsRight = true; else c.IsRight = false; c.SelectChoiceID = choiceID; choiceitems.Add(c); } break; case "填空": break; case "判断": break; case "简答": break; case "程序填空": break; } } } catch (Exception e) { HttpContext.Current.Response.Write("错误信息:" + e.Message); return false; } finally { if (dr != null) dr.Close(); myConn.Close(); } if (questions == null) return false; dc.ChoiceItemInfo.InsertAllOnSubmit<ChoiceItemInfo>(choiceitems); dc.SubmitChanges(); return true; }
/// <summary> /// 删除试题信息 /// </summary> /// <param name="s">试题实体</param> public static void DeleteQuestion(QuestionInfo s, ExamDbDataContext dc) { AttachInfo<QuestionInfo>(dc.QuestionInfo, s); dc.QuestionInfo.DeleteOnSubmit(s); dc.SubmitChanges(); }
/// <summary> /// 更新试题信息 /// </summary> /// <param name="s">试题实体</param> public static void UpdateQuestion(QuestionInfo s, ExamDbDataContext dc) { AttachInfo<QuestionInfo>(dc.QuestionInfo, s); dc.SubmitChanges(); // PurgeCacheItems("AllQuestions_" + s.DepartmentID.ToString()); }
private void detach_QuestionInfo(QuestionInfo entity) { this.SendPropertyChanging(); entity.QuestionTypeInfo = null; }
private void detach_QuestionInfo(QuestionInfo entity) { this.SendPropertyChanging(); entity.KnowledgePointInfo = null; }
private void attach_QuestionInfo(QuestionInfo entity) { this.SendPropertyChanging(); entity.CourseInfo = this; }