using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace baoge.Admin
{
	/// <summary>
	/// admin_search1 的摘要说明。
	/// </summary>
	public class admin_search1 : System.Web.UI.Page
	{

		protected System.Web.UI.WebControls.TextBox key_word;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.DropDownList search_type;
		protected System.Web.UI.WebControls.CustomValidator Cv_id;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["AdminName"]==null)
			{
				Response.Redirect("Admin_Login.aspx");
			}
			string keyword=Request.QueryString["keyword"].ToString();
			string search_type=Request.QueryString["search_type"].ToString();
		
			string c=null;
			if(search_type.ToString()=="0")
			{
				c="Title like '%"+keyword+"%'";
			}
			if(search_type.ToString()=="1")
			{
				c="Content like '%"+keyword+"%'";
			}
			DataView dv=new DataView(search.selectAllPerson());
			dv.RowFilter=c;
			dv.Sort="ArticleID Desc";
			
			this.DataGrid1.DataSource=dv;
			this.DataGrid1.DataBind();
		}



		private void Cv_id_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
		{
			string KeyWord;
			KeyWord=key_word.Text.Trim();
			if(KeyWord.IndexOf(" ")>=0 || KeyWord.IndexOf(",")>=0 || KeyWord.IndexOf("%")>=0)
			{
				args.IsValid=false;
			}
			else
			{
				args.IsValid=true;
			}
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			//						string c=null;
			//			            
			//						if(this.search_type.Items[0].Selected)
			//						{
			//							//				c="Title="+this.TextBox1.Text;
			//							c="Title like '%"+this.key_word.Text+"%'";
			//						}
			//						else
			//							//			{
			//							//			     c="Title like '%'";
			//							//			}
			//							if(this.search_type.Items[1].Selected)
			//						{
			//							c="Content like '%"+this.key_word.Text+"%'";
			//							//				c+=" and Content like '%"+this.TextBox1.Text+"%'";
			//						}
			//						DataView dv=new DataView(search.selectAllPerson());
			//						dv.RowFilter=c;
			//						dv.Sort="ArticleID Desc";
			//						this.DataGrid1.DataSource=dv;
			//						this.DataGrid1.DataBind();


			if(Page.IsValid)
			{
				string redi_wd;
				redi_wd="admin_search.aspx?keyword="+key_word.Text.ToString().Trim()+"&search_type="+search_type.SelectedItem.Value;
				//Response.Write(redi_wd);   
				Response.Redirect(redi_wd);
			}
		}
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Cv_id.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.Cv_id_ServerValidate);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
