private List <ExamItem> GenerateProcessItems(string sqlquery) { SQLServerAccessor dbAccessor = new SQLServerAccessor(); List <Dictionary <string, string> > output = dbAccessor.TableSearch(targetColumns, sqlquery); List <ExamItem> list = new List <ExamItem>(); int index = 0; foreach (Dictionary <string, string> rec in output) { ExamItem item = new ExamItem(); item.index = index++; item.question = rec["Question"]; item.answerRegex = rec["AnswerRegex"]; item.answer = rec["Answer"]; item.answerType = rec["AnswerType"]; item.interpret = rec["Interpret"]; item.askbackMessage = rec["AskbackMessage"]; if (!string.IsNullOrWhiteSpace(rec["Score"])) { item.score = int.Parse(rec["Score"]); } list.Add(item); } return(list); }
public List <ExamItem> ExamItemRowMapper(IDataReader dr) { List <ExamItem> ExamItemList = new List <ExamItem>(); try { while (dr.Read()) { ExamItem examItem = new ExamItem(); examItem.BaseKey = Convert.ToInt32(dr[0]); examItem.Item = dr[1].ToString(); examItem.FunCode = dr[2].ToString(); examItem.ParentId = Convert.ToInt32(dr[3]); ExamItemList.Add(examItem); } } catch (Exception) { } finally { dr.Close(); dbConnection.Close(); } return(ExamItemList); }
private IExamItem CreateExamItem(ExamItem examItem, IEnumerable <Setting> settings = null, string ItemVoice = "", string ItemEndVoice = "") { try { //核心 var type = Type.GetType(examItem.ExamItemType); var v = (IExamItem)Activator.CreateInstance(type, true); v.ItemCode = examItem.ItemCode; v.Name = examItem.ItemName; v.VoiceFile = ItemVoice == string.Empty?examItem.VoiceFile:ItemVoice; v.EndVoiceFile = ItemEndVoice == string.Empty? examItem.EndVoiceFile:ItemEndVoice; v.VoiceText = examItem.VoiceText; var provider = v as IProvider; if (provider != null) { var nameValues = settings.ToValues(); provider.Init(nameValues); } return(v); } catch (Exception exp) { Logger.ErrorFormat("创建 ExamItem {0}发生异常,原因:{1}", examItem.ExamItemType, exp, exp); return(null); } }
public void insert(ExamItem examItem) { examItem.BaseKey = this.getMaxKeyValue(); String sql = "insert into examItem(BaseKey,Item,FunCode,ParentId) \n" + "values(@BaseKey,@Item,@FunCode,@ParentId)"; SqlParameter[] parameters = { new SqlParameter("@BaseKey", examItem.BaseKey), new SqlParameter("@Item", examItem.Item), new SqlParameter("@FunCode", examItem.FunCode), new SqlParameter("@ParentId", examItem.ParentId) }; try { dbConnection.ExecuteNonQuery(sql); } catch (Exception) { } finally { dbConnection.Close(); } }
public void UpdateExamItem() { examItem = new ExamItem(); examItem.ItemCode = ItemCode; examItem.VoiceText = _ItemVoice; examItem.EndVoiceText = _ItemEndVoice; dataService.UpdateExamItemsVoice(examItem); }
private ExamItem BuildEntity(int moduleId, IHtmlElement item) { string selector = @"td[width]"; if (false == item.Exists(selector)) { return(null); } var id_element = item.FindFirst(selector); if (id_element == null) { return(null); } try { var match = Regex.Match(id_element.InnerText(), @"\d+"); int id = Convert.ToInt32(match.Value.ToString().Trim()); string title = id_element.Parent().FindFirst(@".MsoNormal>span").InnerText().Trim().RemoveHtml().RemoveHtmlEncode(); string answer = item.FindFirst("#answer").InnerText().Trim(); string strExamType = item.FindFirst(".st_title").InnerText(); string examType = Regex.Match(strExamType, @"(?<=、).*").Value.Trim(); if (answer.StartsWith("答案:")) { answer = answer.Substring(3).Trim(); } var itemType = ItemTypeService.GetByText(examType); if (itemType == null) { logger.Info(string.Format("未匹配的题目类别[{0}],ExamId=[{1}]", examType, id)); } var model = new ExamItem() { Id = id, Title = title, Answer = answer, OriginalHtml = item.InnerHtml(), Module_Id = moduleId, ItemType = itemType != null ? itemType.Id : 0, CreateTime = DateTime.Now, DelFlag = false }; return(model); } catch (Exception ex) { WriteLog(item.ToString(), ex.Message); throw; } }
public static ExamPaper CreateExamPaper(int paperID) { string sql = "select Fquestion, Fquestiontype, Foptionid, Fextendvalue from t_exam_questions where Fexampaperid = {0}"; sql = string.Format(sql, paperID); DataBase db = new DataBase(); DataSet dsQuestions; db.ExecuteSql(sql, null, out dsQuestions); int questionCount = dsQuestions.get_Tables().get_Item(0).get_Rows().get_Count(); if (questionCount <= 0) { throw new ApplicationException("该试卷还没有题目"); } ExamPaper paper = new ExamPaper(questionCount); paper.paperTitle = ExamPaper.GetPaperName(paperID); for (int i = 0; i < questionCount; i++) { ExamItem examItem = paper.examItems[i]; DataRow drQuestion = dsQuestions.get_Tables().get_Item(0).get_Rows().get_Item(i); examItem.question = drQuestion.get_Item("Fquestion").ToString(); examItem.type = drQuestion.get_Item("Fquestiontype").ToString(); examItem.extendValue = drQuestion.get_Item("Fextendvalue").ToString(); if (examItem.type == "RADIO" || examItem.type == "CHECK") { int optionid = int.Parse(drQuestion.get_Item("Foptionid").ToString()); sql = "select Foptionitemvalue from t_exam_options where Foptionid = {0} order by Foptionitemindex"; sql = string.Format(sql, optionid); DataSet dsOptions; db.ExecuteSql(sql, null, out dsOptions); int optionCount = dsOptions.get_Tables().get_Item(0).get_Rows().get_Count(); if (optionCount <= 0) { throw new ApplicationException("找不到问题的选项"); } examItem.options = new string[optionCount]; for (int j = 0; j < optionCount; j++) { DataRow drOption = dsOptions.get_Tables().get_Item(0).get_Rows().get_Item(j); examItem.options[j] = drOption.get_Item("Foptionitemvalue").ToString(); } } } return(paper); }
public string ToJSON() { string examItemsString = ""; for (int i = 0; i < this.examItems.Length; i++) { ExamItem examItem = this.examItems[i]; string optionsString = ""; if (examItem.options != null) { for (int j = 0; j < examItem.options.Length; j++) { string optionString = "'" + examItem.options[j] + "'"; if (j == 0) { optionsString = optionString; } else { optionsString = optionsString + "," + optionString; } } } optionsString = "[" + optionsString + "]"; string examItemString = string.Format("question:'{0}',type:'{1}',options:{2},extendValue:'{3}'", new object[] { examItem.question, examItem.type, optionsString, examItem.extendValue }); examItemString = "{" + examItemString + "}"; if (i == 0) { examItemsString = examItemString; } else { examItemsString = examItemsString + "," + examItemString; } } examItemsString = "[" + examItemsString + "]"; string examPaper = string.Format("paperTitle:'{0}',examItems:{1}", this.paperTitle, examItemsString); return("[{" + examPaper + "}]"); }
private ExamItem BuildEntity(int moduleId, IHtmlElement item) { try { var id_element = item.FindFirst(@"tr[valign]>td"); var match = Regex.Match(id_element.InnerText(), @"\d+"); int id = Convert.ToInt32(match.Value.Trim()); string title = id_element.NextElement().InnerText().Trim().RemoveHtml().RemoveHtmlEncode(); string answer = item.FindFirst("div[id]").InnerText().Trim().RemoveHtmlEncode(); string examType = item.PreviousElement().Descendants("td") .ElementAt(1) .InnerText().Trim().RemoveHtml().RemoveHtmlEncode(); if (answer.StartsWith("答案:")) { answer = answer.Substring(3).Trim(); } var itemType = ItemTypeService.GetByText(examType); if (itemType == null) { logger.Info(string.Format("未匹配的题目类别[{0}],ExamId=[{1}]", examType, id)); } var model = new ExamItem() { Id = id, Title = title, Answer = answer, OriginalHtml = item.InnerHtml(), Module_Id = moduleId, ItemType = itemType != null ? itemType.Id : 0, CreateTime = DateTime.Now, DelFlag = false }; return(model); } catch (Exception ex) { WriteLog(item.ToString(), ex.Message); throw; } }
public void update(ExamItem examItem) { String sql = "update examItem set Item=@Item,FunCode=@FunCode,ParentId=@ParentId where BaseKey=@BaseKey"; SqlParameter[] parameters = { new SqlParameter("@Item", examItem.Item), new SqlParameter("@FunCode", examItem.FunCode), new SqlParameter("@ParentId", examItem.ParentId), new SqlParameter("@BaseKey", examItem.BaseKey) }; try { dbConnection.ExecuteNonQuery(sql); } catch (Exception) { } finally { dbConnection.Close(); } }
public string ProcessItem(string userId, string userAnswer, ref ExamContext context, ref ExamInfo examInfo) { int index = context.processContext.index; context.stage = StageType.InProcess; ExamItem item = examInfo.items[index]; if (Utils.Utils.IsRegexMatched(item.answerRegex, userAnswer)) { context.processContext.index++; context.processContext.askbackTime = 0; context.processContext.collectedUserAnswer.Add(userAnswer); if (context.processContext.index == examInfo.items.Count) // Finished { string respStr = ""; if (examInfo.dispType == ExamItemAnswerDisplayType.OnebyOne) { respStr += GetReviewImmediately(userAnswer, item.answer, item.interpret) + "\r\n"; } respStr += "\r\n" + GetSummary(context.processContext, examInfo); context.stage = StageType.Completed; return(respStr); } else { string nextQuestion = examInfo.items[context.processContext.index].question; string respStr = ""; if (examInfo.dispType == ExamItemAnswerDisplayType.AllInSummary) { respStr += nextQuestion; } else if (examInfo.dispType == ExamItemAnswerDisplayType.OnebyOne) { respStr += GetReviewImmediately(userAnswer, item.answer, item.interpret) + "\r\n"; respStr += nextQuestion; } return(respStr); } } else { context.processContext.askbackTime++; if (context.processContext.askbackTime > examInfo.askBackLimitTimes) { string respStr = ""; switch (examInfo.quitType) { case QuitType.CachedWithoutSummry: respStr += examInfo.quitMessage; context.stage = StageType.Paused; break; case QuitType.DispatchedWithoutSummry: respStr += examInfo.quitMessage; context.stage = StageType.Completed; break; case QuitType.SummeryImmediately: respStr += examInfo.quitMessage + "\r\n"; respStr += GetSummary(context.processContext, examInfo); context.stage = StageType.Completed; break; } return(respStr); } else { return(item.askbackMessage + "\r\n" + item.question); } } }
public void delete(ExamItem examItem) { this.delete(examItem.BaseKey); }
public void UpdateExamItem(ExamItem item) { dataService.UpdateExamItemsVoice(item); }