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 manage_Inputsurvey : System.Web.UI.Page
{
   
    static int nResult = -1;
    protected void Page_Load(object sender, EventArgs e)
    {
        Loginjudge();
        if (!Page.IsPostBack)
        {
            if (Request.Params["ShowID"] != null)
            {
                if (Int32.TryParse(Request.Params["ShowID"].ToString(), out nResult) == false) { return; }
                Bindsurvey(nResult);
            }
            
        }
    }
    private void Bindsurvey(int nSurveyitemID)
    {
        INews shownews = new Mynews();
        DataSet ds = shownews.DsGetinfo("SELECT * FROM Surveyitem WHERE ParrentID=" + nSurveyitemID);
        SurveyGridView.DataSource = ds.Tables["aa"].DefaultView;
        SurveyGridView.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        INews shownews = new Mynews();
        if (txtItem.Text.Trim().Length < 1)
        {
            return;
        }
        shownews.Executeinfo("INSERT INTO Surveyitem (Surveyitem,ParrentID) VALUES('" + txtItem.Text.ToString() + "'," + nResult + ")");
        Bindsurvey(nResult);
    }
    protected void SurveyGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        INews shownews = new Mynews();
        int nSurveyitemID = Int32.Parse(SurveyGridView.DataKeys[e.RowIndex].Value.ToString());
        shownews.Executeinfo("DELETE FROM Surveyitem WHERE SurveyitemID=" + nSurveyitemID);
        Bindsurvey(nResult);
    }
    private void Loginjudge()
    {
        if (Session["Login"] == null)
        {
            Response.Redirect("Error.aspx");
        }
        else
        {
            if (Session["Login"] != "pass")
            {
                Response.Redirect("Error.aspx");
            }

        }
    }
}
