示例#1
0
        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");
        }