//删除多条记录
 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
 {
     MultiProblem multi = new MultiProblem();//创建MultiProblem对象
     foreach (GridViewRow dr in GridView1.Rows)//对GridView中的每一行进行判断
     {
         if (((CheckBox)dr.FindControl("xuanze")).Checked)//如果选择了进行删除
         {
             int ID = int.Parse(((Label)dr.FindControl("Label1")).Text);
             multi.ID = ID;
             multi.DeleteByProc(ID);
         }
     }
 }
 //删除试题事件
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     MultiProblem multiproblem = new MultiProblem();  //创建单选题对象
     int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值
     if (multiproblem.DeleteByProc(ID))
     {
         Response.Write("<script language=javascript>alert('成功删除试题!')</script>");
     }
     else
     {
         Response.Write("<script language=javascript>alert('该题已被收录入试卷,请勿删除!')</script>");
     }
     GridViewBind();//重新绑定数据
     GridView1.EditIndex = -1;
 }
 protected void GridViewBind()
 {
     MultiProblem multiproblem = new MultiProblem();  //创建多选题对象
     DataSet ds = multiproblem.QueryMultiProblem(int.Parse(ddlCourse.SelectedValue));//根据考试科目查询多选题信息
     GridView1.DataSource = ds.Tables[0].DefaultView;    //为GridView控件指名数据源
     GridView1.DataBind();                               //绑定数据
     //胡媛媛修改,为gridview1中的复选框添加事件,2010-5-5
     if (GridView1.Rows.Count > 0)
     {
         foreach (GridViewRow dr in GridView1.Rows)
         {
             ((CheckBox)dr.FindControl("xuanze")).Attributes.Add("onclick", "SigchkChg()");
         }
     }
     //胡媛媛修改,为gridview1中的复选框添加事件,2010-5-5
 }
    //添加或修改事件
    protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            MultiProblem multiproblem = new MultiProblem();          //创建多选题对象
            multiproblem.CourseID = int.Parse(ddlCourse.SelectedValue);//为多选题对象各属性赋值
            //程军添加,多选题题目不能超过1000个字符,自动截取前1000个字符.2010-4-26;
            if (txtTitle.Text.Length > 1000)
            {
                this.Label1.Visible = true;
                this.Label1.Text = "题干不能超过1000字符,自动截取前1000字符";
                //程军修改,多选题题目文本框显示截取的1000个字符。2010-5-5
                txtTitle.Text = txtTitle.Text.Substring(0, 1000);
                //程军修改,多选题题目文本框显示截取的1000个字符。2010-5-5
                multiproblem.Title = txtTitle.Text.Substring(0, 1000);
            }
            else
            {
                multiproblem.Title = txtTitle.Text;
            }

            if (txtAnswerA.Text.Length > 500)
            {
                this.Label2.Visible = true;
                this.Label2.Text = "答案不能超过500字符,自动截取前500字符";
                //程军修改,多选题答案文本框显示截取500个字符。 2010-5-5
                txtAnswerA.Text = txtAnswerA.Text.Substring(0, 500);
                //程军修改,多选题答案文本框显示截取500个字符。 2010-5-5
                multiproblem.AnswerA = txtAnswerA.Text.Substring(0, 500);

            }
            else
            {
                multiproblem.AnswerA = txtAnswerA.Text;
            }

            if (txtAnswerB.Text.Length > 500)
            {
                this.Label3.Visible = true;
                this.Label3.Text = "答案不能超过500字符,自动截取前500字符";
                //程军修改,多选题答案文本框显示截取500个字符。 2010-5-5
                txtAnswerB.Text = txtAnswerB.Text.Substring(0, 500);
                //程军修改,多选题答案文本框显示截取500个字符。 2010-5-5
                multiproblem.AnswerB = txtAnswerB.Text.Substring(0, 500);

            }
            else
            {
                multiproblem.AnswerB = txtAnswerB.Text;
            }

            if (txtAnswerC.Text.Length > 500)
            {
                this.Label4.Visible = true;
                this.Label4.Text = "答案不能超过500字符,自动截取前500字符";
                //程军修改,多选题答案文本框显示截取500个字符。 2010-5-5
                txtAnswerC.Text = txtAnswerC.Text.Substring(0, 500);
                //程军修改,多选题答案文本框显示截取500个字符。 2010-5-5
                multiproblem.AnswerC = txtAnswerC.Text.Substring(0, 500);

            }
            else
            {
                multiproblem.AnswerC = txtAnswerC.Text;
            }

            if (txtAnswerD.Text.Length > 500)
            {
                this.Label5.Visible = true;
                this.Label5.Text = "答案不能超过500字符,自动截取前500字符";
                //程军修改,多选题答案文本框显示截取500个字符。 2010-5-5
                txtAnswerD.Text = txtAnswerD.Text.Substring(0, 500);
                //程军修改,多选题答案文本框显示截取500个字符。 2010-5-5
                multiproblem.AnswerD = txtAnswerD.Text.Substring(0, 500);

            }
            else
            {
                multiproblem.AnswerD = txtAnswerD.Text;
            }
            //程军添加,多选题题目不能超过1000个字符,自动截取前1000个字符.2010-4-26;
            // multiproblem.Title = txtTitle.Text;
            //multiproblem.AnswerA = txtAnswerA.Text;
            //multiproblem.AnswerB = txtAnswerB.Text;
            // multiproblem.AnswerC = txtAnswerC.Text;
            //multiproblem.AnswerD = txtAnswerD.Text;
            string answer = "";
            for (int i = 0; i < cblAnswer.Items.Count; i++)
            {
                if (cblAnswer.Items[i].Selected)
                {
                    answer += cblAnswer.Items[i].Text;
                }
            }

            //start:胡媛媛添加,判断是否有答案,2010-4-25
            if (answer == "")
            {
                lblMessage.Text = "操作失败,请给出多选题的答案!";
            }
            else
            {
                //end:胡媛媛添加,判断是否有答案,2010-4-25

                multiproblem.Answer = answer;
                if (Request["ID"] != null)                                  //如果是修改题目信息
                {
                    multiproblem.ID = int.Parse(Request["ID"].ToString()); //取出试题主键
                    if (multiproblem.UpdateByProc(int.Parse(Request["ID"].ToString()), int.Parse(ddlCourse.SelectedValue)))//调用修改试题方法修改试题
                    {
                        lblMessage.Text = "成功修改该多选题!";
                    }
                    else
                    {
                        lblMessage.Text = "修改该多选题失败!";
                    }
                }
                else                                                        //如果是添加试题
                {
                    if (multiproblem.InsertByProc(int.Parse(ddlCourse.SelectedValue)))                       //调用添加试题方法添加试题
                    {
                        lblMessage.Text = "成功添加该多选题!";
                    }
                    else
                    {
                        lblMessage.Text = "添加该多选题失败!";
                    }
                }
            }
        }
    }
 //初始化数据
 protected void InitData()
 {
     int multiProblemID = int.Parse(Request["ID"].ToString());  //取出传递过来的试题编号
     MultiProblem multiproblem = new MultiProblem();          //创建单选题对象
     if (multiproblem.LoadData(multiProblemID))                //如果取出题目信息,分别放在相应控件显示
     {
         ddlCourse.SelectedValue = multiproblem.CourseID.ToString();
         txtTitle.Text = multiproblem.Title;
         txtAnswerA.Text = multiproblem.AnswerA;
         txtAnswerB.Text = multiproblem.AnswerB;
         txtAnswerC.Text = multiproblem.AnswerC;
         txtAnswerD.Text = multiproblem.AnswerD;
         string answer = multiproblem.Answer;
         for (int i = 0; i < answer.Length; i++)
         {
             string item = answer[i].ToString();
             for (int j = 0; j < cblAnswer.Items.Count; j++)
             {
                 //胡媛媛修改,将Item[i]中的i改为j,并添加break语句,2010-4-16
                 if (item == cblAnswer.Items[j].Text)
                 {
                     cblAnswer.Items[j].Selected = true;
                     break;
                 }
                 //胡媛媛修改,将Item[i]中的i改为j,并添加break语句,2010-4-16
             }
         }
     }
     else                //查询出错,给出提示
     {
         lblMessage.Text = "加载数据出错!";
     }
 }