//删除考试科目事件
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Course course = new Course();           //创建Course对象
        int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值

        //程军、胡媛媛添加,获取此科目所对应的试卷。2010-5-6
        int flag = 1;  //判断删除过程时候出现错误
        string mySql = "select PaperID  from Paper where CourseID =" +ID ;
        DataBase db = new DataBase();
        Paper paper = new Paper();
        DataSet ds = db.GetDataSetSql(mySql);
        if (ds.Tables[0].Rows.Count != 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                int pid = Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString());
                if(!paper.DeleteByProc(pid)) flag=0;
            }
        }

        if (!course.DeleteByProc(ID))
        {
            flag=0;
        }

        if (flag == 1)
        {
            //程军修改,删除考试科目后,字体保持不变。2010-4-25
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('成功删除课程章节!')</script>");
            //程军修改,删除考试科目后,字体保持不变。2010-4-25
        }
        else
        {
            //程军修改,删除考试科目后,字体保持不变。2010-4-25
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('删除课程章节失败!')</script>");
            //程军修改,删除考试科目后,字体保持不变。2010-4-25
        }
        //程军、胡媛媛添加,获取此科目所对应的试卷。2010-5-6

        GridView1.EditIndex = -1;
        InitData();
    }
    //根据设置自动生成试卷
    protected void imgBtnConfirm_Click(object sender, ImageClickEventArgs e)
    {
        //程军添加,判断如果输入的分数不是整数,自动截取整数,并加1;2010-5-8
        string sf = txtSingleFen.Text.Trim();
        string mf = txtMultiFen.Text.Trim();
        string jf = txtJudgeFen.Text.Trim();
        string ff = txtFillFen.Text.Trim();
        int sfNum = txtSingleNum.Text.Trim() == "" ? 0 : Int32.Parse(txtSingleNum.Text.Trim());
        int mfNum = txtMultiNum.Text.Trim() == "" ? 0 : Int32.Parse(txtMultiNum.Text.Trim());
        int jfNum = txtJudgeNum.Text.Trim() == "" ? 0 : Int32.Parse(txtJudgeNum.Text.Trim());
        int ffNum = txtFillNum.Text.Trim() == "" ? 0 : Int32.Parse(txtFillNum.Text.Trim());
        int sum = 0;

        if (sf.IndexOf('.') != -1)
        {
            Label4.Visible = true;
            Label4.Text = "自动截取为整数分值";
            int state = sf.IndexOf('.');
            int i = int.Parse(sf.Substring(0,state));
            txtSingleFen.Text = Convert.ToString(i+1);
            sf = txtSingleFen.Text;
        }
        sum += (sf  == "" ? 0 : Int32.Parse(sf)) * sfNum;

        if (mf.IndexOf('.') != -1)
        {
            Label5.Visible = true;
            Label5.Text = "自动截取为整数分值";
            int state = mf.IndexOf('.');
            int i = int.Parse(mf.Substring(0, state));
            txtMultiFen.Text = Convert.ToString(i + 1);
            mf = txtMultiFen.Text;
        }
        sum += (mf == "" ? 0 : Int32.Parse(mf)) * mfNum;

        if (jf.IndexOf('.') != -1)
        {
            Label11.Visible = true;
            Label11.Text = "自动截取为整数分值";
            int state = jf.IndexOf('.');
            int i = int.Parse(jf.Substring(0, state));
            txtJudgeFen.Text = Convert.ToString(i + 1);
            jf = txtJudgeFen.Text;
        }
        sum += (jf == "" ? 0 : Int32.Parse(jf)) * jfNum;

        if (ff.IndexOf('.') != -1)
        {
            Label12.Visible = true;
            Label12.Text = "自动截取为整数分值";
            int state = ff.IndexOf('.');
            int i = int.Parse(ff.Substring(0, state));
            txtFillFen.Text = Convert.ToString(i + 1);
            ff = txtFillFen.Text;
        }
        sum += (ff == "" ? 0 : Int32.Parse(ff)) * ffNum;

        if (sum != 100)
        {
            Warning.Text = "请按百分制出卷";
            return;
        }
        Warning.Text = null;

        //程军添加,判断如果输入的分数不是整数,自动截取整数,并加1;2010-5-8

        DataBase db = new DataBase();//创建DataBase类对象

        //程军添加,判断试卷名称是不是重复名称.2010-4-25
        string strName = txtPaperName.Text.Trim();
        string mySql = "select * from Paper where PaperName ='"+strName+"'";
        bool flag = db.GetRecord(mySql);
        if (flag == true)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(),"alert","<script>alert('试卷名称重复!')</script>");
            this.txtPaperName.Focus();

        }

        //胡媛媛添加,为select子句添加where CourseID="+int.Parse(ddlCourse.SelectedValue),2010-4-16
        else
        {
            Panel1.Visible = true;
            // 程军修改,试卷制定的时候允许不选某一题型。2010-5-5
            int n1, n2, n3, n4;
            if (txtSingleNum.Text.Trim() == "")
            {
                n1 = 0;
            }
            else
            {
                n1 = int.Parse(txtSingleNum.Text.Trim());
            }
            string GridView1Str = "select top " + n1 + " * from SingleProblem where ChapterID=" + int.Parse(ddlCourse.SelectedValue) + " order by newid()";//根据参数设置查询单选题Sql语句
            DataSet ds1 = db.GetDataSetSql(GridView1Str);//调用DataBase类方法GetDataSetSql方法查询数据

            if (ds1.Tables[0].Rows.Count != n1)
            {
                Warning.Text = "单选题题库中的题量不足";
                imgBtnSave.Enabled = false;
                return;
            }
            Warning.Text = null;
            imgBtnSave.Enabled = true;

            GridView1.DataSource = ds1.Tables[0].DefaultView;//为单选题GridView控件指名数据源
            GridView1.DataBind();//绑定数据
            if (txtMultiNum.Text.Trim() == "")
            {
                n2 = 0;
            }
            else
            {
                n2 = int.Parse(txtMultiNum.Text.Trim());
            }
            string GridView2Str = "select top " + n2 + " * from MultiProblem where ChapterID=" + int.Parse(ddlCourse.SelectedValue) + "order by newid()";//根据参数设置查询多选题Sql语句
            DataSet ds2 = db.GetDataSetSql(GridView2Str);//调用DataBase类方法GetDataSetSql方法查询数据

            if (ds2.Tables[0].Rows.Count != n2)
            {
                Warning.Text = "多选题题库中的题量不足";
                imgBtnSave.Enabled = false;
                return;
            }
            Warning.Text = null;
            imgBtnSave.Enabled = true;

            GridView2.DataSource = ds2.Tables[0].DefaultView;//为多选题GridView控件指名数据源
            GridView2.DataBind();//绑定数据
            if (txtJudgeNum.Text.Trim() == "")
            {
                n3 = 0;
            }
            else
            {
                n3 = int.Parse(txtJudgeNum.Text.Trim());
            }
            string GridView3Str = "select top " + n3 + " * from JudgeProblem where ChapterID=" + int.Parse(ddlCourse.SelectedValue) + "order by newid()";//根据参数设置查询判断题Sql语句
            DataSet ds3 = db.GetDataSetSql(GridView3Str);//调用DataBase类方法GetDataSetSql方法查询数据

            if (ds3.Tables[0].Rows.Count != n3)
            {
                Warning.Text = "判断题题库中的题量不足";
                imgBtnSave.Enabled = false;
                return;
            }
            Warning.Text = null;
            imgBtnSave.Enabled = true;

            GridView3.DataSource = ds3.Tables[0].DefaultView;//为判断题GridView控件指名数据源
            GridView3.DataBind();//绑定数据
            if (txtFillNum.Text.Trim() == "")
            {
                n4 = 0;
            }
            else
            {
                n4 = int.Parse(txtFillNum.Text.Trim());
            }
            string GridView4Str = "select top " + n4 + " * from FillBlankProblem where ChapterID=" + int.Parse(ddlCourse.SelectedValue) + "order by newid()";//根据参数设置查询填空题Sql语句
            // 程军修改,试卷制定的时候允许不选某一题型。2010-5-5
            //胡媛媛添加,为select子句添加where CourseID="+int.Parse(ddlCourse.SelectedValue),2010-4-16

            DataSet ds4 = db.GetDataSetSql(GridView4Str);//调用DataBase类方法GetDataSetSql方法查询数据

            if (ds4.Tables[0].Rows.Count != n4)
            {
                Warning.Text = "填空题题库中的题量不足";
                imgBtnSave.Enabled = false;
                return;
            }
            Warning.Text = null;
            imgBtnSave.Enabled = true;

            GridView4.DataSource = ds4.Tables[0].DefaultView;//为填空题GridView控件指名数据源
            GridView4.DataBind();//绑定数据

            //胡媛媛添加,当没有试题时,给出提示信息,并隐藏保存按钮,2010-5-5
            if (n1 == 0 && n2 == 0 && n3 == 0 && n4 == 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),"alert","<script>alert('当前试卷没有试题!')</script>");
                this.imgBtnSave.Visible = false;
                return;
            }
            //胡媛媛添加,当没有试题时,给出提示信息,并隐藏保存按钮,2010-5-5

            //胡媛媛添加,显示答案,2010-4-26
            for (int i = 0; i < GridView1.Rows.Count; i++)  //显示单选题的答案
            {
                string answer = ds1.Tables[0].Rows[i][7].ToString();
                switch (answer)
                {
                    case "A":
                        {
                            RadioButton rdl = (RadioButton)GridView1.Rows[i].FindControl("RadioButton1");
                            rdl.Checked = true;
                            break;
                        }
                    case "B":
                        {
                            RadioButton rdl = (RadioButton)GridView1.Rows[i].FindControl("RadioButton2");
                            rdl.Checked = true;
                            break;
                        }
                    case "C":
                        {
                            RadioButton rdl = (RadioButton)GridView1.Rows[i].FindControl("RadioButton3");
                            rdl.Checked = true;
                            break;
                        }
                    case "D":
                        {
                            RadioButton rdl = (RadioButton)GridView1.Rows[i].FindControl("RadioButton4");
                            rdl.Checked = true;
                            break;
                        }
                }
            }

            for (int i = 0; i < GridView2.Rows.Count; i++)   //显示多选题的答案
            {
                string answer = ds2.Tables[0].Rows[i][7].ToString();
                for (int j = 0; j < answer.Length; j++)
                {
                    string item = answer[j].ToString();
                    switch (item)
                    {
                        case "A":
                            {
                                CheckBox cb = (CheckBox)GridView2.Rows[i].FindControl("CheckBox1");
                                cb.Checked = true;
                                break;
                            }
                        case "B":
                            {
                                CheckBox cb = (CheckBox)GridView2.Rows[i].FindControl("CheckBox2");
                                cb.Checked = true;
                                break;
                            }
                        case "C":
                            {
                                CheckBox cb = (CheckBox)GridView2.Rows[i].FindControl("CheckBox3");
                                cb.Checked = true;
                                break;
                            }
                        case "D":
                            {
                                CheckBox cb = (CheckBox)GridView2.Rows[i].FindControl("CheckBox4");
                                cb.Checked = true;
                                break;
                            }
                    }
                }
            }

            for (int i = 0; i < GridView3.Rows.Count; i++)  //显示判断题的答案
            {
                string answer = ds3.Tables[0].Rows[i][3].ToString();
                RadioButtonList rdl = (RadioButtonList)GridView3.Rows[i].FindControl("radiobtlist");
                if (answer.ToLower() == "true")
                {
                    rdl.SelectedValue = "true";
                }
                else
                {
                    rdl.SelectedValue = "false";
                }
            }

            for (int i = 0; i < GridView4.Rows.Count; i++)  //显示填空题的答案
            {
                string answer = ds4.Tables[0].Rows[i][4].ToString();
                TextBox tb = (TextBox)GridView4.Rows[i].FindControl("TextBox1");
                tb.Text = answer;
            }

            //胡媛媛添加,显示答案,2010-4-26

        }
        //程军添加,判断试卷名称是不是重复名称.2010-4-25
    }