protected void GridViewBind()
 {
     JudgeProblem judgeproblem = new JudgeProblem();  //创建判断题对象
     DataSet ds = judgeproblem.QueryJudgeProblem(int.Parse(ddlCourse.SelectedValue));//根据试卷科目查询判断题信息
     GridView1.DataSource = ds.Tables[0].DefaultView;    //为GridView控件指名数据源
     GridView1.DataBind();                               //绑定数据
 }
 //显示选择科目的判断题
 protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
 {
     JudgeProblem judgeproblem = new JudgeProblem();  //创建单选题对象
     DataSet ds = judgeproblem.QueryJudgeProblem(int.Parse(ddlCourse.SelectedValue));//根据试卷科目查询单选题信息
     GridView1.DataSource = ds.Tables[0].DefaultView;    //为GridView控件指名数据源
     GridView1.DataBind();                               //绑定数据
 }
 //删除试题事件
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     JudgeProblem judgeproblem = new JudgeProblem();  //创建判断题对象
     int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值
     if (judgeproblem.DeleteByProc(ID))
     {
         Page.RegisterStartupScript("", "<script language=javascript>alert('成功删除试题!')</script>");
     }
     else
     {
         Page.RegisterStartupScript("", "<script language=javascript>alert('删除试题失败!')</script>");
     }
     GridViewBind();//重新绑定数据
     GridView1.EditIndex = -1;
 }
示例#4
0
 //初始化数据
 protected void InitData()
 {
     int judgeProblemID = int.Parse(Request["ID"].ToString());   //取出传递过来的试题编号
     JudgeProblem judgeproblem = new JudgeProblem();             //创建判断题对象
     if (judgeproblem.LoadData(judgeProblemID))                  //如果取出题目信息,分别放在相应控件显示
     {
         ddlCourse.SelectedValue = judgeproblem.CourseID.ToString();
         ddlDiff.SelectedValue = judgeproblem.DiffID.ToString();
         txtTitle.Text = judgeproblem.Title;
         rblAnswer.SelectedValue = judgeproblem.Answer.ToString().ToLower();   //注意小写化,数据库保存的True,False,首字母大写,会导致不匹配
     }
     else                //查询出错,给出提示
     {
         lblMessage.Text = "加载数据出错!";
     }
 }
示例#5
0
    //添加或修改事件
    protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            JudgeProblem judgeproblem = new JudgeProblem();          //创建判断题对象
            judgeproblem.CourseID = int.Parse(ddlCourse.SelectedValue);//为判断题对象各属性赋值
            judgeproblem.DiffID = int.Parse(ddlDiff.SelectedValue);//为填空题对象各属性赋值
            judgeproblem.Title = txtTitle.Text;
            judgeproblem.Answer = bool.Parse(rblAnswer.SelectedValue);

            if (Request["ID"] != null)                                  //如果是修改题目信息
            {
                judgeproblem.ID = int.Parse(Request["ID"].ToString()); //取出试题主键
                if (judgeproblem.UpdateByProc(int.Parse(Request["ID"].ToString())))//调用修改试题方法修改试题
                {
                    lblMessage.Text = "成功修改该判断题!";
                    txtTitle.Text = "";
                    rblAnswer.SelectedValue = null;
                }
                else
                {
                    lblMessage.Text = "修改该判断题失败!";
                }
            }
            else                                                        //如果是添加试题
            {
                if (judgeproblem.InsertByProc())                       //调用添加试题方法添加试题
                {
                    lblMessage.Text = "成功添加该判断题!";
                    txtTitle.Text = "";
                    rblAnswer.SelectedValue = null;
                }
                else
                {
                    lblMessage.Text = "添加该判断题失败!";
                }
            }
        }
    }
示例#6
0
 protected void txtTitle_TextChanged(object sender, EventArgs e)
 {
     JudgeProblem jp = new JudgeProblem();
     if (jp.isReduplicated(txtTitle.Text.Trim()) == true)
     {
         Page.RegisterStartupScript("", "<script>alert('改题已经存在!');</script>");
         txtTitle.Text = "";
     }
 }
 //删除多条记录
 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
 {
     JudgeProblem judge = new JudgeProblem();//创建JudgeProblem对象
     foreach (GridViewRow dr in GridView1.Rows)//对GridView中的每一行进行判断
     {
         if (((CheckBox)dr.FindControl("xuanze")).Checked)//如果选择了进行删除
         {
             int ID = int.Parse(((Label)dr.FindControl("Label1")).Text);
             judge.ID = ID;
             judge.DeleteByProc(ID);
         }
     }
 }