using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Data.OleDb;

public partial class system_Video_videodetails : System.Web.UI.Page
{
    public DataRow dr;
    public DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

        PageFunc.IfSystemLogin(this.Page);

        #endregion
        //if (IsPostBack)
        //    return;

        if (Request.QueryString["vid"] != null && Request.QueryString["vid"].ToString() != "")
        {
            dr = FrontFunc.GetDataByID(Request.QueryString["vid"].ToString());
        }

        BindData();
    }

    //视频评论
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txt_Content.Text.Trim() == "")
        {
            JavaScriptFunc.Alert(this.Page, "不能为空");
            return;
        }

        StringBuilder strSql = new StringBuilder();
        strSql.Append("insert into NT_Video(");
        strSql.Append("[MemberID],[DataId],[Content])");
        strSql.Append(" values (");
        strSql.Append("@MemberID,@DataId,@Content)");
        OleDbParameter[] parameters = 
            {
                new OleDbParameter("@MemberID", OleDbType.Integer,4),
                new OleDbParameter("@DataId", OleDbType.Integer,4),
                new OleDbParameter("@Content", OleDbType.VarChar)
            };
        parameters[0].Value = int.Parse(Session["ID1"].ToString());
        parameters[1].Value = int.Parse(Request.QueryString["vid"].ToString());
        parameters[2].Value = txt_Content.Text.Trim();


        DbHelperOleDb.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        txt_Content.Text = "";
        BindData();

        JavaScriptFunc.Alert(this.Page, "评论成功");
    }

    #region 评论绑定
    /// <summary>
    /// 数据绑定
    /// </summary>
    private void BindData()
    {

        //计算总数的语句的头部
        string sql_CountFirst = string.Empty;
        sql_CountFirst += " select";
        sql_CountFirst += " count(*)";
        sql_CountFirst += " from NT_Video ";
        sql_CountFirst += " where DataId="+Request.QueryString["vid"].ToString();

        //查询语句的头部
        string sql_SelectFirst = "select v.Content,v.AddTime,m.Account,m.Name ";
        sql_SelectFirst += " from NT_Video v left join NT_Member m on v.MemberId=m.ID ";
        sql_SelectFirst += " where DataId=" + Request.QueryString["vid"].ToString();
        sql_SelectFirst += " order by v.ID desc";


        dt = WebControlsFunc.GetDataTableByAspNetPager(AspNetPager1, sql_CountFirst, sql_SelectFirst);


    }
    #endregion

    #region 分页事件
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindData();
    }
    #endregion
}
