Ejemplo n.º 1
0
    /// <summary>
    /// 保存按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        //判断是否钩选了正确答案
        if (lblAnswer.Text == "")
        {
            lblAnswerError.Visible = true;
            return;
        }
        lblAnswerError.Visible = false;
        //判断问题是否重复
        Question();
        //判断是否没填答案D就填答案E
        if (txtAnswerD.Text.Trim() == "" && txtAnswerE.Text.Trim() != "")
        {
            lblAnswerE.Visible = true;
            return;
        }
        //判断下拉框选项是否为空
        else if (sltQuestionTypeId.Text == "")
        {
            lblQuestionType.Visible = true;
            return;
        }

        lblAnswerE.Visible = false;
        CSExmQuestion exm = new CSExmQuestion(config.DBConn);

        exm.Question_Guid   = Guid.NewGuid().ToString();
        exm.Question        = HttpUtility.HtmlEncode(this.txtQuestionAdd.Text);
        exm.QuestionType_Id = this.sltQuestionTypeId.SelectedValue;
        //遍历页面所有checkbox并把钩选为true的checkbox的值截取字母拼到arrList里
        string arrList = GetSelectedKeyValues();

        exm.Answer    = arrList;
        exm.AnswerA   = HttpUtility.HtmlEncode(this.txtAnswerA.Text);
        exm.AnswerB   = HttpUtility.HtmlEncode(this.txtAnswerB.Text);
        exm.AnswerC   = HttpUtility.HtmlEncode(this.txtAnswerC.Text);
        exm.AnswerD   = HttpUtility.HtmlEncode(this.txtAnswerD.Text);
        exm.AnswerE   = HttpUtility.HtmlEncode(this.txtAnswerE.Text);
        exm.CreatedBy = "";        // 测试修改config.Staff.Staff_Id;
        try
        {
            exm.Insert();
            //页面跳转
            Response.Write("<Script Langage='JavaScript'>");
            Response.Write("if(confirm('添加成功!继续添加?'))");
            Response.Write("{window.location='QuestionAdd.aspx';}");
            Response.Write("else{window.location='QuestionList.aspx';}");
            Response.Write("</Script>");
        }
        catch (Exception Err)
        {
            throw Err;
        }
        finally
        {
            Response.Write("<script type='text/javascript'>alert('添加失败');window.location.href=window.location.href;</script>");
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 保存按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        //判断是否钩选了正确答案
        if (lblAnswer.Text == "")
        {
            lblAnswerError.Visible = true;
            return;
        }
        lblAnswerError.Visible = false;
        //判断问题是否重复
        Question();
        //判断是否没填答案D就填答案E
        if (txtAnswerD.Text.Trim() == "" && txtAnswerE.Text.Trim() != "")
        {
            lblAnswerE.Visible = true;
            return;
        }
        lblAnswerE.Visible = false;
        //数据库连接
        CSExmQuestion exm = new CSExmQuestion(config.DBConn);

        exm.Question_Guid   = ViewState["Question_Guid"].ToString();
        exm.Question        = HttpUtility.HtmlEncode(this.txtQuestionChange.Text);
        exm.QuestionType_Id = this.sltQuestionTypeId.SelectedValue;
        //遍历页面所有checkbox并把钩选为true的checkbox的值截取字母拼到arrList里
        string arrList = GetSelectedKeyValues();

        exm.Answer = arrList;
        //exm.Answer = HttpUtility.HtmlEncode(this.lblAnswer.Text);
        exm.AnswerA    = HttpUtility.HtmlEncode(this.txtAnswerA.Text);
        exm.AnswerB    = HttpUtility.HtmlEncode(this.txtAnswerB.Text);
        exm.AnswerC    = HttpUtility.HtmlEncode(this.txtAnswerC.Text);
        exm.AnswerD    = HttpUtility.HtmlEncode(this.txtAnswerD.Text);
        exm.AnswerE    = HttpUtility.HtmlEncode(this.txtAnswerE.Text);
        exm.ModifiedBy = "";//config.Staff.Staff_Id;

        try
        {
            exm.Update();
            //弹出对话框
            Response.Write("<Script Langage='JavaScript'>");
            Response.Write("alert('修改成功!');");
            Response.Write("window.location='QuestionList.aspx';");
            Response.Write("</Script>");
        }
        catch
        { }
        finally
        {
            Response.Write("<script type='text/javascript'>alert('题目修改失败');window.location.href=window.location.href;</script>");
        }
    }