using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using D.BLL;
using D.Common;
using D.Model;

public partial class search_Default : System.Web.UI.Page
{
    private B_Create bllCreate = new B_Create();
    private int p = 1;
    private string wd = string.Empty;
    private B_SiteLucene bllSiteLucene = new B_SiteLucene();
    private M_SiteLucene modelSiteLucene = new M_SiteLucene();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            modelSiteLucene = bllSiteLucene.GetModel();

            #region
            if (!string.IsNullOrEmpty(Request.QueryString["p"]))
            {
                try
                {
                    p = int.Parse(Request.QueryString["p"]);
                }
                catch { }
            }

            if (!string.IsNullOrEmpty(Request.QueryString["wd"]))
            {
                try
                {
                    wd = Function.Filter(Request.QueryString["wd"]);
                }
                catch { }
            }
            #endregion

            int count = 0;
            int PageSize = modelSiteLucene.PageSize;
            DataTable dt = PanGuLuceneHelper.instance.SearchIndex("", "" + wd + "", p, PageSize, out count);
            RepSearchIndex.DataSource = dt;
            RepSearchIndex.DataBind();

            int pagecount = 0;
            if (count % PageSize == 0)
            {
                pagecount = count / PageSize;
            }
            else
            {
                pagecount = count / PageSize + 1;
            }

            LitPager.Text = bllCreate.GetUltimateListPage(null, null, null, 10, "首页", "上一页", "下一页", "尾页", modelSiteLucene.CssName, p, pagecount, count, modelSiteLucene.PagerId, PageSize, "条");
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        //Response.Redirect("?wd=" + txtKeyword.Text.Trim() + "");
    }
    public string GetImgUrl(string imgurl,string url)
    {
        if (imgurl.Length > 0)
        {
            return "<div class=\"listimg\"><a href=\"" + url + "\" target=\"_blank\" class=\"imga\"><img src=\"" + imgurl + "\"></a></div>";
        }
        else
        {
            return string.Empty;
        }
    }
}