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;

public partial class New_List : System.Web.UI.Page
{
    public int tID_1 = 0;
    public int tID_2 = 0;
    string key = "";
    BLL.News news = new BLL.News();
    BLL.Class_1 c_1 = new BLL.Class_1();
    BLL.Class_2 c_2 = new BLL.Class_2();
    protected void Page_Load(object sender, EventArgs e)
    {//这里逻辑有点问题,如果大类不存在,有小类也不赋值,再研究.
        Title = "新闻列表";
        if((Request.Params["class1"] != null)&&(Request.Params["class1"]!=""))
        {
            tID_1 = Int32.Parse(Request.Params["class1"].ToString());
            if (Request.Params["class2"] != null)
            {
                tID_2 = Int32.Parse(Request.Params["class2"].ToString());
                if (!IsPostBack)
                    Bind();
            }
            else
            {
                if (!IsPostBack)
                    Bind();
            }
        }
        else
        {
            Bind();
        }
    }
    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
        Bind();
    }
    protected void Bind()
    {
        //在这里绑定类别,不知合适不合适.
        BindTitle();
        if (Request.Params["key"] != null)
            key = Request.Params["key"].ToString();
        DataView dv = news.getNewslist(tID_1, tID_2, key).DefaultView;
        PagedDataSource pds = new PagedDataSource();

        AspNetPager1.RecordCount = dv.Count;
        pds.DataSource = dv;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        pds.PageSize = AspNetPager1.PageSize;

        this.Rpt_newlist.DataSource = pds;
        this.Rpt_newlist.DataBind();
    }
    protected void BindTitle()
    {
        if ((tID_1 > 0) || (tID_2 > 0) || ((Request.Params["key"] != null) && (Request.Params["key"] != "")))
        {
            if (tID_1 > 0)
                Ltl_class1.Text = c_1.getClassName(tID_1);
            if (tID_2 > 0)
                Ltl_class2.Text = c_2.getClassName(tID_2);
            else
                Ltl_class2.Text = "全部小类";
            if ((Request.Params["key"] != null) && (Request.Params["key"] != ""))
            {
                //通过url不能传中文值,还是需要编码?用session吧.
                //了解,不能直接在地址栏输入中文:a.aspx?key=新闻
                Ltl_key.Text = "&gt;" + Request.Params["key"].ToString();
            }
        }
        else
        {
            Ltl_class1.Text = "全部新闻列表";
            Ltl_class2.Text = "全部小类";
        }
    }
}
