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 System.Data.SqlClient;

public partial class wormadmin_search : System.Web.UI.Page
{
    SqlConnection one=conn.sqlconn();
    protected string action = System.Web.HttpContext.Current.Request.QueryString["action"];
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Session["superad"] == null || Session["superpw"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            Page.Theme = "SkinFile";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            search_class();
            //日志的分类下拉列框绑定
            if (action == "dairy")
            {
                dairy_class();
            }
            //图片的分类下拉列框绑定
            if (action == "pic")
            {
                pic_class();
            }
            date1.Value = "";
            date2.Value = "";
        }
    }

    protected void search_class()
    {
        temptitle.Text = action;
        switch (action)
        { 
            case "dairy":
                search_title.Text = "日志搜索";
                break;
            case "pic":
                search_title.Text = "图片搜索";
                break;
            case "dairy_pl":
                search_title.Text = "评论搜索";
                break;
            case "customer_manage":
                search_title.Text = "用户搜索";
                break;
            default:
                search_title.Text = "暂时没有相关搜索";
                break;
        }
        
    }

    protected void btsearch_Click(object sender, EventArgs e)
    {
        Server.Transfer(temptitle.Text+".aspx?search=1");
    }

    //下拉列框日记分类
    protected void dairy_class()
    {
        try
        {
            one.Open();
            string sql = "select distinct dclass from classdai";
            SqlCommand cmd = new SqlCommand(sql, one);
            SqlDataReader rs = cmd.ExecuteReader();
            while (rs.Read())
            {
                dlclass.Items.Add(new ListItem(rs["dclass"].ToString(), rs["dclass"].ToString()));
            }
        }
        catch (System.Exception ee)
        {
            Response.Write(ee.Message.ToString());
        }
        finally
        {
            one.Dispose();
            one.Close();
        }
    }

    //图片分类下拉菜单的数据绑定
    protected void pic_class()
    {
        try
        {
            one.Open();
            string sql = "select distinct pclass from picclass";
            SqlCommand cmd = new SqlCommand(sql, one);
            SqlDataReader rs = cmd.ExecuteReader();
            while (rs.Read())
            {
                dlclass.Items.Add(new ListItem(rs["pclass"].ToString(), rs["pclass"].ToString()));
            }
        }
        catch (System.Exception ee)
        {
            Response.Write(ee.Message.ToString());
        }
        finally
        {
            one.Close();
        }
    }
}
