using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class etwuser_password_baohu : System.Web.UI.Page
{
    public int userid = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cookEtwuser"];
        if (Request.Cookies["cookEtwuser"] == null)
        {
            Response.Redirect("../index.aspx");
        }
         DataSet ds1 = DbHelperSQL.Query("select userid from etw_user where username='" + GetCookie["username"].ToString() + "'");
         if (ds1.Tables[0].Rows.Count > 0)
         {
              userid = Convert.ToInt32(ds1.Tables[0].Rows[0]["userid"]);
         }
         if (!IsPostBack)
        {
            etw.etw_baohu baohu = new etw.etw_baohu();
            DataSet dsb = baohu.check_baohu(userid);
            if (dsb.Tables[0].Rows.Count>0)
            {
                answertxt.Text = dsb.Tables[0].Rows[0]["answer"].ToString();
                definequestiontxt.Text = dsb.Tables[0].Rows[0]["definequestion"].ToString();
                defineanswertxt.Text = dsb.Tables[0].Rows[0]["defineanswer"].ToString();
            }
            etw.etw_question que = new etw.etw_question();
            DataSet dsc = que.GetList();
            DropDownList1.DataSource = dsc.Tables[0].DefaultView;
            DropDownList1.DataTextField = "question";
            DropDownList1.DataValueField = "id";
            DropDownList1.DataBind();
        }
        
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        etw.etw_baohu lead = new etw.etw_baohu();
        lead.userid =userid;
        lead.questionid = Convert.ToInt32(DropDownList1.SelectedItem.Value);
        lead.answer = answertxt.Text.Trim();
        lead.definequestion = definequestiontxt.Text.Trim();
        lead.defineanswer = defineanswertxt.Text.Trim();
        lead.Add();
        Fun.JsAlerT("添加成功！", "password_baohu.aspx"); 
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {

    }
}
