public string Modify(string datas) { string[] data = datas.Split('#'); long id = Convert.ToInt64(data[0]); string qClass = data[2]; List <@class> classes = new _Class().Search(u => u.class_Class == qClass); if (classes.Count <= 0) { return("您所输入的问题类别不存在!"); } question q = Search(u => u.question_Id == id)[0]; q.qusetion_Stem = data[1]; q.question_ClassId = classes[0].class_Id; q.question_Option1 = data[3]; q.question_Option2 = data[4]; q.question_Option3 = data[5]; q.question_Option4 = data[6]; q.question_Option5 = data[7]; q.question_Option6 = data[8]; q.question_Option7 = data[9]; Modify(q, new string[] { "qusetion_Stem", "question_ClassId", "question_Option1", "question_Option2", "question_Option3", "question_Option4", "question_Option5", "question_Option6", "question_Option7" }); return("ok"); }
public string AddQuestion(string datas) { string[] data = datas.Split('#'); string que = data[0]; string qClass = data[1]; for (int i = 2; i < data.Length; i++) { if (data[i] == "undefined") { data[i] = ""; } } List <@class> classes = new _Class().Search(u => u.class_Class == qClass); if (classes.Count <= 0) { return("您所输入的问题类别不存在!"); } List <question> questions = Search(u => u.qusetion_Stem == que); if (questions.Count > 0) { questions[0].question_ClassId = classes[0].class_Id; questions[0].question_IsDel = false; questions[0].question_Option1 = data[2]; questions[0].question_Option2 = data[3]; questions[0].question_Option3 = data[4]; questions[0].question_Option4 = data[5]; questions[0].question_Option5 = data[6]; questions[0].question_Option6 = data[7]; questions[0].question_Option7 = data[8]; Modify(questions[0], new string[] { "question_ClassId", "question_IsDel", "question_Option1", "question_Option2", "question_Option3", "question_Option4", "question_Option5", "question_Option6", "question_Option7" }); return("ok"); } question q = new question(); q.qusetion_Stem = que; q.question_ClassId = classes[0].class_Id; q.question_Option1 = data[2]; q.question_Option2 = data[3]; q.question_Option3 = data[4]; q.question_Option4 = data[5]; q.question_Option5 = data[6]; q.question_Option6 = data[7]; q.question_Option7 = data[8]; Add(q); return("ok"); }
public string ImportQusetions(string filename, string id) { long testInfoId = 0; try { testInfoId = new TestInfo().Search(u => u.testInfo_OwnComPanyId == id && u.testInfo_IsDel == false)[0].testInfo_Id; } catch { return("您还没有创建问卷!"); } #region 打开文件,检查数据格式并转化为DataTable string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + ";Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", conn); DataSet ds = new DataSet(); da.Fill(ds, "table"); conn.Close(); DataTable table = ds.Tables["table"]; string result = CheckDataTable(table); if (result != "ok") { return(result); } #endregion int errorTests = 0; int errorQuestions = 0; Question Q = new Question(); Test T = new Test(); //遍历每行,将数据包装进rightTests和rightQuestions集合 test t = new test(); question q = new question(); for (int i = 0; i < table.Rows.Count; i++) { bool AllNull = string.IsNullOrEmpty(table.Rows[i][2].ToString()) && string.IsNullOrEmpty(table.Rows[i][3].ToString()) && string.IsNullOrEmpty(table.Rows[i][4].ToString()) && string.IsNullOrEmpty(table.Rows[i][5].ToString()) && string.IsNullOrEmpty(table.Rows[i][6].ToString()) && string.IsNullOrEmpty(table.Rows[i][7].ToString()); if (AllNull) { q.question_Option1 = "1"; q.question_Option2 = "2"; q.question_Option3 = "3"; q.question_Option4 = "4"; q.question_Option5 = "5"; q.question_Option6 = "6"; q.question_Option7 = "7"; } else { q.question_Option1 = table.Rows[i][2].ToString(); q.question_Option2 = table.Rows[i][3].ToString(); q.question_Option3 = table.Rows[i][4].ToString(); q.question_Option4 = table.Rows[i][5].ToString(); q.question_Option5 = table.Rows[i][6].ToString(); q.question_Option6 = table.Rows[i][7].ToString(); q.question_Option7 = table.Rows[i][8].ToString(); } string stem = table.Rows[i][0].ToString(); List <question> questions = Q.Search(k => k.qusetion_Stem == stem && k.question_IsDel == false); if (questions.Count > 0) {//题库中已存在此问题,不再插入,直接引用 t.test_QuestionId = questions[0].question_Id; t.test_TestInfoId = testInfoId; try { long qid = t.test_QuestionId; if (T.SearchCount(k => k.test_QuestionId == qid && k.test_TestInfoId == testInfoId && k.question.question_IsDel == false) > 0) { continue; } T.Add(t); } catch { errorTests++; } } else { q.qusetion_Stem = stem; string myclass = table.Rows[i][1].ToString(); List <@class> classes = new _Class().Search(k => k.class_Class == myclass); if (classes.Count <= 0) { return("导入中止,请确定您所插入表中的问题类别在类别中已存在!<br/>请在题库类别管理中添加。"); } else { q.question_ClassId = classes[0].class_Id; } try { Q.Add(q); } catch { errorQuestions++; } t.test_QuestionId = q.question_Id; t.test_TestInfoId = testInfoId; try { T.Add(t); } catch { errorTests++; } } } if (errorTests == 0 && errorQuestions == 0) { return("ok"); } else { return("有" + errorQuestions + "条数据出错,请检查数据!"); } }
public string AddTestQuestion(string data, long testInfoId) { string[] datas = data.Split('#'); string stem = datas[0]; Question Q = new Question(); List <question> ques = Q.Search(u => u.qusetion_Stem == stem); string qclass = datas[1]; if (ques.Count < 1) { //Create new question q = new question(); List <@class> c = new _Class().Search(u => u.class_Class == qclass); if (c.Count < 1) { return("不存在次类别,添加失败!"); } q.question_IsDel = false; q.qusetion_Stem = datas[0]; q.question_ClassId = c[0].class_Id; q.question_Option1 = datas[2]; q.question_Option2 = datas[3]; q.question_Option3 = datas[4]; q.question_Option4 = datas[5]; q.question_Option5 = datas[6]; q.question_Option6 = datas[7]; q.question_Option7 = datas[8]; try { new Question().Add(q); } catch { return("数据插入异常!"); } test t = new test(); t.test_QuestionId = q.question_Id; t.test_TestInfoId = testInfoId; try { Add(t); } catch { return("数据插入异常!"); } } else { long qId = ques[0].question_Id; long tests = new Test().SearchCount(k => k.test_QuestionId == qId); if (tests > 1) { return("此问卷中已包含此问题,请勿重复添加!"); } List <@class> c = new _Class().Search(u => u.class_Class == qclass); if (c.Count < 1) { return("不存在次类别,添加失败!"); } test t = new test(); t.test_QuestionId = ques[0].question_Id; t.test_TestInfoId = testInfoId; try { Add(t); } catch { return("数据插入异常!"); } } return("ok"); }