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 Base;


public partial class Search_SearchNews : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }

    }

    private void Bind()
    {
        string str = "";
        string type = "";
        int page = 1;
        if (Request.QueryString["keyword"] != null && Request.QueryString["keyword"] != "")
        {
            str = Request.QueryString["keyword"].ToString();
            lblKey.Text += str;
        }
        if (Request.QueryString["page"] != null && Request.QueryString["page"] != "")
        {
            page = int.Parse(Request.QueryString["page"].ToString());
        }
       
        string strselect = "W_Consultative.*,W_ConsultativeType.Name";
        string table = "W_Consultative inner join W_ConsultativeType on W_Consultative.TypeID=W_ConsultativeType.ID";
       // string strWhere = "";//
        string strWhere=" Title like '%" + str + "%'";
        //if (Request.QueryString["Type"] != null && Request.QueryString["Type"] != "")
        //{
        //    type = Request.QueryString["Type"].ToString();
        //    strWhere += "and  W_ConsultativeType.Name='%" + type + "%'";
        //}
        DataTable dt = PageList.GetDataTable(strWhere, table, 1, "AddDate", "*", 10, 1, 0);
        if (dt.Rows.Count == 0)
        {
            lblMessage.Visible = true;
            lblMessage.Text = "<font color='red' size='5pt'>暂无数据</font>";
        }
        else
        {
            lblMessage.Visible = false;
            lblCount.Text = " " + dt.Rows.Count + " ";
        }
        dlstNews.DataSource = dt.DefaultView;
        dlstNews.DataBind();
        lblPagination.Text = PageList.GoToPager(page, 10, "SearchNews.aspx?page", strWhere, table);

    }

    public string GetShortDate(string dateStr)
    {
        if (dateStr != string.Empty)
            return Convert.ToDateTime(dateStr).ToShortDateString();
        else
            return String.Empty;
    }

    public string ProcessImg(string strImage)
    {
        if (strImage != string.Empty)
        {
            string image =ProcessAbsoluteUrl(strImage);
            string str = "<img src='" + image+"'width='83px' height='83px'>";
            return str;
        }
        else
            return string.Empty;
    }

    protected void dropArea_SelectedIndexChanged(object sender, EventArgs e)
    {
        string str = "";
        int page = 1;
        string Date = dropDate.SelectedValue;
        if (Request.QueryString["str"] != null && Request.QueryString["str"] != "")
        {
            str = Request.QueryString["str"].ToString();
        }
        if (Request.QueryString["page"] != null && Request.QueryString["page"] != "")
        {
            page = int.Parse(Request.QueryString["page"].ToString());
        }
        string strWhere = "";                        //1=1 and name like '%'" + str + "'%'
        string strselect = "W_Consultative.*,W_ConsultativeType.Name";
        string table = "W_Consultative inner join W_ConsultativeType on W_Consultative.TypeID=W_ConsultativeType.ID";
        if (Date != "")
        {
            switch (Date.ToString())
            {
                case "最近三天":
                    strWhere = strWhere + " datediff(day,AddDate,getdate())<=3";
                    break;
                case "最近一周":
                    strWhere = strWhere + " datediff(day,AddDate,getdate())<=7";
                    break;
                case "最近一个月":
                    strWhere = strWhere + " datediff(day,AddDate,getdate())<=30";
                    break;
                case "最近三个月":
                    strWhere = strWhere + " datediff(m,AddDate,getdate()) <=3";
                    break;
                default:
                   // strWhere = strWhere + " datediff(m,AddDate,getdate())";
                    break;
            }
        }
        DataTable dt = PageList.GetDataTable(strWhere, table, 1, "AddDate", "*", 10, 1, 0);
        if (dt.Rows.Count == 0)
        {
            lblMessage.Visible = true;
            lblMessage.Text = "<font color='red' size='5pt'>暂无数据</font>";
        }
        else
        {
            lblMessage.Visible = false;
            lblCount.Text = " " + dt.Rows.Count + " ";
        }
        dlstNews.DataSource = dt.DefaultView;
        dlstNews.DataBind();

        lblPagination.Text = PageList.GoToPager(page, 10, "SearchNews.aspx?page", strWhere, table);
        dropDate.SelectedValue = Date;
    }
}
