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;
using System.Data.SqlClient;

public partial class manage_Editsurvey : System.Web.UI.Page
{
    INews shownews = new Mynews();
    protected void Page_Load(object sender, EventArgs e)
    {
        Loginjudge();
        if (!Page.IsPostBack)
        {
            Showdiaocha();
        }

    }
    //绑定控件
    private void Showdiaocha()
    {
        DataSet ds = Getdiaocha();
        DiaochaGridView.DataSource = ds.Tables["aa"].DefaultView;
        DiaochaGridView.DataBind();
    }
    //打开调查数据库
    public DataSet Getdiaocha()
    {
      
        DataSet ds = shownews.DsGetinfo("SELECT * FROM Survey ORDER BY SurveyID DESC");
        return ds;
    }
    //更新显示
    protected void DiaochaoGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int nSurveyID = Int32.Parse(DiaochaGridView.DataKeys[e.RowIndex].Value.ToString());
        
        shownews.Executeinfo("UPDATE Survey SET ShowID=0");
        shownews.Executeinfo("UPDATE Survey SET ShowID=1 WHERE SurveyID=" + nSurveyID);
        Showdiaocha();
    }
    //插入标题
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtTitle.Text.Trim().Length < 1)
        {
            return;
        }
        shownews.Executeinfo("INSERT INTO Survey (Title) VALUES('" + txtTitle.Text.ToString() + "')");
        txtTitle.Text = "";
        Showdiaocha();
    }
    //删除标题
    protected void DiaochaGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int nSurveyID = Int32.Parse(DiaochaGridView.DataKeys[e.RowIndex].Value.ToString());
        shownews.Executeinfo("DELETE FROM Survey WHERE SurveyID=" + nSurveyID);
        Showdiaocha();
    }
    private void Loginjudge()
    {
        if (Session["Login"] == null)
        {
            Response.Redirect("Error.aspx");
        }
        else
        {
            if (Session["Login"] != "pass")
            {
                Response.Redirect("Error.aspx");
            }

        }
    }
}
