Listen ICedts_ItemXMLRepository.Getlisten(string text, string type) { Listen listen = new Listen(); ItemBassInfo info = new ItemBassInfo(); doc = new XmlDocument(); doc.LoadXml(text); node = doc.SelectSingleNode("assessmentItem");//查找<assessmentItem>节点 elem = (XmlElement)node; info.ItemID = Guid.Parse(elem.GetAttribute("identifier")); info.Course = elem.GetAttribute("course"); info.Unit = elem.GetAttribute("unit"); XmlNodeList nodeList = node.ChildNodes;//<assessmentItem>下的所有子节点 if (type == "2") { info.QuestionCount = nodeList.Count; } else if (type == "5") { info.QuestionCount = nodeList.Count - 2; } else { info.QuestionCount = nodeList.Count - 1; } info.ItemType = type; info.PartType = "2"; info.AnswerResposn = "_"; info.QustionInterval = ""; info.QuestionID = new List <Guid>(); info.AnswerValue = new List <string>(); info.Tip = new List <string>(); info.Problem = new List <string>(); info.DifficultQuestion = new List <double>(); info.ScoreQuestion = new List <double>(); info.questionSound = new List <string>(); info.TimeQuestion = new List <double>(); info.timeInterval = new List <int>(); listen.Choices = new List <string>(); info.Score = 0.0; info.ReplyTime = 0.0; info.Diffcult = 0.0; switch (type) { #region 短对话听力 case "2": { info.ItemType_CN = "短对话听力"; for (int i = 0; i < nodeList.Count; i++) { XmlElement qElem = (XmlElement)nodeList[i]; //question节点 XmlNodeList qList = nodeList[i].ChildNodes; //question下的所有子节点 for (int j = 0; j < qList.Count; j++) { XmlElement pElem = (XmlElement)qList[j]; //question下的一个子节点 //判断节点名为prompt if (pElem.Name == "prompt") { XmlNodeList soundList = qList[j].ChildNodes; //prompt下的所有子节点 for (int k = 0; k < soundList.Count; k++) { XmlElement sElem = (XmlElement)soundList[k]; //prompt下的一个子节点 if (sElem.GetAttribute("src") != "") { info.QustionInterval = sElem.GetAttribute("duration"); string src = sElem.GetAttribute("src"); listen.SoundFile = src.Substring(0, src.LastIndexOf('.')); XmlNodeList scriptList = soundList[k].ChildNodes; //sound下的所有子节点 for (int m = 0; m < scriptList.Count; m++) { XmlElement tElem = (XmlElement)scriptList[m]; if (tElem.Name == "transcript") { listen.Script = tElem.InnerXml; } } } } } //判断节点名为choice if (pElem.Name == "choice") { XmlNodeList optionList = qList[j].ChildNodes; for (int k = 0; k < optionList.Count; k++) { XmlElement oElem = (XmlElement)optionList[k]; if (oElem.Name == "option") { listen.Choices.Add(oElem.InnerXml); } } } //判断节点名为key if (pElem.Name == "key") { string[] answers = { "A", "B", "C", "D" }; int temp = int.Parse(pElem.InnerXml) - 1; info.AnswerValue.Add(answers[temp]); } } info.questionSound.Add(""); info.timeInterval.Add(0); info.Tip.Add(""); info.Problem.Add(""); info.ScoreQuestion.Add(1); info.Score += 1; info.TimeQuestion.Add(1.0); info.ReplyTime += 1.0; info.DifficultQuestion.Add(0.2); info.Diffcult += 0.2; } info.Diffcult = info.Diffcult / info.QuestionCount; listen.Info = info; break; } #endregion #region 长对话听力 case "3": { info.ItemType_CN = "长对话听力"; for (int i = 0; i < nodeList.Count; i++) { if (i == 0) { XmlElement pElem = (XmlElement)nodeList[i]; //prompt节点 XmlNodeList soundList = nodeList[i].ChildNodes; for (int j = 0; j < soundList.Count; j++) { XmlElement sElem = (XmlElement)soundList[j]; if (sElem.Name == "sound" && sElem.GetAttribute("src") != "") { info.QustionInterval = sElem.GetAttribute("duration"); listen.SoundFile = sElem.GetAttribute("src").Substring(0, sElem.GetAttribute("src").LastIndexOf('.')); listen.Script = sElem.FirstChild.InnerXml; } } continue; } XmlElement qElem = (XmlElement)nodeList[i]; //question节点 XmlNodeList qList = nodeList[i].ChildNodes; //question下的所有子节点 for (int j = 0; j < qList.Count; j++) { XmlElement pElem = (XmlElement)qList[j]; //question下的一个子节点 //判断节点名为prompt if (pElem.Name == "prompt") { XmlNodeList soundList = qList[j].ChildNodes; //prompt下的所有子节点 for (int k = 0; k < soundList.Count; k++) { XmlElement sElem = (XmlElement)soundList[k]; //prompt下的一个子节点 if (sElem.GetAttribute("src") != "") { string src = sElem.GetAttribute("src"); info.questionSound.Add(src.Substring(0, src.LastIndexOf('.'))); info.timeInterval.Add(int.Parse(sElem.GetAttribute("duration"))); XmlNodeList scriptList = soundList[k].ChildNodes; //sound下的所有子节点 for (int m = 0; m < scriptList.Count; m++) { XmlElement tElem = (XmlElement)scriptList[m]; if (tElem.Name == "transcript") { info.Problem.Add(tElem.InnerXml); } } } } } //判断节点名为choice if (pElem.Name == "choice") { XmlNodeList optionList = qList[j].ChildNodes; for (int k = 0; k < optionList.Count; k++) { XmlElement oElem = (XmlElement)optionList[k]; if (oElem.Name == "option") { listen.Choices.Add(oElem.InnerXml); } } } //判断节点名为key if (pElem.Name == "key") { string[] answers = { "A", "B", "C", "D" }; int temp = int.Parse(pElem.InnerXml) - 1; info.AnswerValue.Add(answers[temp]); } } info.Tip.Add(""); info.ScoreQuestion.Add(1); info.Score += 1; info.TimeQuestion.Add(1.0); info.ReplyTime += 1.0; info.DifficultQuestion.Add(0.2); info.Diffcult += 0.2; } info.Diffcult = info.Diffcult / info.QuestionCount; listen.Info = info; break; } #endregion #region 听力短文理解 case "4": { info.ItemType_CN = "听力短文理解"; for (int i = 0; i < nodeList.Count; i++) { if (i == 0) { XmlElement pElem = (XmlElement)nodeList[i]; //prompt节点 XmlNodeList soundList = nodeList[i].ChildNodes; for (int j = 0; j < soundList.Count; j++) { XmlElement sElem = (XmlElement)soundList[j]; if (sElem.Name == "sound" && sElem.GetAttribute("src") != "") { info.QustionInterval = sElem.GetAttribute("duration"); listen.SoundFile = sElem.GetAttribute("src").Substring(0, sElem.GetAttribute("src").LastIndexOf('.')); listen.Script = sElem.FirstChild.InnerXml; } } continue; } XmlElement qElem = (XmlElement)nodeList[i]; //question节点 XmlNodeList qList = nodeList[i].ChildNodes; //question下的所有子节点 for (int j = 0; j < qList.Count; j++) { XmlElement pElem = (XmlElement)qList[j]; //question下的一个子节点 //判断节点名为prompt if (pElem.Name == "prompt") { XmlNodeList soundList = qList[j].ChildNodes; //prompt下的所有子节点 for (int k = 0; k < soundList.Count; k++) { XmlElement sElem = (XmlElement)soundList[k]; //prompt下的一个子节点 if (sElem.GetAttribute("src") != "") { string src = sElem.GetAttribute("src"); info.questionSound.Add(src.Substring(0, src.LastIndexOf('.'))); info.timeInterval.Add(int.Parse(sElem.GetAttribute("duration"))); XmlNodeList scriptList = soundList[k].ChildNodes; //sound下的所有子节点 for (int m = 0; m < scriptList.Count; m++) { XmlElement tElem = (XmlElement)scriptList[m]; if (tElem.Name == "transcript") { info.Problem.Add(tElem.InnerXml); } } } } } //判断节点名为choice if (pElem.Name == "choice") { XmlNodeList optionList = qList[j].ChildNodes; for (int k = 0; k < optionList.Count; k++) { XmlElement oElem = (XmlElement)optionList[k]; if (oElem.Name == "option") { listen.Choices.Add(oElem.InnerXml); } } } //判断节点名为key if (pElem.Name == "key") { string[] answers = { "A", "B", "C", "D" }; int temp = int.Parse(pElem.InnerXml) - 1; info.AnswerValue.Add(answers[temp]); } } info.Tip.Add(""); info.ScoreQuestion.Add(1); info.Score += 1; info.TimeQuestion.Add(1.0); info.ReplyTime += 1.0; info.DifficultQuestion.Add(0.2); info.Diffcult += 0.2; } info.Diffcult = info.Diffcult / info.QuestionCount; listen.Info = info; break; } #endregion #region 合型听力 default: { info.ItemType_CN = "复合型听力"; for (int i = 0; i < nodeList.Count - 1; i++) { if (i == 0) { XmlElement pElem = (XmlElement)nodeList[i]; //prompt节点 XmlNodeList soundList = nodeList[i].ChildNodes; for (int j = 0; j < soundList.Count; j++) { XmlElement sElem = (XmlElement)soundList[j]; if (sElem.Name == "sound" && sElem.GetAttribute("src") != "") { info.QustionInterval = sElem.GetAttribute("duration"); listen.SoundFile = sElem.GetAttribute("src").Substring(0, sElem.GetAttribute("src").LastIndexOf('.')); } if (sElem.Name == "text") { int a = 0; while (sElem.InnerXml.IndexOf("<tag type=\"text\" />") > 0) { a++; int index = sElem.InnerXml.IndexOf("<tag type=\"text\" />"); int length = "<tag type=\"text\" />".Length; sElem.InnerXml = sElem.InnerXml.Substring(0, index) + "(_" + a + "_)" + sElem.InnerXml.Substring(index + length); } listen.Script = sElem.InnerXml; } } continue; } XmlElement qElem = (XmlElement)nodeList[i]; //question节点 XmlNodeList qList = nodeList[i].ChildNodes; //question下的所有子节点 for (int j = 0; j < qList.Count; j++) { XmlElement pElem = (XmlElement)qList[j]; //question下的一个子节点 //判断节点名为key if (pElem.Name == "key") { info.AnswerValue.Add(pElem.InnerXml); } } info.questionSound.Add(""); info.timeInterval.Add(0); info.Tip.Add(""); info.Problem.Add(""); info.ScoreQuestion.Add(1); info.Score += 1; info.TimeQuestion.Add(1.0); info.ReplyTime += 1.0; info.DifficultQuestion.Add(0.2); info.Diffcult += 0.2; } info.Diffcult = info.Diffcult / info.QuestionCount; listen.Info = info; break; } #endregion } return(listen); }
Listen ICedts_AssignRepository.SelectListen(Guid item) { var Assigns = (from As in db.CEDTS_Assign where As.AssessmentItemID == item orderby As.Time descending select As.QuestionID).FirstOrDefault(); if (Assigns == null) { return(null); } else { string[] Assign = Assigns.Split(','); var question1 = (from m in db.CEDTS_Question where m.AssessmentItemID == item orderby m.Order ascending select m).ToList(); var question = (from m in db.CEDTS_Question where m.AssessmentItemID == item orderby m.Order ascending select m).ToList(); var assess = (from m in db.CEDTS_AssessmentItem where m.AssessmentItemID == item select m).First(); List <Guid> QID = new List <Guid>(); int Count = 0; for (int s = 0; s < Assign.Length; s++) { QID.Add(Guid.Parse(Assign[s])); } foreach (var q in question1) { if (!QID.Contains(q.QuestionID)) { question.Remove(q); if (Count == 0) { Count = assess.QuestionCount.Value - 1; } else { Count = Count - 1; } } } if (Count == 0) { Count = assess.QuestionCount.Value; } var Itemtype = (from m in db.CEDTS_ItemType where m.ItemTypeID == assess.ItemTypeID select m).First(); var PartType = (from m in db.CEDTS_PartType where m.PartTypeID == Itemtype.PartTypeID select m).First(); ItemBassInfo info = new ItemBassInfo(); info.AnswerValue = new List <string>(); info.Problem = new List <string>(); info.Tip = new List <string>(); info.QuestionID = new List <Guid>(); info.DifficultQuestion = new List <double>(); info.ScoreQuestion = new List <double>(); Listen listen = new Listen(); info.Knowledge = new List <string>(); info.KnowledgeID = new List <string>(); listen.Choices = new List <string>(); info.TimeQuestion = new List <double>(); info.ItemID = item; info.Count = Convert.ToInt32(assess.Count); info.ItemType = Itemtype.TypeName; info.ItemType_CN = Itemtype.TypeName_CN; info.PartType = PartType.TypeName; info.QuestionCount = Convert.ToInt32(question.Count); info.ReplyTime = Convert.ToInt32(assess.Duration); info.Diffcult = Convert.ToDouble(assess.Difficult); info.Score = Convert.ToInt32(assess.Score); listen.Script = assess.Original; listen.SoundFile = item.ToString(); string QkID = null; foreach (var qu in question) { var QkList = (from m in db.CEDTS_QuestionKnowledge where m.QuestionID == qu.QuestionID orderby m.Weight ascending select m.QuestionKnowledgeID).ToList(); foreach (var q in QkList) { QkID += q + ","; } } QkID = QkID.Substring(0, QkID.LastIndexOf(",")); info.QuestionKnowledgeID = QkID; foreach (var list in question) { info.QuestionID.Add(list.QuestionID); info.Problem.Add(list.QuestionContent); info.ScoreQuestion.Add(list.Score.Value); info.TimeQuestion.Add(list.Duration.Value); info.DifficultQuestion.Add(list.Difficult.Value); listen.Choices.Add(list.ChooseA); listen.Choices.Add(list.ChooseB); listen.Choices.Add(list.ChooseC); listen.Choices.Add(list.ChooseD); info.AnswerValue.Add(list.Answer); info.Tip.Add(list.Analyze); string name = string.Empty; string id = string.Empty; var KnowledgeList = (from m in db.CEDTS_QuestionKnowledge where m.QuestionID == list.QuestionID orderby m.Weight ascending select m.KnowledgePointID).ToList(); foreach (var Knowledge in KnowledgeList) { var KnowledgeName = (from m in db.CEDTS_KnowledgePoints where m.KnowledgePointID == Knowledge select m).First(); id += KnowledgeName.KnowledgePointID + ","; name += KnowledgeName.Title + ","; } name = name.Substring(0, name.LastIndexOf(",")); id = id.Substring(0, id.LastIndexOf(',')); info.KnowledgeID.Add(id); info.Knowledge.Add(name); } listen.Info = info; return(listen); } }
List <Listen> ICedts_TemporaryPaperRepository.SelectEditLpc(Guid id, int UserID) { List <Listen> LpcList = new List <Listen>(); var AssmentIDList = (from m in db.CEDTS_TemporaryPaperAssessment where m.PaperID == id && m.ItemTypeID == 5 orderby m.Weight ascending select m.AssessmentItemID).ToList(); foreach (var AssessID in AssmentIDList) { var question = (from m in db.CEDTS_TemporaryQuestion where m.AssessmentItemID == AssessID orderby m.Order ascending select m).ToList(); var Assess = (from m in db.CEDTS_TemporaryAssessmentItem where m.AssessmentItemID == AssessID select m).FirstOrDefault(); Listen Lpc = new Listen(); ItemBassInfo info = new ItemBassInfo(); info.AnswerValue = new List <string>(); info.Problem = new List <string>(); info.Tip = new List <string>(); info.QuestionID = new List <Guid>(); info.DifficultQuestion = new List <double>(); info.ScoreQuestion = new List <double>(); info.Knowledge = new List <string>(); info.KnowledgeID = new List <string>(); info.TimeQuestion = new List <double>(); info.questionSound = new List <string>(); info.timeInterval = new List <int>(); info.QustionInterval = Assess.Interval.ToString(); info.ItemID = AssessID.Value; info.Count = Assess.Count.Value; info.ItemType = "5"; info.ItemType_CN = "复合型听力"; info.PartType = "2"; info.QuestionCount = Assess.QuestionCount.Value; info.ReplyTime = Assess.Duration.Value; info.Diffcult = Assess.Difficult.Value; info.Score = Assess.Score.Value; Lpc.Script = Assess.Original; Lpc.SoundFile = AssessID.ToString(); string QkID = null; if (UserID == 1) { foreach (var qu in question) { var QkList = (from m in db.CEDTS_TemporaryQuestionKnowledge where m.QuestionID == qu.QuestionID orderby m.Weight ascending select m.QuestionKnowledgeID).ToList(); foreach (var q in QkList) { QkID += q + ","; } } QkID = QkID.Substring(0, QkID.LastIndexOf(",")); } info.QuestionKnowledgeID = QkID; foreach (var list in question) { info.QuestionID.Add(list.QuestionID); info.Problem.Add(list.QuestionContent); info.ScoreQuestion.Add(list.Score.Value); info.TimeQuestion.Add(list.Duration.Value); info.DifficultQuestion.Add(list.Difficult.Value); info.AnswerValue.Add(list.Answer); info.questionSound.Add(list.Sound); info.timeInterval.Add(list.Interval.Value); info.Tip.Add(list.Analyze); if (UserID == 1) { string name = string.Empty; string Qkid = string.Empty; var KnowledgeList = (from m in db.CEDTS_TemporaryQuestionKnowledge where m.QuestionID == list.QuestionID orderby m.Weight ascending select m.KnowledgePointID).ToList(); foreach (var Knowledge in KnowledgeList) { var KnowledgeName = (from m in db.CEDTS_KnowledgePoints where m.KnowledgePointID == Knowledge select m).First(); Qkid += KnowledgeName.KnowledgePointID + ","; name += KnowledgeName.Title + ","; } name = name.Substring(0, name.LastIndexOf(",")); Qkid = Qkid.Substring(0, Qkid.LastIndexOf(',')); info.KnowledgeID.Add(Qkid); info.Knowledge.Add(name); } } Lpc.Info = info; LpcList.Add(Lpc); } return(LpcList); }