/// <summary> /// 更新一条数据 /// </summary> public int Update(SqlTransaction sqltran, Entities.KLQuestion model) { SqlParameter[] parameters = { new SqlParameter("@KLQID", SqlDbType.BigInt, 8), new SqlParameter("@KLID", SqlDbType.BigInt, 8), new SqlParameter("@AskCategory", SqlDbType.Int, 4), new SqlParameter("@Ask", SqlDbType.NVarChar, 2000), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUserID", SqlDbType.Int, 4), new SqlParameter("@ModifyTime", SqlDbType.DateTime), new SqlParameter("@ModifyUserID", SqlDbType.Int, 4) }; parameters[0].Value = model.KLQID; parameters[1].Value = model.KLID; parameters[2].Value = model.AskCategory; parameters[3].Value = model.Ask; parameters[4].Value = model.Status; parameters[5].Value = model.CreateTime; parameters[6].Value = model.CreateUserID; parameters[7].Value = model.ModifyTime; parameters[8].Value = model.ModifyUserID; return(SqlHelper.ExecuteNonQuery(sqltran, CommandType.StoredProcedure, P_KLQUESTION_UPDATE, parameters)); }
/// <summary> /// 增加一条数据 /// </summary> public int Insert(Entities.KLQuestion model) { SqlParameter[] parameters = { new SqlParameter("@KLQID", SqlDbType.BigInt, 8), new SqlParameter("@KLID", SqlDbType.BigInt, 8), new SqlParameter("@AskCategory", SqlDbType.Int, 4), new SqlParameter("@Ask", SqlDbType.NVarChar, 2000), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUserID", SqlDbType.Int, 4), new SqlParameter("@ModifyTime", SqlDbType.DateTime), new SqlParameter("@ModifyUserID", SqlDbType.Int, 4) }; parameters[0].Direction = ParameterDirection.Output; parameters[1].Value = model.KLID; parameters[2].Value = model.AskCategory; parameters[3].Value = model.Ask; parameters[4].Value = model.Status; parameters[5].Value = model.CreateTime; parameters[6].Value = model.CreateUserID; parameters[7].Value = model.ModifyTime; parameters[8].Value = model.ModifyUserID; SqlHelper.ExecuteNonQuery(CONNECTIONSTRINGS, CommandType.StoredProcedure, P_KLQUESTION_INSERT, parameters); return((int)parameters[0].Value); }
/// <summary> /// 根据小题id取小题name /// </summary> /// <param name="KLQID"></param> /// <returns></returns> public string GetSmallquestionName(string KLQID) { Entities.KLQuestion Model = null; Model = BLL.KLQuestion.Instance.GetKLQuestion(Convert.ToInt32(KLQID)); if (Model != null) { return(Model.Ask); } else { return(""); } }
//停用试题 private void questionDisableKnowledgeLib(out string msg) { msg = string.Empty; string connectionstrings = ConfigurationUtil.GetAppSettingValue("ConnectionStrings_CC"); SqlConnection connection = new SqlConnection(connectionstrings); connection.Open(); SqlTransaction sqltran = connection.BeginTransaction("SampleTransaction"); try { if (RequestKLQID != "") { string[] KLQIDs = RequestKLQID.Split(','); for (int i = 0; i < KLQIDs.Length; i++) { long _klqid; if (long.TryParse(KLQIDs[i], out _klqid)) { Entities.KLQuestion model = BLL.KLQuestion.Instance.GetKLQuestion(_klqid); if (model.Status == 0) { model.Status = -2; BLL.KLQuestion.Instance.Update(sqltran, model); BLL.Util.InsertUserLog(sqltran, "【停用】知识库试题表【停用】主键:【" + _klqid + "】将操作状态【正常】修改为:【停用】的记录"); } msg = "{'msg':'停用操作成功'}"; } } } //事务提交 sqltran.Commit(); } catch (Exception ex) { sqltran.Rollback(); msg = "{'msg':'" + ex.Message.ToString() + "'}"; } finally { connection.Close(); } }
private Entities.KLQuestion LoadSingleKLQuestion(DataRow row) { Entities.KLQuestion model = new Entities.KLQuestion(); if (row["KLQID"].ToString() != "") { model.KLQID = long.Parse(row["KLQID"].ToString()); } if (row["KLID"].ToString() != "") { model.KLID = long.Parse(row["KLID"].ToString()); } if (row["AskCategory"].ToString() != "") { model.AskCategory = int.Parse(row["AskCategory"].ToString()); } model.Ask = row["Ask"].ToString(); if (row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } if (row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } if (row["CreateUserID"].ToString() != "") { model.CreateUserID = int.Parse(row["CreateUserID"].ToString()); } if (row["ModifyTime"].ToString() != "") { model.ModifyTime = DateTime.Parse(row["ModifyTime"].ToString()); } if (row["ModifyUserID"].ToString() != "") { model.ModifyUserID = int.Parse(row["ModifyUserID"].ToString()); } return(model); }
//提交或保存:type=submit 提交;type=save 保存 public void examOnlineOperate(string type, out string msg) { msg = string.Empty; int loginerID = BLL.Util.GetLoginUserID(); //登陆者ID int _EOLID = 0; //插入该考生在线考试记录后返回的主键 int _EOLDID = 0; //插入在线考试小题明细记录后返回的主键 int _totalScore = 0; //记录总得分,最后一步更新到在线考试表中 bool isSubject = false; //是否存在主观题,默认false 不存在(在线考试试卷则为已阅);true存在(在线考试试卷则为未阅) int _paperID; //试卷ID if (!int.TryParse(RequestExamPaperID, out _paperID)) { msg = "{msg:'试卷ID出错,操作失败!'}"; return; } Entities.ExamOnline model_examOnlineInsert = null; //新增时增加的在线考试实体,如果之前没保存过,则需要新增 Entities.ExamOnline model_examOnlineToUpdate = null; //需要修改之前保存过的试卷信息 ArrayList array_examOnlineDetailDelete = new ArrayList(); //如果有过保存的记录,则保存需要删除的小题明细ID 集合 ArrayList array_examOnlineAnswerDelete = new ArrayList(); //如果有过保存的记录,则保存需要删除的答案ID 集合 bool paperIsSave = false; //该考生试卷是否被保存过,false 没有;true 是; ArrayList array_appendValueAnswer = new ArrayList(); //记录答案对应的小题明细数组 int examOnlineDetailIndex = 0; //数组值 int _EIID; if (!int.TryParse(RequestEIID, out _EIID)) { msg = "{msg:'项目ID出错,操作失败!'}"; return; } judgeSubmitExamLimit(_EIID, out msg); if (msg != string.Empty) { return; } //在线考试明细表 集合(非主观题) List <Entities.ExamOnlineDetail> list_examOnlineDetail = new List <Entities.ExamOnlineDetail>(); //在线考试答案表 集合(非主观题) List <Entities.ExamOnlineAnswer> list_examOnlineAnswer = new List <Entities.ExamOnlineAnswer>(); //在线考试明细表 集合(主观题) List <Entities.ExamOnlineDetail> list_SubjetExamOnlineDetail = new List <Entities.ExamOnlineDetail>(); //在线考试答案表 集合(主观题) List <Entities.ExamOnlineAnswer> list_SubjetExamOnlineAnswer = new List <Entities.ExamOnlineAnswer>(); //日志:修改 在线考试表 集合 ArrayList array_updateExamOnlineLog = new ArrayList(); //在线考试表 修改前的model Entities.ExamOnline model_updateExamOnlineLog_Old = null; //日志:插入 在线考试表 集合 ArrayList arry_insertExamOnlineLog = new ArrayList(); //日志:插入 在线考试明细表 记录集合 ArrayList array_insertExamOnlineDetailLog = new ArrayList(); //日志:插入 在线考试答案表 记录集合 ArrayList array_insertExamOnlineAnswerLog = new ArrayList(); #region 准备数据 Entities.QueryExamOnline query_examOnlineSave = new Entities.QueryExamOnline(); int saveCount; if (RequestExamType == "1") //补考项目考试 { query_examOnlineSave.MEIID = _EIID; query_examOnlineSave.IsMakeUp = 1; } else if (RequestExamType == "0") //正常项目考试 { query_examOnlineSave.IsMakeUp = 0; query_examOnlineSave.EIID = _EIID; } query_examOnlineSave.ExamPersonID = loginerID; DataTable dt_examOnlineSave = BLL.ExamOnline.Instance.GetExamOnline(query_examOnlineSave, "", 1, 10000, out saveCount); if (dt_examOnlineSave.Rows.Count > 0) { paperIsSave = true; //存在数据,准备上次保存的数据,对其进行修改 model_examOnlineToUpdate = BLL.ExamOnline.Instance.GetExamOnline(long.Parse(dt_examOnlineSave.Rows[0]["EOLID"].ToString())); model_updateExamOnlineLog_Old = model_examOnlineToUpdate; if (model_examOnlineToUpdate != null) { model_examOnlineToUpdate.ExamEndTime = DateTime.Now; model_examOnlineToUpdate.IsLack = 0; //准备需要删除的小题明细ID 集合 Entities.QueryExamOnlineDetail query_examOnlineDetailDelete = new Entities.QueryExamOnlineDetail(); query_examOnlineDetailDelete.EOLID = int.Parse(model_examOnlineToUpdate.EOLID.ToString()); DataTable dt_detailDelete = BLL.ExamOnlineDetail.Instance.GetExamOnlineDetail(query_examOnlineDetailDelete, "", 1, 10000, out saveCount); for (int i = 0; i < dt_detailDelete.Rows.Count; i++) { //插入 集合 array_examOnlineDetailDelete.Add(dt_detailDelete.Rows[i]["EOLDID"].ToString()); //准备需要删除的该小题答案ID 集合 Entities.QueryExamOnlineAnswer query_examOnlineAnswerDelete = new Entities.QueryExamOnlineAnswer(); query_examOnlineAnswerDelete.EOLDID = int.Parse(dt_detailDelete.Rows[i]["EOLDID"].ToString()); DataTable dt_answerDelete = BLL.ExamOnlineAnswer.Instance.GetExamOnlineAnswer(query_examOnlineAnswerDelete, "", 1, 10000, out saveCount); for (int j = 0; j < dt_answerDelete.Rows.Count; j++) { //插入 集合 array_examOnlineAnswerDelete.Add(dt_answerDelete.Rows[j]["RecID"].ToString()); } } } } // a、准备 插入在线考试表记录 数据 // 如果之前保存过数据,则不需要新增,修改即可 if (paperIsSave == false) { model_examOnlineInsert = new Entities.ExamOnline(); if (RequestExamType == "1") //补考项目考试 { model_examOnlineInsert.IsMakeUp = 1; model_examOnlineInsert.MEIID = _EIID; //根据补考项目ID,找到对应的考试项目ID,并赋值 Entities.MakeUpExamInfo model_makeUpExamInfoGetEIID = BLL.MakeUpExamInfo.Instance.GetMakeUpExamInfo(_EIID); if (model_makeUpExamInfoGetEIID == null) { msg = "{msg:'该补考项目对应考试项目ID未找到,操作失败!'}"; return; } model_examOnlineInsert.EIID = int.Parse(model_makeUpExamInfoGetEIID.EIID.ToString()); } else if (RequestExamType == "0") //正常项目考试 { model_examOnlineInsert.IsMakeUp = 0; model_examOnlineInsert.EIID = _EIID; } model_examOnlineInsert.ExamPersonID = loginerID; model_examOnlineInsert.ExamStartTime = DateTime.Parse(RequestExamStartTime); model_examOnlineInsert.ExamEndTime = DateTime.Now; model_examOnlineInsert.CreateTime = DateTime.Now; model_examOnlineInsert.CreaetUserID = loginerID; model_examOnlineInsert.IsLack = 0; //不算缺考 //_EOLID = insertExamOnline(tran, model_examOnlineInsert); } if (model_examOnlineInsert != null) { model_examOnlineInsert.Status = type == "save" ? 0 : 1; } if (model_examOnlineToUpdate != null) { model_examOnlineToUpdate.Status = type == "save" ? 0 : 1; } #endregion #region b、准备 插入在线考试小题明细 数据 #region 1)准备 非主观题 数据 if (RequestNoSubjectQestion != "") { //分解成每一个小题数组,类似['大题ID:小题ID:单选题答案','大题ID:小题ID:复选题答案1;复选题答案2;复选题答案3'] string[] noSubjectQuestion = RequestNoSubjectQestion.Split(','); for (int i = 0; i < noSubjectQuestion.Length; i++) { examOnlineDetailIndex = i; //分解成每一个小题详细信息的数组,类似['大题ID','小题ID','复选题答案1;复选题答案2;复选题答案3'] string[] eachNoSubjectQuestion = noSubjectQuestion[i].Split(':'); //如果该小题的详细信息都有值,则插入;否则,不插入 if (eachNoSubjectQuestion[0] != "" && eachNoSubjectQuestion[1] != "" && eachNoSubjectQuestion[2] != "") { Entities.ExamOnlineDetail model_examOnlineDetailInsert = new Entities.ExamOnlineDetail(); //model_examOnlineDetailInsert.EOLID = int.Parse(_EOLID.ToString()); model_examOnlineDetailInsert.EPID = _paperID; model_examOnlineDetailInsert.BQID = long.Parse(eachNoSubjectQuestion[0]); model_examOnlineDetailInsert.KLQID = long.Parse(eachNoSubjectQuestion[1]); model_examOnlineDetailInsert.Score = 0; // (1)根据该生给出的答案去比较正确的答案 // 先根据该小题ID去找出该题正确答案串 string rightAnswer = string.Empty; Entities.QueryKLQAnswer query_KLQAnswer = new Entities.QueryKLQAnswer(); int totalCount; query_KLQAnswer.KLQID = model_examOnlineDetailInsert.KLQID; DataTable dt_KLQAnswer = BLL.KLQAnswer.Instance.GetKLQAnswer(query_KLQAnswer, "", 1, 10000, out totalCount); if (dt_KLQAnswer.Rows.Count == 0) { msg = "{msg:'对应题目的答案未找到,操作失败!'}"; return; } for (int j = 0; j < dt_KLQAnswer.Rows.Count; j++) { rightAnswer += dt_KLQAnswer.Rows[j]["KLAOID"].ToString() + ";"; } rightAnswer = rightAnswer.TrimEnd(';'); // 比较该串与考生给出的答案串是否相同,相同则得分;不相同给零分 // 比较方法(两个长度相同,分解考生答案,保证每一个答案都在正确答案内) if (eachNoSubjectQuestion[2].Length == rightAnswer.Length) { string[] eachNoSubjectAnswer = eachNoSubjectQuestion[2].Split(';'); bool IsRightOrWrong = true; // 答案是否正确,正确true;错误false for (int ea = 0; ea < eachNoSubjectAnswer.Length; ea++) { if (!rightAnswer.Contains(eachNoSubjectAnswer[ea])) { IsRightOrWrong = false; } } if (IsRightOrWrong) { // (2)找到该小题如果正确则应得的分数 Entities.ExamBigQuestion model_examBigQuestion = BLL.ExamBigQuestion.Instance.GetExamBigQuestion(model_examOnlineDetailInsert.BQID); if (model_examBigQuestion == null) { msg = "{msg:'对应该小题的对应的分数未找到,操作失败!'}"; return; } int eachQuestionScore = model_examBigQuestion.EachQuestionScore; model_examOnlineDetailInsert.Score = eachQuestionScore; _totalScore += eachQuestionScore; //计入总得分 } } model_examOnlineDetailInsert.CreaetUserID = loginerID; model_examOnlineDetailInsert.CreateTime = DateTime.Now; //插入在线考试小题明细表 集合 list_examOnlineDetail.Add(model_examOnlineDetailInsert); //插入在线考试小题明细表 日志集合 string detailsLog = "在线考试小题明细表【插入】"; int epidLog; int bqidLog; int klqidLog; if (int.TryParse(model_examOnlineDetailInsert.EPID.ToString(), out epidLog)) { Entities.ExamPaper model_examPaperLog = BLL.ExamPaper.Instance.GetExamPaper(epidLog); if (model_examPaperLog != null) { detailsLog += "试卷名称【" + model_examPaperLog.Name + "】"; } } if (int.TryParse(model_examOnlineDetailInsert.BQID.ToString(), out bqidLog)) { Entities.ExamBigQuestion model_examBigQuestionLog = BLL.ExamBigQuestion.Instance.GetExamBigQuestion(bqidLog); if (model_examBigQuestionLog != null) { detailsLog += "大题名称【" + model_examBigQuestionLog.Name + "】"; } } if (int.TryParse(model_examOnlineDetailInsert.KLQID.ToString(), out klqidLog)) { Entities.KLQuestion model_klqQestionLog = BLL.KLQuestion.Instance.GetKLQuestion(klqidLog); if (model_klqQestionLog != null) { detailsLog += "小题内容【" + model_klqQestionLog.Ask + "】"; } } detailsLog += "本小题得分【" + model_examOnlineDetailInsert.Score + "】插入时间【" + model_examOnlineDetailInsert.CreateTime + "】的记录"; array_insertExamOnlineDetailLog.Add(detailsLog); // (3)插入在线考试答案表 // 分解答案串,分条插入该表 string[] eachAnswer = eachNoSubjectQuestion[2].Split(';'); for (int k = 0; k < eachAnswer.Length; k++) { Entities.ExamOnlineAnswer model_examOnlineAnswer = new Entities.ExamOnlineAnswer(); //model_examOnlineAnswer.EOLDID = int.Parse(_EOLDID.ToString()); model_examOnlineAnswer.ExamAnswer = eachAnswer[k]; model_examOnlineAnswer.CreaetUserID = loginerID; model_examOnlineAnswer.CreateTime = DateTime.Now; //插入在线考试答案表 集合 list_examOnlineAnswer.Add(model_examOnlineAnswer); array_appendValueAnswer.Add(examOnlineDetailIndex); //插入在线考试答案表 日志集合 array_insertExamOnlineAnswerLog.Add("在线考试答案表【插入】提交答案:【" + model_examOnlineAnswer.ExamAnswer + "】插入时间【" + model_examOnlineAnswer.CreateTime + "】的记录"); } } } } #endregion #region 2)准备 插入主观题 数据(主观题答案为空,也会插入) if (RequestSubjectQuestion != "") { //分解成每一个小题数组,类似['大题ID^^小题ID^^答案','大题ID^^小题ID^^答案','大题ID^^小题ID^^答案'] string[] subjectQuestion = RequestSubjectQuestion.Split(new string[] { "$$" }, StringSplitOptions.None); for (int i = 0; i < subjectQuestion.Length; i++) { //分解成每一题的每个详细信息,类似['大题ID','小题ID','答案'] string[] eachSubjectQuestion = subjectQuestion[i].Split(new string[] { "^^" }, StringSplitOptions.None); Entities.ExamOnlineDetail model_subjectExamOnlineDetail = new Entities.ExamOnlineDetail(); //model_subjectExamOnlineDetail.EOLID = _EOLID.ToString; model_subjectExamOnlineDetail.EPID = _paperID; model_subjectExamOnlineDetail.BQID = long.Parse(eachSubjectQuestion[0]); model_subjectExamOnlineDetail.KLQID = long.Parse(eachSubjectQuestion[1]); model_subjectExamOnlineDetail.Score = 0; model_subjectExamOnlineDetail.CreaetUserID = loginerID; model_subjectExamOnlineDetail.CreateTime = DateTime.Now; //插入在线考试小题明细表 集合 list_SubjetExamOnlineDetail.Add(model_subjectExamOnlineDetail); //插入在线考试小题明细表 日志集合 string detailsLog = "在线考试小题明细表【主观题】【插入】"; int epidLog; int bqidLog; int klqidLog; if (int.TryParse(model_subjectExamOnlineDetail.EPID.ToString(), out epidLog)) { Entities.ExamPaper model_examPaperLog = BLL.ExamPaper.Instance.GetExamPaper(epidLog); if (model_examPaperLog != null) { detailsLog += "试卷名称【" + model_examPaperLog.Name + "】"; } } if (int.TryParse(model_subjectExamOnlineDetail.BQID.ToString(), out bqidLog)) { Entities.ExamBigQuestion model_examBigQuestionLog = BLL.ExamBigQuestion.Instance.GetExamBigQuestion(bqidLog); if (model_examBigQuestionLog != null) { detailsLog += "大题名称【" + model_examBigQuestionLog.Name + "】"; } } if (int.TryParse(model_subjectExamOnlineDetail.KLQID.ToString(), out klqidLog)) { Entities.KLQuestion model_klqQestionLog = BLL.KLQuestion.Instance.GetKLQuestion(klqidLog); if (model_klqQestionLog != null) { detailsLog += "小题内容【" + model_klqQestionLog.Ask + "】"; } } detailsLog += "本小题得分【" + model_subjectExamOnlineDetail.Score + "】插入时间【" + model_subjectExamOnlineDetail.CreateTime + "】的记录"; array_insertExamOnlineDetailLog.Add(detailsLog); //在线考试答案表 实体 Entities.ExamOnlineAnswer model_subjectExamOnlineAnswer = new Entities.ExamOnlineAnswer(); //model_subjectExamOnlineAnswer.EOLDID = _EOLDID; model_subjectExamOnlineAnswer.ExamAnswer = eachSubjectQuestion[2]; model_subjectExamOnlineAnswer.CreaetUserID = loginerID; model_subjectExamOnlineAnswer.CreateTime = DateTime.Now; //插入在线考试答案表 集合 list_SubjetExamOnlineAnswer.Add(model_subjectExamOnlineAnswer); //插入在线考试答案表 日志集合 array_insertExamOnlineAnswerLog.Add("在线考试答案表【插入】提交答案:【" + model_subjectExamOnlineAnswer.ExamAnswer + "】插入时间【" + model_subjectExamOnlineAnswer.CreateTime + "】的记录"); //将isSubject字段修改为 true;在线考试的IsMarking需修改为0未阅 isSubject = true; } } if (model_examOnlineInsert != null) { model_examOnlineInsert.SumScore = _totalScore; model_examOnlineInsert.IsMarking = isSubject == false ? 1 : 0; //准备插入数据的日志 string logStr = string.Empty; if (type == "save") { logStr += "【保存】"; } else { logStr += "【提交】"; } logStr += "在线考试表【插入】"; string meiidStr = model_examOnlineInsert.IsMakeUp == 1 ? "补考项目ID【" + model_examOnlineInsert.MEIID + "】" : ""; string isMakeUp = model_examOnlineInsert.IsMakeUp == 1 ? "补考" : "未补考"; string isMakeing = model_examOnlineInsert.IsMarking == 1 ? "已阅" : "未阅"; string status = model_examOnlineInsert.Status == 1 ? "提交" : "保存"; //考试项目名称 string eiidName = string.Empty; Entities.ExamInfo model_examInfo = BLL.ExamInfo.Instance.GetExamInfo(model_examOnlineInsert.EIID); if (model_examInfo != null) { eiidName = model_examInfo.Name; logStr += "考试项目名称【" + eiidName + "】"; } logStr += meiidStr + "考生名称【" + BLL.Util.GetNameInHRLimitEID(loginerID) + "】考试开始时间【" + model_examOnlineInsert.ExamStartTime + "】考试结束时间【" + model_examOnlineInsert.ExamEndTime + "】总得分【" + model_examOnlineInsert.SumScore + "】是否补考【" + isMakeUp + "】是否阅卷【" + isMakeing + "】状态【" + status + "】的记录"; arry_insertExamOnlineLog.Add(logStr); } if (model_examOnlineToUpdate != null) { model_examOnlineToUpdate.SumScore = _totalScore; model_examOnlineToUpdate.IsMarking = isSubject == false ? 1 : 0; //准备修改数据的日志 string logStr = string.Empty; if (type == "save") { logStr += "【保存】"; } else { logStr += "【提交】"; } logStr += "在线考试表【更新】"; if (model_updateExamOnlineLog_Old.SumScore != model_examOnlineToUpdate.SumScore) { logStr += "总得分从【" + model_updateExamOnlineLog_Old.SumScore + "】修改成【" + model_examOnlineToUpdate.SumScore + "】"; } if (model_updateExamOnlineLog_Old.IsMarking != model_examOnlineToUpdate.IsMarking) { string isMarking_Old = model_updateExamOnlineLog_Old.IsMarking == 1 ? "是" : "否"; string isMarking_Now = model_examOnlineToUpdate.IsMarking == 1 ? "是" : "否"; logStr += "是否阅卷从【" + isMarking_Old + "】修改成【" + isMarking_Now + "】"; } if (model_updateExamOnlineLog_Old.ExamEndTime != model_examOnlineToUpdate.ExamEndTime) { logStr += "考试结束时间从【" + model_updateExamOnlineLog_Old.ExamEndTime + "】修改成【" + model_examOnlineToUpdate.ExamEndTime + "】"; } if (model_updateExamOnlineLog_Old.Status != model_examOnlineToUpdate.Status) { string status_Old = model_updateExamOnlineLog_Old.Status == 1 ? "提交" : "保存"; string status_Now = model_examOnlineToUpdate.Status == 1 ? "提交" : "保存"; logStr += "考生试卷状态从【" + status_Old + "】修改成【" + status_Now + "】"; } logStr += "记录"; array_updateExamOnlineLog.Add(logStr); } #endregion #endregion #region 提交、保存 实务操作 string connectionstrings = ConfigurationUtil.GetAppSettingValue("ConnectionStrings_CC"); SqlConnection connection = new SqlConnection(connectionstrings); connection.Open(); SqlTransaction tran = connection.BeginTransaction("SampleTransaction"); try { //如果没有保存过的,新增一条;如果被保存过,修改在线考试这条记录并删除之前的小题明细和答案,然后重新插入,反之都要插入 if (paperIsSave == false) { //插入在线考试表一条记录 _EOLID得到返回的主键值 _EOLID = insertExamOnline(tran, model_examOnlineInsert); } else { _EOLID = int.Parse(model_examOnlineToUpdate.EOLID.ToString()); //修改在线考试表的该条记录 updateExamOnline(tran, model_examOnlineToUpdate); //删除明细表的该考生本张试卷ID的所有明细记录 for (int i = 0; i < array_examOnlineDetailDelete.Count; i++) { long eoldid = long.Parse(array_examOnlineDetailDelete[i].ToString()); BLL.ExamOnlineDetail.Instance.Delete(tran, eoldid); BLL.Util.InsertUserLog(tran, "在线考试明细表【删除】主键ID:【" + eoldid + "】的记录"); } //删除答案表的该考生本张试卷ID的所有答案记录 for (int j = 0; j < array_examOnlineAnswerDelete.Count; j++) { long recid = long.Parse(array_examOnlineAnswerDelete[j].ToString()); BLL.ExamOnlineAnswer.Instance.Delete(tran, recid); BLL.Util.InsertUserLog(tran, "在线考试答案表【删除】主键ID:【" + recid + "】的记录"); } } //插入非主观题 for (int kk = 0; kk < list_examOnlineDetail.Count; kk++) { //插入在线考试小题明细表 _EOLDID到返回的主键值 Entities.ExamOnlineDetail eachExamOnlineDetail = list_examOnlineDetail[kk]; eachExamOnlineDetail.EOLID = _EOLID; _EOLDID = insertOnlineDetail(tran, eachExamOnlineDetail); //插入在线考试答案表 这两个表的插入不一定是一对,因为有的是多选,需要多条插入 for (int n = kk; n < array_appendValueAnswer.Count; n++) { if (kk == int.Parse(array_appendValueAnswer[n].ToString())) { Entities.ExamOnlineAnswer eachExamOnlineAnswer = list_examOnlineAnswer[n]; eachExamOnlineAnswer.EOLDID = _EOLDID; insertExamOnlineAnswer(tran, eachExamOnlineAnswer); } } } //插入主观题 for (int tt = 0; tt < list_SubjetExamOnlineDetail.Count; tt++) { //插入在线考试小题明细表 _EOLDID到返回的主键值 Entities.ExamOnlineDetail eachExamOnlineDetail = list_SubjetExamOnlineDetail[tt]; eachExamOnlineDetail.EOLID = _EOLID; _EOLDID = int.Parse(insertOnlineDetail(tran, eachExamOnlineDetail).ToString()); //插入在线考试答案表 这两个表的插入肯定是一对,所以不用循环list Entities.ExamOnlineAnswer eachExamOnlineAnswer = list_SubjetExamOnlineAnswer[tt]; eachExamOnlineAnswer.EOLDID = _EOLDID; insertExamOnlineAnswer(tran, eachExamOnlineAnswer); } //插入日志 for (int log1 = 0; log1 < arry_insertExamOnlineLog.Count; log1++) { BLL.Util.InsertUserLog(tran, arry_insertExamOnlineLog[log1].ToString()); } for (int log2 = 0; log2 < array_updateExamOnlineLog.Count; log2++) { BLL.Util.InsertUserLog(tran, array_updateExamOnlineLog[log2].ToString()); } for (int log3 = 0; log3 < array_insertExamOnlineDetailLog.Count; log3++) { BLL.Util.InsertUserLog(tran, array_insertExamOnlineDetailLog[log3].ToString()); } for (int log4 = 0; log4 < array_insertExamOnlineAnswerLog.Count; log4++) { BLL.Util.InsertUserLog(tran, array_insertExamOnlineAnswerLog[log4].ToString()); } //事务提交 tran.Commit(); msg = "{msg:'true'}"; } catch (Exception ex) { tran.Rollback(); msg = "{msg:'" + ex.Message.ToString() + "'}"; BLL.Loger.Log4Net.Error("在线考试异常", ex); } finally { connection.Close(); } #endregion }
/// <summary> /// 添加时的保存 /// </summary> /// <param name="knowModel"></param> /// <param name="faqModel"></param> /// <param name="questionModel"></param> /// <param name="answerModel"></param> /// <param name="optionModel"></param> /// <param name="errMsg"></param> public void AddSave(Entities.KnowledgeLib knowModel, Entities.KLFAQ faqModel, Entities.KLQuestion questionModel, Entities.KLQAnswer answerModel, Entities.KLAnswerOption optionModel, out string errMsg) { errMsg = ""; SqlConnection connection = new SqlConnection(CONNECTIONSTRINGS); connection.Open(); SqlTransaction sqlTran = connection.BeginTransaction("SampleTransaction"); try { int kid = Dal.KnowledgeLib.Instance.Insert(sqlTran, knowModel); int faqId = Dal.KLFAQ.Instance.Insert(sqlTran, faqModel); int questionId = Dal.KLQuestion.Instance.Insert(sqlTran, questionModel); Dal.KLQAnswer.Instance.Insert(sqlTran, answerModel); int optionId = Dal.KLAnswerOption.Instance.Insert(sqlTran, optionModel); } catch (Exception ex) { sqlTran.Rollback(); errMsg = ex.Message.ToString(); } finally { connection.Close(); } }
private void Submit(out string msg, int userID, out int epid) { msg = ""; epid = 0;//返回的试卷ID //将页面的上的数据转换成类 ExamPaperPageInfo Info = (ExamPaperPageInfo)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(ExamPaperInfoStr, typeof(ExamPaperPageInfo)); Entities.ExamPaper examPaper = null; List <Entities.ExamBigQuestion> bigQList = null; List <Entities.ExamBSQuestionShip> shipList = null; string delBigQIDs = string.Empty; string DelShipIDs = string.Empty; //验证数据并转换成实体类 Info.Validate(out examPaper, out bigQList, out shipList, out delBigQIDs, out msg); if (string.IsNullOrEmpty(msg)) { //如果验证通过 //记录用户操作日志 List <StringBuilder> listLogStr = new List <StringBuilder>(); StringBuilder sblogstr = new StringBuilder(); #region 获得最终的试卷实体类 if (examPaper.EPID > 0) { //编辑 Entities.ExamPaper oldExamPaper = null; oldExamPaper = BLL.ExamPaper.Instance.GetExamPaper((long)examPaper.EPID); if (oldExamPaper != null) { #region 判断 if (oldExamPaper.Status == (int)ExamPaperState.InUsed) { msg = "已使用状态的试卷不能编辑"; return; } if (oldExamPaper.Status == (int)ExamPaperState.NotUsed && Action == "save") { msg = "未使用状态的试卷不能进行保存操作,只能提交"; return; } if (oldExamPaper.Status == -1) { msg = "已删除的试卷不能编辑"; return; } #endregion #region 记日志 sblogstr = new StringBuilder(); string logstr = ""; if (oldExamPaper.Name != examPaper.Name) { logstr += "将试卷名称由‘" + oldExamPaper.Name + "’改为‘" + examPaper.Name + "’,"; } if (oldExamPaper.ECID != examPaper.ECID) { logstr += "将试卷分类由‘" + oldExamPaper.ECID + "’改为‘" + examPaper.ECID + "’,"; } if (oldExamPaper.ExamDesc != examPaper.ExamDesc) { logstr += "将考试说明由‘" + oldExamPaper.ExamDesc + "’改为‘" + examPaper.ExamDesc + "’,"; } if (oldExamPaper.TotalScore != examPaper.TotalScore) { logstr += "将总分由‘" + oldExamPaper.TotalScore + "’改为‘" + examPaper.TotalScore + "’,"; } if (logstr != "") { logstr += "编辑了试卷【" + oldExamPaper.Name + "】:" + logstr; } if (logstr != "") { sblogstr.Append(logstr); listLogStr.Add(sblogstr); } #endregion oldExamPaper.Name = examPaper.Name; oldExamPaper.ECID = examPaper.ECID; oldExamPaper.ExamDesc = examPaper.ExamDesc; oldExamPaper.TotalScore = examPaper.TotalScore; oldExamPaper.LastModifyTime = DateTime.Now; oldExamPaper.LastModifyUserID = userID; oldExamPaper.BGID = examPaper.BGID; examPaper = oldExamPaper; } else { msg = "没有找到对应的试卷信息"; return; } } else { #region 记日志 sblogstr = new StringBuilder(); sblogstr.Append("添加了试卷【" + examPaper.Name + "】"); listLogStr.Add(sblogstr); #endregion //新增 examPaper.CreateTime = DateTime.Now; examPaper.CreaetUserID = userID; examPaper.LastModifyTime = DateTime.Now; examPaper.LastModifyUserID = userID; } #region 根据保存或者提交,设置试卷状态 if (Action == "save") { #region 记日志 sblogstr = new StringBuilder(); sblogstr.Append("保存了试卷【" + examPaper.Name + "】"); listLogStr.Add(sblogstr); #endregion examPaper.Status = (int)Entities.ExamPaperState.NotComplete; } else if (Action == "sub") { #region 记日志 sblogstr = new StringBuilder(); sblogstr.Append("提交了试卷【" + examPaper.Name + "】"); listLogStr.Add(sblogstr); #endregion examPaper.Status = (int)Entities.ExamPaperState.NotUsed; } else { msg = "没有找到对应的试卷信息"; return; } #endregion #endregion #region 获得大题实体类 if (bigQList != null) { ExamBigQuestion oldBigQModel; for (int i = 0; i < bigQList.Count; i++) { if (bigQList[i].BQID > 0) { //编辑 oldBigQModel = null; oldBigQModel = BLL.ExamBigQuestion.Instance.GetExamBigQuestion((long)bigQList[i].BQID); if (oldBigQModel == null) { msg = "没有找到ID为" + bigQList[i].BQID + "大题信息"; return; } else { #region 记日志 sblogstr = new StringBuilder(); string logstr = ""; sblogstr.Append("编辑了大题【" + oldBigQModel.Name + "】:"); if (oldBigQModel.Name != bigQList[i].Name) { logstr += "将大题名称由‘" + oldBigQModel.Name + "’改为‘" + bigQList[i].Name + "’,"; } if (oldBigQModel.BQDesc != bigQList[i].BQDesc) { logstr += "将大题描述由‘" + oldBigQModel.BQDesc + "’改为‘" + bigQList[i].BQDesc + "’,"; } if (oldBigQModel.AskCategory != bigQList[i].AskCategory) { logstr += "将题型由‘" + oldBigQModel.AskCategory + "’改为‘" + bigQList[i].AskCategory + "’,"; } if (oldBigQModel.EachQuestionScore != bigQList[i].EachQuestionScore) { logstr += "将每题分值由‘" + oldBigQModel.EachQuestionScore + "’改为‘" + bigQList[i].EachQuestionScore + "’,"; } if (oldBigQModel.QuestionCount != bigQList[i].QuestionCount) { logstr += "将试题总量由‘" + oldBigQModel.QuestionCount + "’改为‘" + bigQList[i].QuestionCount + "’,"; } if (logstr != "") { sblogstr.Append(logstr); listLogStr.Add(sblogstr); } #endregion oldBigQModel.Name = bigQList[i].Name; oldBigQModel.BQDesc = bigQList[i].BQDesc; oldBigQModel.AskCategory = bigQList[i].AskCategory; oldBigQModel.EachQuestionScore = bigQList[i].EachQuestionScore; oldBigQModel.QuestionCount = bigQList[i].QuestionCount; oldBigQModel.NO = bigQList[i].NO; bigQList[i] = oldBigQModel; } } else { #region 记日志 sblogstr = new StringBuilder(); sblogstr.Append("添加了大题【" + bigQList[i].Name + "】"); listLogStr.Add(sblogstr); #endregion //新增 bigQList[i].Status = 0; bigQList[i].CreateTime = DateTime.Now; bigQList[i].CreateUserID = userID; bigQList[i].ModifyTime = DateTime.Now; bigQList[i].ModifyUserID = userID; } } } #endregion #region 获得大小题关系实体类 if (shipList != null) { Entities.ExamBSQuestionShip oldshipMode; for (int i = 0; i < shipList.Count; i++) { if (shipList[i].BQID > 0) { //编辑的大题 oldshipMode = null; oldshipMode = BLL.ExamBSQuestionShip.Instance.GetExamBSQuestionShip((long)shipList[i].BQID, (long)shipList[i].KLQID); if (oldshipMode != null) { //编辑 Entities.KLQuestion klQuestion = BLL.KLQuestion.Instance.GetKLQuestion((long)shipList[i].KLQID); if (klQuestion.Status == -1) { msg = "小题【" + klQuestion.Ask + "】已经被删除"; return; } oldshipMode.BQID = shipList[i].BQID; oldshipMode.KLQID = shipList[i].KLQID; oldshipMode.NO = shipList[i].NO; shipList[i] = oldshipMode; } else { #region 记日志 sblogstr = new StringBuilder(); sblogstr.Append("添加了大题【" + shipList[i].BQID + "】下的小题【" + shipList[i].KLQID + "】"); listLogStr.Add(sblogstr); #endregion //新增 shipList[i].CreateTime = DateTime.Now; shipList[i].CreateUserID = userID; } } else { //新增的大题 shipList[i].CreateTime = DateTime.Now; shipList[i].CreateUserID = userID; } } #region 查出所有删除的小题 Entities.QueryExamBSQuestionShip shipquery; foreach (Entities.ExamBigQuestion item in bigQList)//循环大题 { if (item.BQID <= 0) { continue; } shipquery = new QueryExamBSQuestionShip(); shipquery.BQID = item.BQID; int totalCount = 0; //查找大题下的所有对应关系 DataTable olddt = BLL.ExamBSQuestionShip.Instance.GetExamBSQuestionShip(shipquery, "", 1, 9999, out totalCount); if (olddt != null) { int f = 0; foreach (DataRow dr in olddt.Rows) { f = 0; foreach (Entities.ExamBSQuestionShip shipItem in shipList) { if (dr["BQID"].ToString() == shipItem.BQID.ToString() && dr["KLQID"].ToString() == shipItem.KLQID.ToString()) { //存在 f = 1; break; } } if (f == 0) { //如果不存在,就是删除了 DelShipIDs = DelShipIDs + dr["BQID"].ToString() + "," + dr["KLQID"].ToString() + ";"; } } } } #endregion } #endregion #region 事务提交 string connectionstrings = ConfigurationUtil.GetAppSettingValue("ConnectionStrings_CC"); SqlConnection connection = new SqlConnection(connectionstrings); connection.Open(); SqlTransaction tran = connection.BeginTransaction("SampleTransaction"); //真实的数据操作 try { #region 保存试卷信息 if (examPaper.EPID > 0) { //edit epid = (int)examPaper.EPID; BLL.ExamPaper.Instance.Update(tran, examPaper); } else { //add epid = BLL.ExamPaper.Instance.Insert(tran, examPaper); } #endregion #region 保存大题和大小题关系 int bigQId = 0; if (bigQList != null) { foreach (Entities.ExamBigQuestion item in bigQList) { if (item.BQID > 0) { //编辑 bigQId = (int)item.BQID; BLL.ExamBigQuestion.Instance.Update(tran, item); } else { //添加 item.EPID = epid; bigQId = BLL.ExamBigQuestion.Instance.Insert(tran, item); } #region 保存大小题关系信息 if (shipList != null) { foreach (Entities.ExamBSQuestionShip shipItem in shipList) { if (shipItem.NO == item.NO)//当前大题的 { shipItem.BQID = bigQId; BLL.ExamBSQuestionShip.Instance.Delete(tran, shipItem.BQID, shipItem.KLQID); BLL.ExamBSQuestionShip.Instance.Insert(tran, shipItem); } } } #endregion } } #endregion #region 除小题关系 if (DelShipIDs != string.Empty) { DelShipIDs = DelShipIDs.Substring(0, DelShipIDs.Length - 1); string[] idGroup = DelShipIDs.Split(';'); foreach (string group in idGroup) { BLL.ExamBSQuestionShip.Instance.Delete(tran, long.Parse(group.Split(',')[0]), long.Parse(group.Split(',')[1])); } } #endregion #region 除大题 if (!String.IsNullOrEmpty(delBigQIDs)) { #region 记日志 sblogstr = new StringBuilder(); sblogstr.Append("删除了大题【" + delBigQIDs + "】"); listLogStr.Add(sblogstr); #endregion foreach (string item in delBigQIDs.Split(',')) { BLL.ExamBigQuestion.Instance.Delete(tran, long.Parse(item)); } } #endregion #region 保存用户操作日志 foreach (StringBuilder sbStr in listLogStr) { BLL.Util.InsertUserLog(tran, sbStr.ToString()); } #endregion tran.Commit(); } catch (Exception ex) { tran.Rollback(); msg = ex.Message.ToString(); BLL.Loger.Log4Net.Info(ex.ToString()); } finally { connection.Close(); } #endregion } }
/// <summary> /// 更新一条数据 /// </summary> public int Update(SqlTransaction sqltran, Entities.KLQuestion model) { return(Dal.KLQuestion.Instance.Update(sqltran, model)); }
/// <summary> /// 更新一条数据 /// </summary> public int Update(Entities.KLQuestion model) { return(Dal.KLQuestion.Instance.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Insert(SqlTransaction sqltran, Entities.KLQuestion model) { return(Dal.KLQuestion.Instance.Insert(sqltran, model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Insert(Entities.KLQuestion model) { return(Dal.KLQuestion.Instance.Insert(model)); }