protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
 {
     if (Session["handexam"] != null)
     {
         exam1 = (Exam)Session["handexam"];
     }
     vatxttitle3.Validate();
     vatxttime3.Validate();
     vatxttime3a.Validate();
     if (vatxttime3a.IsValid && vatxttime3.IsValid && vatxttitle3.IsValid)
     {
         SqlConnection con = new SqlConnection(DealData.constring);
         SqlCommand    cmd = new SqlCommand("usp_CreateExam", con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add(new SqlParameter("@qaid", SqlDbType.VarChar)).Value        = exam1.QAId;
         cmd.Parameters.Add(new SqlParameter("@qbid", SqlDbType.VarChar)).Value        = exam1.QBId;
         cmd.Parameters.Add(new SqlParameter("@amark", SqlDbType.VarChar)).Value       = exam1.AMark;
         cmd.Parameters.Add(new SqlParameter("@bmark", SqlDbType.VarChar)).Value       = exam1.BMark;
         cmd.Parameters.Add(new SqlParameter("@time", SqlDbType.VarChar)).Value        = Convert.ToInt32(txttime3.Text);
         cmd.Parameters.Add(new SqlParameter("@endtime", SqlDbType.DateTime)).Value    = Convert.ToDateTime(lbendtime3.Text);
         cmd.Parameters.Add(new SqlParameter("@deletetime", SqlDbType.DateTime)).Value = Convert.ToDateTime(lbdeletetime3.Text);
         cmd.Parameters.Add(new SqlParameter("@title", SqlDbType.NVarChar, 50)).Value  = HttpUtility.HtmlEncode(txttitle3.Text);
         try
         {
             con.Open();
             if (cmd.ExecuteNonQuery() > 0)
             {
                 exam1.Clear();
                 if (Session["handexam"] != null)
                 {
                     Session["handexam"] = null;
                 }
                 ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('已成功生成试卷!')", true);
             }
         }
         catch (Exception err)
         {
             eMessage.Message(err);
             ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('试卷生成失败,数据库连接发生错误!')", true);
         }
         finally
         {
             if (con != null && con.State != ConnectionState.Closed)
             {
                 con.Close();
             }
         }
     }
     exam1.Clear();
     Session["handexam"] = null;
     Session["QAId"]     = null;
     Session["QBId"]     = null;
 }
    protected void btCreate_Click(object sender, EventArgs e)
    {
        string type    = "'exam'";
        int    state   = 0;
        Exam   newExam = new Exam();

        if (vaamark2.IsValid && vaaskmark.IsValid && vaasknum.IsValid && vaasknum2.IsValid && valevel.IsValid && vaselectmark.IsValid && vaselectnum.IsValid && vaselectnum2.IsValid && vasmark2.IsValid && vatime.IsValid && vatime2.IsValid && vatitle.IsValid)
        {
            SqlCommand cmd = new SqlCommand("usp_SelectQA", new SqlConnection(DealData.constring));
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@selectnum", SqlDbType.Int)).Value     = Convert.ToInt32(txtNumSelect.Text);
            cmd.Parameters.Add(new SqlParameter("@level1", SqlDbType.Int)).Value        = Convert.ToInt32(level1.SelectedValue);
            cmd.Parameters.Add(new SqlParameter("@level2", SqlDbType.Int)).Value        = Convert.ToInt32(level2.SelectedValue);
            cmd.Parameters.Add(new SqlParameter("@type", SqlDbType.NVarChar, 50)).Value = type.ToString();
            SqlDataReader reader;
            try
            {
                cmd.Connection.Open();
                reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        newExam.aAddId(Convert.ToInt32(reader["QuestionAId"]), Convert.ToInt32(txtMarkSelect.Text));
                    }
                }
                reader.Close();
                state = 1;
            }
            catch (Exception err)
            {
                eMessage.Message(err);
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('从选择题题中提取试题时出错,请联系管理员!')", true);
            }
            finally
            {
                if (cmd.Connection != null)
                {
                    cmd.Connection.Close();
                }
                cmd.Dispose();
            }
            if (state == 1)
            {
                SqlCommand cmd1 = new SqlCommand("usp_SelectQB", new SqlConnection(DealData.constring));
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.Parameters.Add(new SqlParameter("@asknum", SqlDbType.Int)).Value        = Convert.ToInt32(txtNumAsk.Text);
                cmd1.Parameters.Add(new SqlParameter("@level1", SqlDbType.Int)).Value        = Convert.ToInt32(level1.SelectedValue);
                cmd1.Parameters.Add(new SqlParameter("@level2", SqlDbType.Int)).Value        = Convert.ToInt32(level2.SelectedValue);
                cmd1.Parameters.Add(new SqlParameter("@type", SqlDbType.NVarChar, 50)).Value = "'exam'";
                try
                {
                    cmd1.Connection.Open();
                    reader = cmd1.ExecuteReader();
                    if (reader != null)
                    {
                        while (reader.Read())
                        {
                            newExam.bAddId(Convert.ToInt32(reader["QuestionBId"]), Convert.ToInt32(txtMarkAsk.Text));
                        }
                    }
                    reader.Close();
                    state = 2;
                }
                catch (Exception err)
                {
                    newExam.Clear();
                    eMessage.Message(err);
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('从问答题题库中提取试题时发生错误,请稍候重试或联系管理员!')", true);
                }
                finally
                {
                    if (cmd1.Connection != null)
                    {
                        cmd1.Connection.Close();
                    }
                }
            }
            if (state == 2)
            {
                SqlCommand cmd2 = new SqlCommand("usp_CreateExam", new SqlConnection(DealData.constring));
                cmd2.CommandType = CommandType.StoredProcedure;
                cmd2.Parameters.Add(new SqlParameter("@title", SqlDbType.NVarChar, 50)).Value  = HttpUtility.HtmlEncode(txtTitle.Text);
                cmd2.Parameters.Add(new SqlParameter("@qaid", SqlDbType.VarChar)).Value        = newExam.QAId;
                cmd2.Parameters.Add(new SqlParameter("@qbid", SqlDbType.VarChar)).Value        = newExam.QBId;
                cmd2.Parameters.Add(new SqlParameter("@amark", SqlDbType.VarChar)).Value       = newExam.AMark;
                cmd2.Parameters.Add(new SqlParameter("@bmark", SqlDbType.VarChar)).Value       = newExam.BMark;
                cmd2.Parameters.Add(new SqlParameter("@endtime", SqlDbType.DateTime)).Value    = Convert.ToDateTime(lbEndTime.Text);
                cmd2.Parameters.Add(new SqlParameter("@deletetime", SqlDbType.DateTime)).Value = Convert.ToDateTime(lbDeleteTime.Text);
                cmd2.Parameters.Add(new SqlParameter("@time", SqlDbType.Int)).Value            = Convert.ToInt32(Time.Text);
                try
                {
                    cmd2.Connection.Open();
                    if (cmd2.ExecuteNonQuery() > 0)
                    {
                        ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('试卷生成成功!')", true);
                        ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "window.location.href='CreateExam.aspx'", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('试卷记录插入数据库发生问题,试卷生成失败,请联系管理员!');window.location.href='CreateExam.aspx'", true);
                    }
                }
                catch (Exception err)
                {
                    eMessage.Message(err);
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('在将试卷记录保存在数据库过程中打开数据库连接发生错误,试卷生成失败,请联系管理员!');window.location.href='CreateExam.aspx'", true);
                }
                finally
                {
                    if (cmd.Connection != null)
                    {
                        cmd.Connection.Close();
                    }
                }
            }
            newExam.Clear();
        }
        else
        {
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('请填写完整的信息并仔细检查输入!');window.location.href='CreateExam.aspx'", true);
        }
    }