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
{
	/// <summary>
	/// search1 的摘要说明。
	/// </summary>
	public class search1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox key_word;
		protected System.Web.UI.WebControls.DropDownList search_type;
		protected System.Web.UI.WebControls.CustomValidator Cv_id;
		protected System.Web.UI.WebControls.Button btnsubmit;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			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();
			
		}






		
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnsubmit.Click += new System.EventHandler(this.btnsubmit_Click);
			this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		
		#endregion
		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();
		//
		//
		//			
		//		}

		private void btnsubmit_Click(object sender, System.EventArgs e)
		{
			if(Page.IsValid)
			{
				string redi_wd;
				redi_wd="search.aspx?keyword="+key_word.Text.ToString().Trim()+"&search_type="+search_type.SelectedItem.Value;
				//Response.Write(redi_wd);   
				Response.Redirect(redi_wd);
			}
		}

		private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
		         this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
			     this.DataGrid1.DataBind();
		}

		
	}
}
