我在做在线考试系统,下面是考试页面的代码,没有给业务层和数据访问层的代码,因为不会影响大家阅读下面的代码的,我要实现的就是获取用户做错的题号(这个题号是要数据库中的,不是页面上的),以便根据题号获取这题的的知识点,题目表叫SubjectTeble,字段:id,Subject,A,B,C,D,Anwser,IsManychect,LessonId(依次为id,题目,选项ABCD,答案,知识点id),我库中有个错题表:id,用户id,知识点id,错误次数,关键就是下面代码的最后计算分数的方法里面如何写代码实现我的功能了,高手请指教,我做了4天了,重申要求:评分的时候获取作错的题号,并查出这题是属于哪个知识点的,并将信息插入错题表中,以便以后让用户知道自己的弱项是哪个知识点 
//用于存储正确答案
    public string singleanswer = "";
    public string doubleanswer = "";
    //用于存储考生答案
    public string singlestudentAnswer = "";
    public string doublestudentAnswer = "";
    //用于存储分数
    public int point = 0;    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string str = Request.QueryString["strInfo"].ToString();//获取发送过来的信息
            
            this.getCom1(str);//随机抽取一定数量的单选题并绑定到DataList的方法
            this.getCom2(str);//随机抽取一定数量的多选题并绑定到另一个DataList的方法
        }
       
    }    //随机抽取一定数量的单选题并绑定到DataList的方法
    protected void getCom1(string str)
    {
        int TremId = int.Parse(str.Substring(0, 1));//获取用户是哪个阶段的
        int LessionId = int.Parse(str.Substring(1));//获取他是哪个班级的
        int IsManyCheckt = 0;//是否是多选
        List<SubjectTeble> list = TestManager.GetRandomTestpaperByLession(TremId, LessionId,IsManyCheckt);//根据之前条件通过业务层和数据访问层获取题目的集合
        this.DataList1.DataSource = list;//绑定到控件上
        this.DataList1.DataBind();        //获取正确答案
        foreach (SubjectTeble st in list)
        {
            singleanswer += st.Anwser.ToString();
        }
        Session["singleanswer"] = singleanswer;        //生成单选题题号
        for (int tID1 = 1; tID1 <= DataList1.Items.Count; tID1++)
        {
            Label lblSelect = (Label)DataList1.Items[tID1 - 1].FindControl("Label2");
            lblSelect.Text = tID1.ToString() + "、";
        }
    }    //随机抽取一定数量的多选题并绑定到另一个DataList的方法
    protected void getCom2(string str)
    {
        int TremId = int.Parse(str.Substring(0, 1));
        int LessionId = int.Parse(str.Substring(1));
        int IsManyCheckt = 1;
        List<SubjectTeble> list = TestManager.GetRandomTestpaperByLession(TremId, LessionId, IsManyCheckt);
        this.DataList2.DataSource = list;
        this.DataList2.DataBind();
        //获取正确答案
        foreach (SubjectTeble st in list)
        {
            doubleanswer += st.Anwser.ToString();
        }
        Session["doubleanswer"] = doubleanswer;        //生成多选题题号
        for (int tID2 = 1; tID2 <= DataList2.Items.Count; tID2++)
        {
            Label lblDSelect = (Label)DataList2.Items[tID2 - 1].FindControl("Label24");
            lblDSelect.Text = tID2.ToString() + "、";
        }
    }    //提交试卷
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string singleanswer = Session["singleanswer"].ToString();
        string doubleanswer = Session["doubleanswer"].ToString();        //单选题的用户选的答案
        for (int i = 0; i < DataList1.Items.Count; i++)
        {
            RadioButtonList rbl = (RadioButtonList)(DataList1.Items[i].FindControl("RadioButtonList1"));
            if (rbl != null)
            {
                if (rbl.SelectedValue.ToString() != "")
                {
                    singlestudentAnswer += rbl.SelectedValue.ToString();//将用户的选的答案组合成连接字符串
                }
                else
                {
                    singlestudentAnswer += "0";//如果用户没有选择,就将那题用户选的答案设为0,答案只有ABCD,
                }            }        }      //多选题用户选的答案
        for (int i = 0; i < DataList2.Items.Count; i++)
        {
            string dd = "";
            CheckBoxList cbl = (CheckBoxList)(DataList2.Items[i].FindControl("CheckBoxList1"));
            if (cbl != null)
            {
                for (int j = 0; j < cbl.Items.Count; j++)
                {
                    if (cbl.Items[j].Selected == true)
                    {
                        dd += cbl.Items[j].Value.ToString();
                    }
                    else
                    {
                        //studentAnswer += "0";
                    }
                }
            }
            //因为我多选题的答案只有两个,我只能实现这个了,因为评分是截取两个来对比的
            if (dd.Length > 2)
            {
                doublestudentAnswer += "xx";//选多了算错
            }
            else if (dd.Length < 2)
            {
                doublestudentAnswer += "xx";//少了也算错
            }
            else
            {
                doublestudentAnswer += dd;//类加用户的答案
            }
        }
        //计算分数
        //多选题分数
        for (int i = 0; i < doublestudentAnswer.Length; i = i + 2)
        {
            if (doubleanswer.Length < doublestudentAnswer.Length)
            {
                int k = doublestudentAnswer.Length - doubleanswer.Length;
                for (int h = 0; h < k; h++)
                {
                    doubleanswer += "0";
                }
            }
            if (doubleanswer.Substring(i, 2).Equals(doublestudentAnswer.Substring(i, 2)))
                point += 2;
        }        //单选题分数
        for (int i = 0; i < singleanswer.Length; i++)
        {
            if (singleanswer.Substring(i, 1).Equals(singlestudentAnswer.Substring(i, 1)))
                point += 2;
        }
  }

解决方案 »

  1.   

    说白了,我就是想在最后计算分数的两个for循环里面获取作错的题目的信息,以便查出他是哪个知识点的
      

  2.   

    就是最后那两个计算分数的for循环里面,如何获取用户作错的题目信息,然后再查出做错那题是那个知识点的
      

  3.   

    就是在评分的两个for循环里面获取作错的题目信息,我搞了几天都不得,将获取的题目信息放进一个数组吗?然后还要写方法,查出这些题目是属于哪个知识点的,将它插入错题表里面 
      

  4.   

            if (dd.Length > 2)
                {
                    doublestudentAnswer += "xx";//选多了算错
                }
                else if (dd.Length < 2)
                {
                    doublestudentAnswer += "xx";//少了也算错
                }
                else
                {
                    doublestudentAnswer += dd;//类加用户的答案
                }在这一块错误的时候就把题号记录下来。。
        for (int i = 0; i < doublestudentAnswer.Length; i = i + 2)
            {
                if (doubleanswer.Length < doublestudentAnswer.Length)
                {
                    int k = doublestudentAnswer.Length - doubleanswer.Length;
                    for (int h = 0; h < k; h++)
                    {
                        doubleanswer += "0";
                    }
                }
                if (doubleanswer.Substring(i, 2).Equals(doublestudentAnswer.Substring(i, 2)))
                    point += 2;
            }        //单选题分数
            for (int i = 0; i < singleanswer.Length; i++)
            {
                if (singleanswer.Substring(i, 1).Equals(singlestudentAnswer.Substring(i, 1)))
                    point += 2;
            }
    或是在打分的时候,即然此题能给就表示是正确的。除去正确的也就是错误的了。。得到错误的题号信息就行了
      

  5.   

     //提交试卷
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string singleanswer = Session["singleanswer"].ToString();
            string doubleanswer = Session["doubleanswer"].ToString();        //单选题的用户选的答案
            for (int i = 0; i < DataList1.Items.Count; i++)
            {
                RadioButtonList rbl = (RadioButtonList)(DataList1.Items[i].FindControl("RadioButtonList1"));
                if (rbl != null)
                {
                    if (rbl.SelectedValue.ToString() != "")
                    {
                        singlestudentAnswer += rbl.SelectedValue.ToString();//将用户的选的答案组合成连接字符串
                    }
                    else
                    {
                        singlestudentAnswer += "0";//如果用户没有选择,就将那题用户选的答案设为0,答案只有ABCD,
                    }            }        }其中
    RadioButtonList rbl = (RadioButtonList)(DataList1.Items[i].FindControl("RadioButtonList1"));
    就是获取每题的信息了,就是不懂如何获取这题目的信息了
      

  6.   

    为何你不把眼睛离的远点呢?隔的远点,也许你看到的是一幅画,而不是一些无意义的点。集合的合,差,并,补,集合元素的sum,count都有现成的解法。
    如果
    题A的知识点 {a,b,c}
    题B的知识点{a,c,d,e}
    而且题A,B都做错了,那么他们的交集是什么?他们的合集与元素的count又是什么?