public void Operation_QuestionBank(HR_Train_QuestionBank obj) { try { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; HR_Train_QuestionBank temp = new HR_Train_QuestionBank(); var varData = from a in ctx.HR_Train_QuestionBank where a.ID == obj.ID select a; if (varData.Count() == 0) { ctx.HR_Train_QuestionBank.InsertOnSubmit(obj); } else if (varData.Count() == 1) { if (obj.Type == null) { ctx.HR_Train_QuestionBank.DeleteOnSubmit(varData.Single()); } else { temp = varData.Single(); temp.Answer = obj.Answer; temp.CourseID = obj.CourseID; temp.Questions = obj.Questions; temp.Type = obj.Type; } } else { throw new Exception("记录数不唯一"); } ctx.SubmitChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } }
decimal MarkingAnswer() { decimal rightCount = 0; foreach (Guid guid in _ListGuidQuestion) { HR_Train_QuestionBank bank = _ServiceBasicInfo.GetBankInfo(guid); if (bank != null) { if (bank.Answer == _DicAnswer[guid.ToString()]) { rightCount += 1; } } else { rightCount += 1; } } return(rightCount / (decimal)_ListGuidQuestion.Count() * 100); }
public void InputQuestionsBank(int courseID, DataTable questionsTable) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; ctx.Connection.Open(); ctx.Transaction = ctx.Connection.BeginTransaction(); try { questionsTable = DataSetHelper.OrderBy(questionsTable, "考题ID,选项"); List <string> lstQuestions = DataSetHelper.ColumnsToList_Distinct(questionsTable, "考题ID"); foreach (string questionsID in lstQuestions) { DataTable tempQuestions = DataSetHelper.SiftDataTable(questionsTable, "考题ID = '" + questionsID + "'"); if (tempQuestions.Rows.Count > 0) { CE_HR_Train_QuesitonsType quesType = GeneralFunction.StringConvertToEnum <CE_HR_Train_QuesitonsType>(tempQuestions.Rows[0]["考题类型"].ToString()); HR_Train_QuestionBank bank = new HR_Train_QuestionBank(); switch (quesType) { case CE_HR_Train_QuesitonsType.判断题: bank.Answer = tempQuestions.Rows[0]["答案"].ToString().ToUpper(); bank.CourseID = courseID; bank.ID = Guid.NewGuid(); bank.Questions = tempQuestions.Rows[0]["考题内容"].ToString(); bank.Type = tempQuestions.Rows[0]["考题类型"].ToString(); ctx.HR_Train_QuestionBank.InsertOnSubmit(bank); break; case CE_HR_Train_QuesitonsType.单选题: case CE_HR_Train_QuesitonsType.多选题: Guid guid = Guid.NewGuid(); bank.Answer = tempQuestions.Rows[0]["答案"].ToString().ToUpper(); bank.CourseID = courseID; bank.ID = guid; bank.Questions = tempQuestions.Rows[0]["考题内容"].ToString(); bank.Type = tempQuestions.Rows[0]["考题类型"].ToString(); ctx.HR_Train_QuestionBank.InsertOnSubmit(bank); ctx.SubmitChanges(); foreach (DataRow dr in tempQuestions.Rows) { HR_Train_QuestionBank_Option option = new HR_Train_QuestionBank_Option(); option.OptionContent = dr["选项内容"].ToString(); option.OptionTag = dr["选项"].ToString().ToUpper(); option.QuestionID = guid; ctx.HR_Train_QuestionBank_Option.InsertOnSubmit(option); } ctx.SubmitChanges(); break; default: break; } } } ctx.SubmitChanges(); ctx.Transaction.Commit(); } catch (Exception ex) { ctx.Transaction.Rollback(); throw new Exception(ex.Message); } }