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 mp4manage : 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
            {
                BindAllmp4();
            }
        }
    }
    protected void selectmp4_CancelCommand(object source, DataGridCommandEventArgs e)
    {
        selectmp4.EditItemIndex = -1;
        BindAllmp4();

    }
    protected void selectmp4_DeleteCommand(object source, DataGridCommandEventArgs e)
    {

        SqlParameter[] prams ={db.ParamBuilder("@DownID",Convert.ToInt32(((Label)e.Item.FindControl("DownID")).Text),SqlDbType.Int)
            };
        //执行存储过程
        try
        {
            db.ExecuteNonQuery("Pr_Mp4_Delete", 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 selectmp4_EditCommand(object source, DataGridCommandEventArgs e)
    {
        selectmp4.EditItemIndex = (int)e.Item.ItemIndex;
        BindAllmp4();

    }
    protected void selectmp4_UpdateCommand(object source, DataGridCommandEventArgs e)
    {
        SqlParameter[] prams ={
            db.ParamBuilder("@DownID",Convert.ToInt32(((Label)e.Item.FindControl("DownID")).Text),SqlDbType.Int),
            db.ParamBuilder("@DownTitle",((TextBox)e.Item.FindControl("DownTitle")).Text,SqlDbType.VarChar),
            db.ParamBuilder("@DownFormat",((TextBox)e.Item.FindControl("DownFormat")).Text,SqlDbType.VarChar),
            db.ParamBuilder("@Hits",Convert.ToInt32(((TextBox)e.Item.FindControl("Hits")).Text),SqlDbType.Int),
            db.ParamBuilder("@UpdateTime",DateTime.Now,SqlDbType.DateTime),
            db.ParamBuilder("@DownIntro",((TextBox)e.Item.FindControl("DownIntro")).Text,SqlDbType.VarChar),
            db.ParamBuilder("@DownRecommend",Convert.ToInt32(((TextBox)e.Item.FindControl("DownRecommend")).Text),SqlDbType.Int)
            };
        try
        {
            //执行存储过程
            db.ExecuteNonQuery("Pr_Mp4_Update", prams);
            Response.Write("<script>alert(\"更新成功!\")</script>");
            //selectmp4.EditItemIndex = -1;
        }
        catch (Exception ex)
        {
            //throw new Exception(ex.Message, ex);
            Response.Write("<script>alert(\"更新失败!\")</script>");
        }
        finally
        {
            BindAllmp4();
        }

        
    }
    protected void selectmp4_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        LinkButton delete = (LinkButton)e.Item.FindControl("LinkButton4");
        if (delete != null)
        {
            delete.Attributes.Add("onclick","return confirm('你确定要删除该mp4数据吗?')");
        }
    }
    protected void selectmp4_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        selectmp4.CurrentPageIndex = e.NewPageIndex;
        BindAllmp4();
    }
    public void BindAllmp4()
    {
        DataSet ds = db.DataSetFactory("Pr_Mp4_GetAllMp4");
        selectmp4.DataSource = ds;
        selectmp4.DataBind();
        ds.Dispose();
    }
}
