/// <summary> /// 绑定选择题子项的列表 /// </summary> private void bindGrid(Song.Entities.Questions q) { //最多几项 int maxItem = 8; Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(q, null); List <Song.Entities.QuesAnswer> list = new List <QuesAnswer>(); for (int i = 0; i < maxItem; i++) { if (ans != null && i < ans.Length) { list.Add(ans[i]); } else { Song.Entities.QuesAnswer t = new QuesAnswer(); t.Ans_ID = -1; t.Qus_UID = getUID(); list.Add(t); } } gvAnswer.DataSource = list; gvAnswer.DataKeyNames = new string[] { "Ans_ID" }; gvAnswer.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { query = this.ClientQueryString; //if (string.IsNullOrWhiteSpace(query)) //如果是新增(id大于0),但又没有指定试题类型,则查询当前试题的类型 if (string.IsNullOrWhiteSpace(type) && id > 0) { Song.Entities.Questions entity = Business.Do <IQuestions>().QuesSingle(id); type = entity.Qus_Type.ToString(); } //如果类型指定了,则转向编辑页 if (!string.IsNullOrWhiteSpace(type)) { string goUrl = "Questions_Input{0}.aspx?type={0}&" + this.ClientQueryString; this.Response.Redirect(string.Format(goUrl, type, id)); } //如果不是新增(id小于1),但又没有指定试题类型,输出类型,让用户自己选择 if (string.IsNullOrWhiteSpace(type) && id < 1) { //题型分类汉字名称 string[] typeStr = App.Get["QuesType"].Split(','); rptTypes.DataSource = typeStr; rptTypes.DataBind(); } }
private void fill() { if (id < 1) { return; } mm = Business.Do <IQuestions>().QuesSingle(id); ltTitle.Text = Extend.Html.ClearHTML(mm.Qus_Title, "pre", "p"); //知识点解析 ltExplan.Text = mm.Qus_Explain == string.Empty ? "无" : mm.Qus_Explain; ltExplan.Text = Extend.Html.ClearHTML(ltExplan.Text, "pre", "p"); if (mm.Qus_Type == 1) { getAnswer1(mm); } if (mm.Qus_Type == 2) { getAnswer2(mm); } if (mm.Qus_Type == 3) { getAnswer3(mm); } if (mm.Qus_Type == 4) { getAnswer4(mm); } if (mm.Qus_Type == 5) { getAnswer5(mm); } }
/// <summary> /// 处理试题中的文本内容 /// </summary> /// <param name="qs"></param> /// <returns></returns> private Song.Entities.Questions replaceText(Song.Entities.Questions qs) { qs.Qus_Title = qs.Qus_Title == null ? "" : qs.Qus_Title; qs.Qus_Title = qs.Qus_Title.Replace("\r", ""); qs.Qus_Title = qs.Qus_Title.Replace("\n", ""); qs.Qus_Title = qs.Qus_Title.Replace("\"", """); qs.Qus_Title = qs.Qus_Title.Replace("\t", ""); // qs.Qus_Explain = qs.Qus_Explain == null ? "" : qs.Qus_Explain; if (qs.Qus_Explain != string.Empty) { qs.Qus_Explain = qs.Qus_Explain.Replace("\r", ""); qs.Qus_Explain = qs.Qus_Explain.Replace("\n", ""); qs.Qus_Explain = qs.Qus_Explain.Replace("\"", """); qs.Qus_Explain = qs.Qus_Title.Replace("\t", ""); } // if (qs.Qus_Answer != string.Empty) { qs.Qus_Answer = qs.Qus_Answer == null ? "" : qs.Qus_Answer; qs.Qus_Answer = qs.Qus_Answer.Replace("\r", ""); qs.Qus_Answer = qs.Qus_Answer.Replace("\n", ""); qs.Qus_Answer = qs.Qus_Answer.Replace("\"", """); qs.Qus_Answer = qs.Qus_Title.Replace("\t", ""); } return(qs); }
/// <summary> /// 如果已经提交过答案,通过提交的答题返回试题 /// </summary> /// <param name="exr"></param> /// <returns></returns> private string resultJson(Song.Entities.ExamResults exr) { XmlDocument resXml = new XmlDocument(); resXml.LoadXml(exr.Exr_Results, false); string json = "["; XmlNodeList ques = resXml.GetElementsByTagName("ques"); for (int i = 0; i < ques.Count; i++) { XmlNode node = ques[i]; string type = node.Attributes["type"].Value; string count = node.Attributes["count"].Value; string num = node.Attributes["number"].Value; string quesObj = "{"; quesObj += "'type':'" + type + "','count':'" + count + "','number':'" + num + "',"; quesObj += "'ques':["; quesObj = quesObj.Replace("'", "\""); for (int n = 0; n < node.ChildNodes.Count; n++) { int id = Convert.ToInt32(node.ChildNodes[n].Attributes["id"].Value); Song.Entities.Questions q = null; q = Business.Do <IQuestions>().QuesSingle4Cache(id); if (q == null) { q = Business.Do <IQuestions>().QuesSingle(id); } if (q == null) { continue; } q.Qus_Number = (float)Convert.ToDouble(node.ChildNodes[n].Attributes["num"].Value); q.Qus_Explain = ""; q.Qus_Answer = ""; string js = getQuesJson(q); //如果是单选题,或多选题,或填空题 if (q.Qus_Type == 1 || q.Qus_Type == 2 || q.Qus_Type == 5) { quesObj += getAnserJson(q, js); } else { quesObj += js; } if (n < node.ChildNodes.Count - 1) { quesObj += ","; } } quesObj += "]"; quesObj += "}"; if (i < ques.Count - 1) { quesObj += ","; } json += quesObj; } json += "]"; return(json); }
/// <summary> /// 返回当前大题下的试题 /// </summary> /// <param name="id">试题分类</param> /// <returns></returns> private List <Song.Entities.Questions> getQues(object[] id) { int type = 0; if (id.Length > 0 && id[0] is int) { type = Convert.ToInt32(id[0]); } List <Song.Entities.Questions> list = new List <Entities.Questions>(); XmlNode root = resXml.LastChild; XmlNodeList quesNodes = root.ChildNodes; for (int i = 0; i < quesNodes.Count; i++) { int tp = Convert.ToInt32(quesNodes[i].Attributes["type"].Value); if (tp == type) { //小题的节点 XmlNodeList qnode = quesNodes[i].ChildNodes; for (int j = 0; j < qnode.Count; j++) { int qid = Convert.ToInt32(qnode[j].Attributes["id"].Value); Song.Entities.Questions ques = Business.Do <IQuestions>().QuesSingle(qid); if (ques != null) { ques = Extend.Questions.TranText(ques); ques.Qus_Title = Extend.Html.ClearHTML(ques.Qus_Title, "pre", "p"); ques.Qus_Explain = Extend.Html.ClearHTML(ques.Qus_Explain, "pre", "p"); list.Add(ques); } } } } return(list); }
void fill() { Song.Entities.Questions mm; if (id != 0) { mm = Business.Do <IQuestions>().QuesSingle(id, false); cbIsUse.Checked = mm.Qus_IsUse; //唯一标识 ViewState["UID"] = mm.Qus_UID; //所属专业、课程、章节 SortSelect1.SbjID = mm.Sbj_ID; SortSelect1.CouID = mm.Cou_ID; SortSelect1.OlID = mm.Ol_ID; //难度 ListItem liDiff = ddlDiff.Items.FindByValue(mm.Qus_Diff.ToString()); if (liDiff != null) { ddlDiff.SelectedIndex = -1; liDiff.Selected = true; } //相关资料 if (mm.Kn_ID > 0) { Song.Entities.Knowledge kn = Business.Do <IKnowledge>().KnowledgeSingle((int)mm.Kn_ID); if (kn != null) { ListItem liKns = ddlKnlSort.Items.FindByValue(kn.Kns_ID.ToString()); if (liKns != null) { liKns.Selected = true; } knTitle.InnerText = kn.Kn_Title; tbKnTit.Text = kn.Kn_Title; tbKnID.Text = kn.Kn_ID.ToString(); } } //错误信息 ltErrorInfo.Text = mm.Qus_ErrorInfo; errorInfo.Visible = mm.Qus_IsError; //错误提告 ltWrongInfo.Text = mm.Qus_WrongInfo; wrongInfo.Visible = mm.Qus_IsWrong; } else { //如果是新增 mm = new Song.Entities.Questions(); ViewState["UID"] = WeiSha.Common.Request.UniqueID(); tbKnID.Text = "0"; } //题干 tbTitle.Text = mm.Qus_Title; //讲解 tbExplan.Text = mm.Qus_Explain; //排序号 tbTax.Text = mm.Qus_Tax.ToString(); //试题答案 bindGrid(mm); }
/// <summary> /// 显示试题正确答案 /// </summary> /// <param name="p"></param> /// <returns></returns> private string getSucessAnswer(object[] p) { Song.Entities.Questions qus = null; if (p.Length > 0) { qus = (Song.Entities.Questions)p[0]; } if (qus == null) { return(""); } string ansStr = ""; if (qus.Qus_Type == 1) { //当前试题的答案 Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(qus, null); for (int i = 0; i < ans.Length; i++) { if (ans[i].Ans_IsCorrect) { ansStr += (char)(65 + i); } } } if (qus.Qus_Type == 2) { Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(qus, null); for (int i = 0; i < ans.Length; i++) { if (ans[i].Ans_IsCorrect) { ansStr += (char)(65 + i) + "、"; } } ansStr = ansStr.Substring(0, ansStr.LastIndexOf("、")); } if (qus.Qus_Type == 3) { ansStr = qus.Qus_IsCorrect ? "正确" : "错误"; } if (qus.Qus_Type == 4) { if (qus != null && !string.IsNullOrEmpty(qus.Qus_Answer)) { ansStr = qus.Qus_Answer; } } if (qus.Qus_Type == 5) { //当前试题的答案 Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(qus, null); for (int i = 0; i < ans.Length; i++) { ansStr += (char)(65 + i) + "、" + ans[i].Ans_Context + " "; } } return(ansStr); }
/// <summary> /// 获取判断题答案 /// </summary> /// <param name="qus"></param> private void getAnswer3(Song.Entities.Questions qus) { string ansStr = qus.Qus_IsCorrect ? "正确" : "错误"; ltAnswerWord.Text = ansStr; divAnswerWord.Visible = true; divAnswerText.Visible = false; }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEnter_Click(object sender, EventArgs e) { Song.Entities.Questions mm = null; if (id != 0) { mm = Business.Do <IQuestions>().QuesSingle(id); } else { //如果是新增 mm = new Song.Entities.Questions(); } //题型、学科、题干 mm.Qus_Type = this.type == 0 ? ddlType.SelectedIndex + 1 : this.type; mm.Qus_IsUse = cbIsUse.Checked; mm.Sbj_ID = SortSelect1.SbjID; mm.Sbj_Name = SortSelect1.SbjName; mm.Cou_ID = SortSelect1.CouID; mm.Ol_ID = SortSelect1.OlID; // mm.Qus_Title = tbTitle.Text.Trim(); //难度 mm.Qus_Diff = Convert.ToInt32(ddlDiff.SelectedItem.Value); //答案 mm.Qus_IsCorrect = Convert.ToBoolean(rblIsCorrect.SelectedValue); //资料、讲解 if (tbKnID.Text != string.Empty) { mm.Kn_ID = Convert.ToInt32(tbKnID.Text); } mm.Qus_Explain = tbExplain.Text.Trim(); //UID mm.Qus_UID = getUID(); //是否处理报错信息 if (cbWrong.Checked) { mm.Qus_IsWrong = false; } //确定操作 try { if (id == 0) { id = Business.Do <IQuestions>().QuesAdd(mm); } else { Business.Do <IQuestions>().QuesSave(mm); } Master.AlertCloseAndRefresh("操作成功!"); } catch (Exception ex) { Master.Alert(ex.Message); } }
/// <summary> /// 获取简答题答案 /// </summary> /// <param name="qus"></param> private void getAnswer4(Song.Entities.Questions qus) { if (qus != null && !string.IsNullOrEmpty(qus.Qus_Answer)) { ltAnswerText.Text = qus.Qus_Answer; } divAnswerWord.Visible = false; divAnswerText.Visible = true; }
/// <summary> /// 修改是否显示的状态 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void sbUse_Click(object sender, EventArgs e) { StateButton ub = (StateButton)sender; int index = ((GridViewRow)(ub.Parent.Parent)).RowIndex; int id = int.Parse(this.GridView1.DataKeys[index].Value.ToString()); // Song.Entities.Questions entity = Business.Do <IQuestions>().QuesSingle(id); entity.Qus_IsUse = !entity.Qus_IsUse; Business.Do <IQuestions>().QuesSave(entity); BindData(null, null); }
/// <summary> /// 从缓存中更新试题 /// </summary> /// <param name="qid"></param> /// <returns></returns> public void UpdateSingle(Song.Entities.Questions ques) { for (int i = 0; i < list.Count; i++) { for (int j = 0; j < list[i].Questions.Count; j++) { if (ques.Qus_ID == list[i].Questions[j].Qus_ID) { list[i].Questions[j] = ques; } } } }
/// <summary> /// 获取填空题答案 /// </summary> /// <param name="qusUid"></param> private void getAnswer5(Song.Entities.Questions qus) { string ansStr = ""; //当前试题的答案 Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(qus, null); for (int i = 0; i < ans.Length; i++) { ansStr += ans[i].Ans_Context + "<br/>"; } ltAnswerWord.Text = ansStr; divAnswerWord.Visible = true; divAnswerText.Visible = false; }
/// <summary> /// 输出主式题的Json /// </summary> /// <param name="q"></param> /// <returns></returns> private string getQuesJson(Song.Entities.Questions q) { q = quesClear(q); q = Extend.Questions.TranText(q); //处理文件 q.Qus_Title = q.Qus_Title.Replace("\"", """); //转换双引号 string quesJs = q.ToJson("Qus_ID,Qus_Title,Qus_Diff,Qus_Type,Qus_UID,Qus_Number", null); //如果是单选题,或多选题,或填空题 if (q.Qus_Type == 1 || q.Qus_Type == 2 || q.Qus_Type == 5) { quesJs = getAnserJson(q, quesJs); } return(quesJs); }
//获取当前学科下的所有试卷 protected void Page_Load(object sender, EventArgs e) { Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent(); EmpAccount currentUser = Extend.LoginState.Admin.CurrentUser; if (currentUser == null) { Response.Write(""); Response.End(); return; } //当前员所处的学科 Song.Entities.Team team = Business.Do <ITeam>().TeamSingle((int)currentUser.Team_ID); if (team != null) { sbjid = (int)team.Sbj_ID; } //员工选择的每日一练的学科范围 string sel = Business.Do <ISystemPara>()["SubjectForAccout_" + currentUser.Acc_Id].String; string[] arr = sel.Split(','); if (arr.Length > 0) { arr[arr.Length - 1] = sbjid.ToString(); } //随机抽取学科 if (arr.Length > 1) { Random rand = new Random(); int index = rand.Next(0, arr.Length - 1); sbjid = Convert.ToInt32(arr[index]); } Song.Entities.Questions[] ques = Business.Do <IQuestions>().QuesRandom(org.Org_ID, sbjid, -1, -1, type, diff, diff, true, 1); string tm = ""; if (ques.Length > 0) { Song.Entities.Questions q = ques[0]; q = replaceText(q); tm = q.ToJson(); //如果是单选题,或多选题 if (q.Qus_Type == 1 || q.Qus_Type == 2 || q.Qus_Type == 5) { tm = getAnserJson(q, tm); } } Response.Write(tm); Response.End(); }
/// <summary> /// 处理试题内容 /// </summary> /// <param name="ques"></param> /// <returns></returns> private Song.Entities.Questions quesClear(Song.Entities.Questions ques) { if (ques == null) { return(ques); } ques.Qus_Title = ques.Qus_Title.Replace("<", "<"); ques.Qus_Title = ques.Qus_Title.Replace(">", ">"); ques.Qus_Title = ques.Qus_Title.Replace("{", "{"); ques.Qus_Title = ques.Qus_Title.Replace("}", "}"); ques.Qus_Title = ques.Qus_Title.Replace("\n", "<br/>"); ques.Qus_Title = ques.Qus_Title.Replace("\r", "<br/>"); //ques.Qus_Title = ques.Qus_Title.Replace(" ", " "); ques.Qus_Title = Extend.Html.ClearHTML(ques.Qus_Title, "p", "div", "font", "pre"); return(ques); }
/// <summary> /// 当前试题的选项,仅用于单选与多选 /// </summary> /// <returns>0为没有子级,其它有子级</returns> protected object AnswerItems(object[] p) { Song.Entities.Questions qus = null; if (p.Length > 0) { qus = (Song.Entities.Questions)p[0]; } //当前试题的答案 Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(qus, null); for (int i = 0; i < ans.Length; i++) { ans[i] = Extend.Questions.TranText(ans[i]); //ans[i].Ans_Context = ans[i].Ans_Context.Replace("<", "<"); //ans[i].Ans_Context = ans[i].Ans_Context.Replace(">", ">"); } return(ans); }
protected void lbUse_Click(object sender, EventArgs e) { string keys = GridView1.GetKeyValues; foreach (string id in keys.Split(',')) { if (string.IsNullOrEmpty(id)) { continue; } int tmid = Convert.ToInt16(id); Song.Entities.Questions entity = Business.Do <IQuestions>().QuesSingle(tmid); entity.Qus_IsUse = true; Business.Do <IQuestions>().QuesSave(entity); } BindData(null, null); }
private string getAnserJson(Song.Entities.Questions q, string json) { //当前试题的答案 Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(q, null); string ansStr = "["; for (int i = 0; i < ans.Length; i++) { ansStr += ans[i].ToJson(); if (i < ans.Length - 1) { ansStr += ","; } } ansStr += "]"; json = json.Replace("}", ",\"Answer\":" + ansStr + "}"); return(json); }
/// <summary> /// 获取试题的答案选项 /// </summary> /// <param name="id">uid</param> /// <returns></returns> private List <Song.Entities.QuesAnswer> getItems(object[] p) { Song.Entities.Questions qus = null; if (p.Length > 0) { qus = (Song.Entities.Questions)p[0]; } //当前试题的答案 Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(qus, null); List <Song.Entities.QuesAnswer> list = new List <Entities.QuesAnswer>(); for (int i = 0; i < ans.Length; i++) { ans[i] = Extend.Questions.TranText(ans[i]); list.Add(ans[i]); } return(list); }
/// <summary> /// 获取多选题答案 /// </summary> /// <param name="qus"></param> private void getAnswer2(Song.Entities.Questions qus) { string ansStr = ""; //当前试题的答案 Song.Entities.QuesAnswer[] ans = Business.Do <IQuestions>().QuestionsAnswer(qus, null); for (int i = 0; i < ans.Length; i++) { if (ans[i].Ans_IsCorrect) { ansStr += (char)(65 + i) + "、"; } } ansStr = ansStr.Substring(0, ansStr.LastIndexOf("、")); ltAnswerWord.Text = ansStr; divAnswerWord.Visible = true; divAnswerText.Visible = false; rptItem.DataSource = ans; rptItem.DataBind(); }
//获取当前学科下的所有试卷 protected void Page_Load(object sender, EventArgs e) { Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent(); Song.Entities.Questions[] ques = Business.Do <IQuestions>().QuesRandom(org.Org_ID, sbjid, -1, -1, type, diff, diff, true, 1); string tm = ""; if (ques.Length > 0) { Song.Entities.Questions q = ques[0]; q = replaceText(q); tm = q.ToJson(); //如果是单选题,或多选题 if (q.Qus_Type == 1 || q.Qus_Type == 2 || q.Qus_Type == 5) { tm = getAnserJson(q, tm); } } Response.Write(tm); Response.End(); }
/// <summary> /// 将某一行数据加入到数据库 /// </summary> /// <param name="dr"></param> /// <param name="dl"></param> private void _inputData(DataRow dr) { Song.Entities.Questions obj = new Song.Entities.Questions(); obj.Qus_IsUse = true; obj.Qus_Type = this.type; //正确答案 int correct = 0; foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //Excel的列的值 string column = dr[rel.Key].ToString(); //数据库字段的名称 string field = rel.Value; if (field == "Qus_ID") { if (string.IsNullOrEmpty(column) || column.Trim() == "") { continue; } int ques = Convert.ToInt32(column); Song.Entities.Questions isHavObj = Business.Do <IQuestions>().QuesSingle(ques); if (isHavObj != null) { obj = isHavObj; } } //题干难度、专业、试题讲解 if (field == "Qus_Title") { if (column == string.Empty || column.Trim() == "") { return; } obj.Qus_Title = column; obj.Qus_Title = tranTxt(obj.Qus_Title); } if (field == "Qus_Diff") { obj.Qus_Diff = Convert.ToInt16(column); } if (field == "Sbj_Name") { Song.Entities.Subject subject = Business.Do <ISubject>().SubjectBatchAdd(org.Org_ID, column); if (subject != null) { obj.Sbj_Name = subject.Sbj_Name; obj.Sbj_ID = subject.Sbj_ID; } } if (field == "Cou_Name") { Song.Entities.Course course = Business.Do <ICourse>().CourseBatchAdd(org.Org_ID, obj.Sbj_ID, column); if (course != null) { obj.Cou_ID = course.Cou_ID; } } if (field == "Ol_Name") { Song.Entities.Outline outline = Business.Do <IOutline>().OutlineBatchAdd(org.Org_ID, obj.Sbj_ID, obj.Cou_ID, column); if (outline != null) { obj.Ol_ID = outline.Ol_ID; } } if (field == "Qus_Explain") { obj.Qus_Explain = column; } //唯一值,正确答案,类型 obj.Qus_UID = WeiSha.Common.Request.UniqueID(); if (field == "Ans_IsCorrect") { if (new Regex(@"^\d+$", RegexOptions.Multiline).Match(column).Success) { correct = column == string.Empty ? 0 : Convert.ToInt32(column); } } } //再遍历一遍,取答案 List <Song.Entities.QuesAnswer> ansItem = new List <QuesAnswer>(); foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //数据库字段的名称 string field = rel.Value; Match match = new Regex(@"(Ans_Context)(\d+)").Match(field); if (match.Success) { //Excel的列的值 string column = dr[rel.Key].ToString(); if (column == string.Empty || column.Trim() == "") { continue; } int index = Convert.ToInt16(match.Groups[2].Value); Song.Entities.QuesAnswer ans = new Song.Entities.QuesAnswer(); ans.Ans_Context = column; ans.Ans_IsCorrect = index == correct; ans.Qus_UID = obj.Qus_UID; ansItem.Add(ans); } } //判断是否有错 string error = ""; if (ansItem.Count < 1) { error = "缺少答案选项"; } if (correct < 1 || correct > ansItem.Count) { error = string.Format("正确答案的设置不正确,共{0}个答案选项,不能设置为{1}", ansItem.Count, correct); } obj.Qus_IsError = error != ""; obj.Qus_ErrorInfo = error; if (obj.Sbj_ID == 0) { throw new Exception("当前试题所属专业并不存在"); } if (obj.Cou_ID == 0) { throw new Exception("当前试题所在课程并不存在"); } //if (obj.Ol_ID == 0) throw new Exception("当前试题所在章节并不存在"); if (org != null) { obj.Org_ID = org.Org_ID; } Business.Do <IQuestions>().QuesInput(obj, ansItem); }
/// <summary> /// 将某一行数据加入到数据库 /// </summary> /// <param name="dr"></param> /// <param name="dl"></param> private void _inputData(DataRow dr) { Song.Entities.Questions obj = new Song.Entities.Questions(); obj.Qus_IsUse = true; obj.Qus_Type = this.type; foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //Excel的列的值 string column = dr[rel.Key].ToString(); //数据库字段的名称 string field = rel.Value; if (field == "Qus_ID") { if (string.IsNullOrEmpty(column) || column.Trim() == "") { continue; } int ques = Convert.ToInt32(column); Song.Entities.Questions isHavObj = Business.Do <IQuestions>().QuesSingle(ques); if (isHavObj != null) { obj = isHavObj; } } //题干难度、专业、试题讲解 if (field == "Qus_Title") { if (column == string.Empty || column.Trim() == "") { return; } obj.Qus_Title = column; } if (field == "Qus_Diff") { obj.Qus_Diff = Convert.ToInt16(column); } if (field == "Sbj_Name") { Song.Entities.Subject subject = Business.Do <ISubject>().SubjectBatchAdd(org.Org_ID, column); if (subject != null) { obj.Sbj_Name = subject.Sbj_Name; obj.Sbj_ID = subject.Sbj_ID; } } if (field == "Cou_Name") { Song.Entities.Course course = Business.Do <ICourse>().CourseBatchAdd(org.Org_ID, obj.Sbj_ID, column); if (course != null) { obj.Cou_ID = course.Cou_ID; } } if (field == "Ol_Name") { Song.Entities.Outline outline = Business.Do <IOutline>().OutlineBatchAdd(org.Org_ID, obj.Sbj_ID, obj.Cou_ID, column); if (outline != null) { obj.Ol_ID = outline.Ol_ID; } } if (field == "Qus_Explain") { obj.Qus_Explain = column; } //唯一值,正确答案,类型 obj.Qus_UID = WeiSha.Common.Request.UniqueID(); if (field == "Qus_Answer") { if (column == string.Empty || column.Trim() == "") { obj.Qus_IsError = true; } obj.Qus_Answer = column; } } obj.Qus_ErrorInfo = ""; if (obj.Sbj_ID == 0) { throw new Exception("当前试题所属专业并不存在"); } if (obj.Cou_ID == 0) { throw new Exception("当前试题所在课程并不存在"); } //if (obj.Ol_ID == 0) throw new Exception("当前试题所在章节并不存在"); if (org != null) { obj.Org_ID = org.Org_ID; } Business.Do <IQuestions>().QuesInput(obj, null); }
/// <summary> /// 将某一行数据加入到数据库 /// </summary> /// <param name="dr"></param> /// <param name="dl"></param> private void _inputData(DataRow dr) { Song.Entities.Questions obj = new Song.Entities.Questions(); obj.Qus_IsUse = true; obj.Qus_Type = this.type; foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //Excel的列的值 string column = dr[rel.Key].ToString(); //数据库字段的名称 string field = rel.Value; if (field == "Qus_ID") { if (column == string.Empty || column.Trim() == "") { continue; } int ques = Convert.ToInt32(column); Song.Entities.Questions isHavObj = Business.Do <IQuestions>().QuesSingle(ques); if (isHavObj != null) { obj = isHavObj; } } //题干难度、专业、试题讲解 if (field == "Qus_Title") { if (string.IsNullOrEmpty(column) || column.Trim() == "") { return; } obj.Qus_Title = column; } if (field == "Qus_Diff") { obj.Qus_Diff = Convert.ToInt16(column); } if (field == "Sbj_Name") { Song.Entities.Subject subject = Business.Do <ISubject>().SubjectBatchAdd(org.Org_ID, column); if (subject != null) { obj.Sbj_Name = subject.Sbj_Name; obj.Sbj_ID = subject.Sbj_ID; } } if (field == "Cou_Name") { Song.Entities.Course course = Business.Do <ICourse>().CourseBatchAdd(org.Org_ID, obj.Sbj_ID, column); if (course != null) { obj.Cou_ID = course.Cou_ID; } } if (field == "Ol_Name") { Song.Entities.Outline outline = Business.Do <IOutline>().OutlineBatchAdd(org.Org_ID, obj.Sbj_ID, obj.Cou_ID, column); if (outline != null) { obj.Ol_ID = outline.Ol_ID; } } if (field == "Qus_Explain") { obj.Qus_Explain = column; } //唯一值 obj.Qus_UID = WeiSha.Common.Request.UniqueID(); } //再遍历一遍,取答案 int ansNum = 0; List <Song.Entities.QuesAnswer> ansItem = new List <QuesAnswer>(); foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //数据库字段的名称 string field = rel.Value; Match match = new Regex(@"(Ans_Context)(\d+)").Match(field); if (match.Success) { //Excel的列的值 string column = dr[rel.Key].ToString(); if (column == string.Empty || column.Trim() == "") { continue; } Song.Entities.QuesAnswer ans = new Song.Entities.QuesAnswer(); ans.Ans_Context = column; ans.Qus_UID = obj.Qus_UID; ansNum++; ansItem.Add(ans); } } obj.Qus_Title = tranTxt(obj.Qus_Title); int bracketsCount = new Regex(@"([^)]+)").Matches(obj.Qus_Title).Count; //判断是否有错 string error = ""; if (bracketsCount <= 0) { error = "试题中缺少填空项!(填空项用括号标识)"; } if (ansNum <= 0) { error = "缺少答案项"; } if (ansNum < bracketsCount) { error = string.Format("答案项少于填空项;填空项{0}个,答案{1}个", bracketsCount, ansNum); } // obj.Qus_IsError = error != ""; obj.Qus_ErrorInfo = error; if (obj.Sbj_ID == 0) { throw new Exception("当前试题所属专业并不存在"); } if (obj.Cou_ID == 0) { throw new Exception("当前试题所在课程并不存在"); } //if (obj.Ol_ID == 0) throw new Exception("当前试题所在章节并不存在"); if (org != null) { obj.Org_ID = org.Org_ID; } Business.Do <IQuestions>().QuesInput(obj, ansItem); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEnter_Click(object sender, EventArgs e) { Song.Entities.Questions mm = id <= 0 ? new Song.Entities.Questions() : Business.Do <IQuestions>().QuesSingle(id); //题型、学科、题干 mm.Qus_Type = this.type == 0 ? ddlType.SelectedIndex + 1 : this.type; mm.Qus_IsUse = cbIsUse.Checked; mm.Sbj_ID = SortSelect1.SbjID; mm.Sbj_Name = SortSelect1.SbjName; mm.Cou_ID = SortSelect1.CouID; mm.Ol_ID = SortSelect1.OlID; mm.Qus_Title = tranTxt(tbTitle.Text); //排序号 int tax = 0; int.TryParse(tbTax.Text, out tax); mm.Qus_Tax = tax; //难度 mm.Qus_Diff = Convert.ToInt32(ddlDiff.SelectedItem.Value); //资料、讲解 if (tbKnID.Text != string.Empty) { mm.Kn_ID = Convert.ToInt32(tbKnID.Text); } mm.Qus_Explain = tbExplan.Text.Trim(); //UID mm.Qus_UID = getUID(); //是否处理报错信息 if (cbWrong.Checked) { mm.Qus_IsWrong = false; } //选择项 List <Song.Entities.QuesAnswer> qans = new List <QuesAnswer>(); for (int i = 0; i < gvAnswer.Rows.Count; i++) { //单选钮 RadioButton rb = (RadioButton)gvAnswer.Rows[i].FindControl("rbAns"); //选项文本框 TextBox tb = (TextBox)gvAnswer.Rows[i].FindControl("itemTxt"); //主键 int ansid = 0; string keyId = gvAnswer.DataKeys[gvAnswer.Rows[i].RowIndex].Value.ToString(); int.TryParse(keyId, out ansid); //如果文本框为空,则跳过 if (tb.Text.Trim() == "") { continue; } //创建选项的对象 Song.Entities.QuesAnswer ans = new Song.Entities.QuesAnswer(); ans.Ans_Context = tb.Text.Trim(); ans.Ans_IsCorrect = rb.Checked; ans.Qus_ID = id; ans.Qus_UID = getUID(); ans.Ans_ID = ansid; if (ans.Ans_ID <= 0) { ans.Ans_ID = new Random((i + 1) * DateTime.Now.Millisecond).Next(1, 1000); } qans.Add(ans); } mm.Qus_Items = Business.Do <IQuestions>().AnswerToItems(qans.ToArray()); //确定操作 try { if (id == 0) { id = Business.Do <IQuestions>().QuesAdd(mm); } else { Business.Do <IQuestions>().QuesSave(mm); } Master.AlertCloseAndRefresh("操作成功!"); } catch (Exception ex) { Master.Alert(ex.Message); } }
/// <summary> /// 绑定简答题 /// </summary> private bool bindShortQues(Song.Entities.ExamResults exr) { if (string.IsNullOrEmpty(exr.Exr_Results)) { return(false); } DataTable dt = new DataTable("DataBase"); //试题的id,题干,答案,类型 dt.Columns.Add(new DataColumn("qid", Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("qtitle", Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("answer", Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("type", Type.GetType("System.String"))); //试题分数,得分,考生回答内容 dt.Columns.Add(new DataColumn("num", Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("score", Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("reply", Type.GetType("System.String"))); // XmlDocument resXml = new XmlDocument(); resXml.LoadXml(exr.Exr_Results, false); XmlNodeList nodeList = resXml.SelectSingleNode("results").ChildNodes; for (int i = 0; i < nodeList.Count; i++) { //试题的类型 int type = Convert.ToInt32(nodeList[i].Attributes["type"].Value); //如果是不是简答题,跳过 if (type != 4) { continue; } //试题的Id int id = Convert.ToInt32(nodeList[i].Attributes["id"].Value); //试题的分数 double num = Convert.ToDouble(nodeList[i].Attributes["num"].Value); //试题得分 double score = 0; if (nodeList[i].Attributes["score"] != null) { score = Convert.ToDouble(nodeList[i].Attributes["score"].Value); } //回答 string reply = nodeList[i].InnerText; //生成Datatable DataRow dr = dt.NewRow(); dr["qid"] = id.ToString(); Song.Entities.Questions qus = Business.Do <IQuestions>().QuesSingle(id); if (qus != null) { dr["qtitle"] = qus.Qus_Title; dr["answer"] = qus.Qus_Answer; } dr["type"] = type.ToString(); dr["num"] = num.ToString(); dr["score"] = score < 1 ? "" : score.ToString(); dr["reply"] = reply; dt.Rows.Add(dr); } rptQues.DataSource = dt; rptQues.DataBind(); return(dt.Rows.Count > 0); }
/// <summary> /// 将某一行数据加入到数据库 /// </summary> /// <param name="dr"></param> /// <param name="dl"></param> private void _inputData(DataRow dr) { Song.Entities.Questions obj = new Song.Entities.Questions(); obj.Qus_IsUse = true; obj.Qus_Type = this.type; //正确答案 string[] correct = null; //是否有答案 bool isHavAns = false; foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //Excel的列的值 string column = dr[rel.Key].ToString(); //数据库字段的名称 string field = rel.Value; if (field == "Qus_ID") { if (column == string.Empty || column.Trim() == "") { continue; } int ques = Convert.ToInt32(column); Song.Entities.Questions isHavObj = Business.Do <IQuestions>().QuesSingle(ques); if (isHavObj != null) { obj = isHavObj; } } //题干难度、专业、试题讲解 if (field == "Qus_Title") { if (column == string.Empty || column.Trim() == "") { return; } obj.Qus_Title = tranTxt(column); } if (field == "Qus_Diff") { obj.Qus_Diff = Convert.ToInt16(column); } if (field == "Sbj_Name") { Song.Entities.Subject subject = Business.Do <ISubject>().SubjectBatchAdd(org.Org_ID, column); if (subject != null) { obj.Sbj_Name = subject.Sbj_Name; obj.Sbj_ID = subject.Sbj_ID; } } if (field == "Cou_Name") { Song.Entities.Course course = Business.Do <ICourse>().CourseBatchAdd(org.Org_ID, obj.Sbj_ID, column); if (course != null) { obj.Cou_ID = course.Cou_ID; } } if (field == "Ol_Name") { Song.Entities.Outline outline = Business.Do <IOutline>().OutlineBatchAdd(org.Org_ID, obj.Sbj_ID, obj.Cou_ID, column); if (outline != null) { obj.Ol_ID = outline.Ol_ID; } } if (field == "Qus_Explain") { obj.Qus_Explain = column; } //唯一值,正确答案,类型 obj.Qus_UID = WeiSha.Common.Request.UniqueID(); if (field == "Ans_IsCorrect") { column = Regex.Replace(column, @"[^1-9]", ","); correct = column.Split(','); } } //再遍历一遍,取答案 List <Song.Entities.QuesAnswer> ansItem = new List <QuesAnswer>(); foreach (KeyValuePair <String, String> rel in ExcelInput1.DataRelation) { //数据库字段的名称 string field = rel.Value; Match match = new Regex(@"(Ans_Context)(\d+)").Match(field); if (match.Success) { //Excel的列的值 string column = dr[rel.Key].ToString(); if (column == string.Empty || column.Trim() == "") { continue; } int index = Convert.ToInt16(match.Groups[2].Value); Song.Entities.QuesAnswer ans = new Song.Entities.QuesAnswer(); ans.Ans_Context = column; foreach (string s in correct) { if (s == string.Empty || s.Trim() == "") { continue; } if (index == Convert.ToInt32(s)) { ans.Ans_IsCorrect = true; isHavAns = true; break; } } ans.Qus_UID = obj.Qus_UID; ansItem.Add(ans); } } if (!isHavAns) { obj.Qus_IsError = true; } //判断是否有错 string error = ""; if (ansItem.Count < 1) { error = "缺少答案选项"; } if (!isHavAns) { error = "没有设置正确答案"; } obj.Qus_IsError = error != ""; obj.Qus_ErrorInfo = error; if (obj.Sbj_ID == 0) { throw new Exception("当前试题所属专业并不存在"); } if (obj.Cou_ID == 0) { throw new Exception("当前试题所在课程并不存在"); } //if (obj.Ol_ID == 0) throw new Exception("当前试题所在章节并不存在"); if (org != null) { obj.Org_ID = org.Org_ID; } Business.Do <IQuestions>().QuesInput(obj, ansItem); }