/// <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 (this.course != null) { obj.Cou_ID = this.course.Cou_ID; obj.Sbj_ID = this.course.Sbj_ID; } 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 (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="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> /// <returns></returns> private List <Song.Entities.Examination> getExamItem() { List <Song.Entities.Examination> items = new List <Song.Entities.Examination>(); for (int i = 0; i < GvItem.Rows.Count; i++) { GridViewRow gvr = GvItem.Rows[i]; if (gvr.RowType != DataControlRowType.DataRow) { continue; } //id Label lbID = (Label)gvr.FindControl("lbID"); int itemID = Convert.ToInt32(lbID.Text == string.Empty ? "-1" : lbID.Text); //考试名称 string name = ((TextBox)gvr.FindControl("tbName")).Text; //总分与及格分 TextBox tbTotal = (TextBox)gvr.FindControl("tbTotal"); int total = tbTotal.Text.Trim() == "" ? 60 : Convert.ToInt32(tbTotal.Text); TextBox tbPassscore = (TextBox)gvr.FindControl("tbPassScore"); int passcore = tbPassscore.Text.Trim() == "" ? 60 : Convert.ToInt32(tbPassscore.Text); //考试时间 TextBox tbDate = (TextBox)gvr.FindControl("tbDate"); DateTime date = Convert.ToDateTime(tbDate.Text == string.Empty ? DateTime.Now.AddYears(-100).ToString() : tbDate.Text); //考试时长 TextBox tbSpan = (TextBox)gvr.FindControl("tbSpan"); int span = Convert.ToInt32(tbSpan.Text == string.Empty ? "-1" : tbSpan.Text); //采用的试卷 TextBox tbTestPager = (TextBox)gvr.FindControl("tbTestPager"); int tpID = Convert.ToInt32(tbTestPager.Text == string.Empty ? "-1" : tbTestPager.Text); Song.Entities.TestPaper tp = Business.Do <ITestPaper>().PagerSingle(tpID); //专业 DropDownList sbjddl = (DropDownList)gvr.FindControl("ddlSubject"); int sbjID = 0; string sbjName = ""; if (sbjddl != null && sbjddl.Items.Count > 0) { sbjID = Convert.ToInt32(sbjddl.SelectedValue); sbjName = sbjddl.SelectedItem.Text; } Song.Entities.Subject sbj = Business.Do <ISubject>().SubjectSingle(sbjID); if (sbj != null) { sbjName = sbj.Sbj_Name; } //创建场次对象 Song.Entities.Examination exam = itemID < 1 ? new Song.Entities.Examination() : Business.Do <IExamination>().ExamSingle(itemID); exam = exam == null ? new Song.Entities.Examination() : exam; //赋值 exam.Exam_UID = getUID(); exam.Sbj_ID = sbjID; exam.Sbj_Name = sbjName; exam.Exam_Name = name; exam.Exam_Total = total; exam.Exam_PassScore = passcore; exam.Exam_Date = date; exam.Exam_Span = span; exam.Tp_Id = tpID; exam.Exam_Tax = i + 1; items.Add(exam); } //校验,各场次考试主题不可以相同 bool isExists = false; foreach (Song.Entities.Examination e in items) { if (string.IsNullOrWhiteSpace(e.Exam_Name)) { continue; } foreach (Song.Entities.Examination j in items) { if (e.Exam_Tax == j.Exam_Tax) { continue; } if (e.Exam_Name == j.Exam_Name) { isExists = true; break; } } if (isExists) { break; } } if (isExists) { throw new Exception("各场次考试主题不可以相同"); } return(items); }
/// <summary> /// 通过专业ID,获取专业信息 /// </summary> /// <param name="id">专业id</param> /// <returns></returns> public Song.Entities.Subject ForID(int id) { Song.Entities.Subject sbj = Business.Do <ISubject>().SubjectSingle(id); return(_tran(sbj)); }
/// <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); obj.Qus_Diff = obj.Qus_Diff > 5 || obj.Qus_Diff < 1 ? 3 : obj.Qus_Diff; } 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_IsCorrect") { if (column == string.Empty || column.Trim() == "") { obj.Qus_IsError = true; } obj.Qus_IsCorrect = column.Trim() == "正确"; } } 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); }