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


public partial class system_Message_message : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

        PageFunc.IfSystemLogin(this.Page);

        #endregion
        if (IsPostBack)
            return;

        BindData();
    }

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

        //计算总数的语句的头部
        string sql_CountFirst = string.Empty;
        sql_CountFirst += " select";
        sql_CountFirst += " count(*)";
        sql_CountFirst += " from NT_Message ";
        sql_CountFirst += " where 1=1";

        //查询语句的头部
        string sql_SelectFirst = "select * ";
        sql_SelectFirst += " from NT_Message ";
        sql_SelectFirst += " where 1=1";

        string strsql = "select * from NT_Member where ID=" + Session["ID1"];
        DataSet ds4 = DbHelperOleDb.ExecuteDataSet(CommandType.Text, strsql, null);
        if (ds4 != null && ds4.Tables[0].Rows.Count > 0)
        {
            if (ds4.Tables[0].Rows[0]["Identity"].ToString() != "教师")
            {
                sql_CountFirst += " and ParentId =0 and MemberId=" + Session["ID1"];
                sql_SelectFirst += " and ParentId =0 and MemberId=" + Session["ID1"];
            }
            else {
                sql_CountFirst += " and ParentId =0 ";
                sql_SelectFirst += " and ParentId =0 ";
            }
           
        }

        sql_SelectFirst += " order by ID desc";


        DataTable dt_video = WebControlsFunc.GetDataTableByAspNetPager(AspNetPager1, sql_CountFirst, sql_SelectFirst);
        lit_video.Text = "";
        foreach (DataRow dr in dt_video.Rows)
        {
            //lit_video.Text += "<li><a href='videodetails.aspx?vid=" + dr["ID"] + "' title='" + dr["Title"] + "'><img src='" + dr["TitlePicture"] + "' /><p>" + FrontFunc.Cutstring(dr["Title"].ToString(), 13) + "</p></a></li>";

            lit_video.Text += "<tr><td align='center'>" + dr["ID"] + "</td>";

            string sql = "select * from NT_Member where 1=1 and ID=" + dr["MemberId"];
             
            DataSet ds = DbHelperOleDb.ExecuteDataSet(CommandType.Text, sql, null);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {

                lit_video.Text += "<td>" + ds.Tables[0].Rows[0]["Name"] + "</td>";
                

                //if (ds.Tables[0].Rows[0]["Identity"].ToString() == "教师")
                //{
                //    lit_video.Text += "<td><a href='coursedetails.aspx?vid=" + dr["ID"] + "&ClassId=" + dr["ClassId"] + "'>添加实验项目</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='courselist.aspx?vid=" + dr["ID"] + "&ClassId=" + dr["ClassId"] + "'>查看实验项目</a></td>";
                //}
                //else
                //{
                //    lit_video.Text += "<td><a href='courselist.aspx?vid=" + dr["ID"] + "&ClassId=" + dr["ClassId"] + "'>查看实验项目</a></td>";
                //}
            }

            lit_video.Text += "<td>" + dr["title"] + "</td>";
            lit_video.Text += "<td>" + Convert.ToDateTime(dr["AddTime"]).ToShortDateString() + "</td>";


            string sql1 = "select [Name] from  NT_Member left join NT_Message on NT_Message.MemberId = NT_Member.ID  where ParentId=" + dr["ID"] + " order by NT_Message.[id] desc";
                DataSet ds1 = DbHelperOleDb.ExecuteDataSet(CommandType.Text, sql1, null);
                if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
                {
                    lit_video.Text += "<td>" + ds1.Tables[0].Rows[0]["Name"] + "</td>";
                    lit_video.Text += "<td> <a href ='/system/Message/messageCK.aspx?vid="+dr["ID"]+"' />" + ds1.Tables[0].Rows.Count.ToString() + "</a></td>";
                }
                else {
                    lit_video.Text += "<td>暂无解答</td>";
                    lit_video.Text += "<td>0</td>";

                }
             
            lit_video.Text += "<td><a href='messageCK.aspx?vid=" + dr["ID"] + "'>查看</a></td>";



            lit_video.Text += "</tr>";

            //lit_video.Text += "<tr><td>" + dr["Title"] + "</td><td><a href='coursedetails.aspx?vid=" + dr["ID"] + "'>添加实验项目</a></td></tr>";
        }


    }
    #endregion

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

}
