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 Spaces.Blog;
using System.Collections.Generic;
using Spaces;

public partial class blog_Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
        AspNetPager1.PageChanged += new Xiaoxiao.WebUI.PageChangedEventHandler(AspNetPager1_PageChanged);
        if (!IsPostBack)
        {
       
            BindPost();
        }
    }

    void AspNetPager1_PageChanged(object src, Xiaoxiao.WebUI.PageChangedEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindPost();
    }

    private void BindPost()
    {
        string key = Request.QueryString["keyWord"];
        SearchType st = GetSearchType();
        if (key != null)
        {
            PagedBlogSearch pt = new PagedBlogSearch(key.TrimStart(' ').TrimEnd(' '), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
            pt.SearchType = st;
            int count;
            DataView dv = Blogs.Blog_SearchTopic(pt, out count);
            AspNetPager1.RecordCount = count;
            Entries.DataSource = dv;
            Entries.DataBind();
            txtKey.Text = key;
         
        }
    }

    private SearchType GetSearchType()
    {
        SearchType st = SearchType.Title;
        if (Request.QueryString["Type"] == null)
            return st;
        try {
            st = (SearchType)int.Parse(Request.QueryString["Type"]);
        
        }
        catch {
            st = SearchType.Title;
        }
        return st;
    
    }
  
}
