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

public partial class system_Course_homeworklist : 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()
    {
        DataSet ds = new DataSet();
        string str_ClassId = Request["vid"];
        string str_sTitle = "";
        if (Request["ClassId"] != null)
        {
            string strSql_Class = "select [ID],[ClassName] from NT_Class where ID=" + Request["ClassId"] + "";
            OleDbDataReader sdr_Class = DbHelperOleDb.ExecuteDataReader(CommandType.Text, strSql_Class, null);
            if (sdr_Class.HasRows)
            {
                while (sdr_Class.Read())
                {
                    str_sTitle = sdr_Class["ClassName"].ToString();
                }
            }
            sdr_Class.Close();
        }


        //计算总数的语句的头部
        string sql_CountFirst = string.Empty;
        sql_CountFirst += " select";
        sql_CountFirst += " count(*)";
        sql_CountFirst += " from NT_Data ";
        sql_CountFirst += " where 1=1";
        if (str_ClassId != null && str_ClassId != "")
        {
            sql_CountFirst += " and ParentId=" + str_ClassId;
        }

        //查询语句的头部
        string sql_SelectFirst = "select ID ,ClassId,Title,sTitle,TitlePicture,Intro,Content,AddTime,FilePath,OrderNum,MemberId ";
        sql_SelectFirst += " from NT_Data ";
        sql_SelectFirst += " where 1=1";

        if (str_ClassId != null && str_ClassId != "")
        {
            sql_SelectFirst += " and ParentId=" + str_ClassId;
        }

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


        sql_SelectFirst += " order by OrderNum desc, 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 += "<tr><td align='center'>" + dr["ID"] + "</td><td>" + dr["Title"] + "</td>";
            lit_video.Text += "<td>" + str_sTitle + "</td>";

            string strsql = "select * from NT_Member where ID=" + dr["MemberId"];

            string strsql1 = "select * from NT_Data where ParentId=" + dr["ID"];
            DataSet ds1 = DbHelperOleDb.ExecuteDataSet(CommandType.Text, strsql1, null);

            ds = DbHelperOleDb.ExecuteDataSet(CommandType.Text, strsql, null);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                lit_video.Text += "<td>" + ds1.Tables[0].Rows.Count + "</td>";
                
            }

            string strsql11 = "select * from NT_Member where ID=" + Session["ID1"];
            DataSet ds11 = DbHelperOleDb.ExecuteDataSet(CommandType.Text, strsql11, null);
            if (ds11 != null && ds11.Tables[0].Rows.Count > 0)
            {
                if (ds11.Tables[0].Rows[0]["Identity"].ToString() == "教师")
                {
                    lit_video.Text += "<td><a href='worklist.aspx?vid=" + dr["ID"] + "&ClassId="+dr["ClassId"]+"'>批改作业</a></td>";
                }
                else
                {
                    lit_video.Text += "<td><a href='correcthomework.aspx?vid=" + dr["ID"] + "'>做作业</a></td>";
                }
            }
            lit_video.Text += "</tr>";

        }


    }
    #endregion

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