コード例 #1
0
    protected void ibtCommit_Click(object sender, ImageClickEventArgs e)
    {       ///创建ExamineDB数据库的数据上下文
        ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString);
        ///创建Question类的实例
        //Question q = new Question();
        Subject s = new Subject();

        //q.Score = Int32.Parse(tbScore.Text);
        //q.SubjectID = subjectID;
        //q.Title = tbTitle.Text;
        s.Name = tbTitle.Text;
        //q.Answer = ddlAnswer.SelectedValue;
        ///插入到数据库中
        db.Subject.InsertOnSubmit(s);
        db.SubmitChanges();
        ///查询最近被插入的问题,并获取其ID值
        var query = from qe in db.Subject
                    orderby qe.ID descending
                    select qe;

        if (query.Count() > 0)
        {           ///获取问题的ID值,并添加它的答案
            int questionID = query.First().ID;
            //AddAnswer(db,questionID,"A",tbAnswerA.Text);
            //AddAnswer(db,questionID,"B",tbAnswerB.Text);
            //AddAnswer(db,questionID,"C",tbAnswerC.Text);
            //AddAnswer(db,questionID,"D",tbAnswerD.Text);
        }
        ///将修改保存到数据库
        db.SubmitChanges();
        ///跳转到考题管理页面
        Response.Redirect("~/Admin/SubjectManage.aspx");
    }
コード例 #2
0
    protected void ibtCommit_Click(object sender, ImageClickEventArgs e)
    {       ///创建ExamineDB数据库的数据上下文
        ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString);
        ///创建Question类的实例
        Question q = new Question();

        q.Score     = Int32.Parse(tbScore.Text);
        q.SubjectID = subjectID;
        q.Title     = tbTitle.Text;
        //q.Answer = ddlAnswer1.SelectedValue;
        string answer, a1, a2, a3, a4 = string.Empty;

        a1     = ddlAnswer1.SelectedValue;
        a2     = ddlAnswer2.SelectedValue;
        a3     = ddlAnswer3.SelectedValue;
        a4     = ddlAnswer4.SelectedValue;
        answer = a1;
        if (a2 != "无" && a2 != a1)
        {
            answer += "/" + a2;
        }
        if (a3 != "无" && a3 != a1 && a3 != a2)
        {
            answer += "/" + a3;
        }
        if (a4 != "无" && a4 != a1 && a4 != a2 && a4 != a3)
        {
            answer += "/" + a4;
        }
        q.Answer = answer;
        //Response.Write(answer);
        ///插入到数据库中
        db.Question.InsertOnSubmit(q);
        db.SubmitChanges();
        ///查询最近被插入的问题,并获取其ID值
        var query = from qe in db.Question
                    orderby qe.ID descending
                    select qe;

        if (query.Count() > 0)
        {           ///获取问题的ID值,并添加它的答案
            int questionID = query.First().ID;
            AddAnswer(db, questionID, "A", tbAnswerA.Text);
            AddAnswer(db, questionID, "B", tbAnswerB.Text);
            AddAnswer(db, questionID, "C", tbAnswerC.Text);
            AddAnswer(db, questionID, "D", tbAnswerD.Text);
        }
        ///将修改保存到数据库
        db.SubmitChanges();
        ///跳转到考题管理页面
        Response.Redirect("~/Admin/QuestionManage.aspx");
    }
コード例 #3
0
 protected void gvQuestion_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     //if(e.CommandName == "edit")
     //{   ///跳转到修改考题页面
     //    Response.Redirect("~/Admin/UpdateQuestion.aspx?QuestionID=" + e.CommandArgument.ToString());
     //}
     if (e.CommandName == "del")
     {
         ///创建ExamineDB数据库的数据上下文
         ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString);
         ///产生答案
         //var queryA = from a in db.Answer
         //            where a.QuestionID.Value.ToString() == e.CommandArgument.ToString()
         //            select a;
         //db.Answer.DeleteAllOnSubmit(queryA);
         ///删除考题
         var queryQ = from q in db.Subject
                      where q.ID.ToString() == e.CommandArgument.ToString()
                      select q;
         db.Subject.DeleteAllOnSubmit(queryQ);
         ///提交到数据库
         db.SubmitChanges();
         ///重新显示考题
         BindPageData(Int32.Parse(ddlSubject.SelectedValue));
     }
 }
コード例 #4
0
    protected void ibtCommit_Click(object sender, ImageClickEventArgs e)
    {       ///创建ExamineDB数据库的数据上下文
        ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString);
        ///查询被修改的考题
        var query = from q in db.Question
                    where q.ID == questionID
                    select q;

        ///修改考题的信息
        foreach (Question qe in query)
        {
            qe.Answer = ddlAnswer.SelectedValue;
            qe.Score  = Int32.Parse(tbScore.Text);
            qe.Title  = tbTitle.Text;
        }
        ///查询被修改的答案
        var queryA = from a in db.Answer
                     where a.QuestionID == questionID
                     select a;

        ///修改答案的信息
        foreach (Answer aw in queryA)
        {
            if (aw.Tag.Trim() == "A")
            {
                aw.Body = tbAnswerA.Text;
            }
            if (aw.Tag.Trim() == "B")
            {
                aw.Body = tbAnswerB.Text;
            }
            if (aw.Tag.Trim() == "C")
            {
                aw.Body = tbAnswerC.Text;
            }
            if (aw.Tag.Trim() == "D")
            {
                aw.Body = tbAnswerD.Text;
            }
        }

        ///将修改保存到数据库
        db.SubmitChanges();
        ///跳转到考题管理页面
        Response.Redirect("~/Admin/QuestionManage.aspx");
    }
コード例 #5
0
    protected void ibtCommit_Click(object sender, ImageClickEventArgs e)
    {       ///创建ExamineDB数据库的数据上下文
        ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString);
        ///查询被修改的考题
        var query = from q in db.Question
                    where q.ID == questionID
                    select q;

        ///修改考题的信息
        foreach (Question qe in query)
        {
            //qe.Answer = ddlAnswer1.SelectedValue;
            string answer, a1, a2, a3, a4 = string.Empty;
            a1     = ddlAnswer1.SelectedValue;
            a2     = ddlAnswer2.SelectedValue;
            a3     = ddlAnswer3.SelectedValue;
            a4     = ddlAnswer4.SelectedValue;
            answer = a1;
            if (a2 != "无" && a2 != a1)
            {
                answer += "/" + a2;
            }
            if (a3 != "无" && a3 != a1 && a3 != a2)
            {
                answer += "/" + a3;
            }
            if (a4 != "无" && a4 != a1 && a4 != a2 && a4 != a3)
            {
                answer += "/" + a4;
            }
            qe.Answer = answer;
            qe.Score  = Int32.Parse(tbScore.Text);
            qe.Title  = tbTitle.Text;
        }
        ///查询被修改的答案
        var queryA = from a in db.Answer
                     where a.QuestionID == questionID
                     select a;

        ///修改答案的信息
        foreach (Answer aw in queryA)
        {
            if (aw.Tag.Trim() == "A")
            {
                aw.Body = tbAnswerA.Text;
            }
            if (aw.Tag.Trim() == "B")
            {
                aw.Body = tbAnswerB.Text;
            }
            if (aw.Tag.Trim() == "C")
            {
                aw.Body = tbAnswerC.Text;
            }
            if (aw.Tag.Trim() == "D")
            {
                aw.Body = tbAnswerD.Text;
            }
        }

        ///将修改保存到数据库
        db.SubmitChanges();
        ///跳转到考题管理页面
        Response.Redirect("~/Admin/QuestionManage.aspx");
    }