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 yuanwang : System.Web.UI.Page
{
    public DataBaseLayer db = new DataBaseLayer();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["UserID"] == null && Session["UserName"] != "shuanghan")
            {
                Response.Write("<script>alert(\"请管理员登录!\")</script>");
                Response.Write("<meta http-equiv='refresh' content='1;url=mp4.aspx'>");
            }
            else
            {
                BindAllPromise();
            }
        }
    }
    protected void selectPromise_DeleteCommand(object source, DataGridCommandEventArgs e)
    {
        
            SqlParameter[] prams ={
                db.ParamBuilder("@PromiseID",Convert.ToInt32(((Label)e.Item.FindControl("PromiseID")).Text),SqlDbType.Int)
            };
            //执行存储过程
            try
            {
                db.ExecuteNonQuery("Pr_Mp4_DeletePromise", prams);
                Response.Write("<script>alert(\"删除成功!\")</script>");
                //selectmp4.EditItemIndex = -1;
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert(\"删除失败!\")</script>");
            //throw new Exception(ex.Message, ex);
        }
    }
    protected void selectPromise_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        LinkButton delete = (LinkButton)e.Item.FindControl("LinkButton4");
        if (delete != null)
        {
            delete.Attributes.Add("onclick", "return confirm('你确定要删除他的许愿数据吗?')");
        }
    }
    protected void selectPromise_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        selectPromise.CurrentPageIndex = e.NewPageIndex;
        BindAllPromise();
    }
    public void BindAllPromise()
    {
        DataSet ds = db.DataSetFactory("Pr_Mp4_GetPromise");
        selectPromise.DataSource = ds;
        selectPromise.DataBind();
        ds.Dispose();
    }
}
