//添加考试科目事件
    protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            Course course = new Course();               //创建考试科目对象
            //start:胡媛媛修改,去掉考试科目输入框两边的空格,加trim(),2010-4-29
            course.Name = txtName.Text.Trim();                 //设置考试科目对象属性

            //程军添加,添加考试科目,名称不能相同。2010-4-25
            DataBase db = new DataBase();
            string mySql = "select * from Course where Name ='" + txtName.Text.Trim() + "'";
            //end:胡媛媛修改,去掉考试科目输入框两边的空格,加trim(),2010-4-29
            if (db.GetRecord(mySql))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('课程章节重复!')</script>");
                this.txtName.Focus();
            }
            else
            {
               if (course.InsertByProc())                  //调用添加考试科目方法添加考试科目
              {
                  lblMessage.Text = "成功添加该章节科目!";
              }
              else
              {
                  lblMessage.Text = "添加该章节失败!";
              }
            }

            //程军添加,添加考试科目,名称不能相同。2010-4-25
        }
    }
    //GridView控件RowUpdating事件
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值
        Course course = new Course();           //创建Course对象
        //程军修改,去掉考试科目名称后边的空格并判断考试科目名称是否为空,且修改后的考试科目不能相同.2010-4-25
        string name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName")).Text.Trim();
        course.Name = name;
        if (name == "")
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('课程章节不能为空!')</script>");
        }
        else
        {
            DataBase db = new DataBase();
            string mySql = "select * from Course where Name ='" + name + "'";
            if (db.GetRecord(mySql))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('课程章节名称不能相同!')</script>");
            }
            else
            {
              if (course.UpdateByProc(ID))//使用Users类UpdateByProc方法修改用户信息
             {
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改成功!')</script>");
             }
              else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改失败!')</script>");
            }
             GridView1.EditIndex = -1;
             InitData();
           }

        }
        //程军修改,去掉考试科目名称后边的空格并判断考试科目名称是否为空,且修改后的考试科目不能相同.2010-4-25
    }
示例#3
0
 //胡媛媛添加,按学生ID查询成绩,2010-4-12
 //输入:
 //      UserID - 用户编号;
 //输出:
 //      删除成功:返回True;
 //      删除失败:返回False;
 public bool QueryScoreByUserId(string UID)
 {
     String sqlstr = "select * from Score where UserID=" + UID;
     DataBase DB = new DataBase();
     bool flag = DB.GetRecord(sqlstr);
     return flag;
 }
    //根据设置自动生成试卷
    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
    }