⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.aspx.cs

📁 网上自动答疑系统(C#)
💻 CS
字号:
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.Text;

namespace dayi
{
	/// <summary>
	/// search 的摘要说明。
	/// </summary>
	public class search : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblSearchResult;
		protected System.Web.UI.WebControls.ImageButton btnSearch;
		protected System.Web.UI.WebControls.DropDownList listLimite;
		protected System.Web.UI.WebControls.TextBox txtSearchWord;
		protected System.Web.UI.WebControls.Label lblHotSearchWord;
		protected System.Web.UI.WebControls.Label lblAboutSearchWord;
	
		dayi.controlDatabase cd=new controlDatabase();

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!this.IsPostBack)
			{
				try
				{
					//显示热门搜索词
					this.lblHotSearchWord.Text=cd.hotSearchWord(25);

					//填充范围列表
					DataTable dt=cd.getDataTable("select * from [board] where rootID=0");
					this.listLimite.Items.Clear();//先清空列表
					this.listLimite.Items.Add(new ListItem("所有文章","0"));
					foreach(DataRow row in dt.Rows)
					{
						this.listLimite.Items.Add(new ListItem(row["boardName"].ToString().Trim(),row["boardID"].ToString()));
					}
				
					string type="";
					string keyword="";
					if(Request.QueryString["type"]!=null)
					{
						type=Request.QueryString["type"].ToString();
					}
					if(Request.QueryString["keyword"]!=null)
					{
						keyword=Request.QueryString["keyword"].ToString();
					}

					int page=1;
					if(Request.QueryString["page"]!=null)
					{
						page=Convert.ToInt32(Request.QueryString["page"]);
					}

					this.listLimite.SelectedValue=type;
					this.txtSearchWord.Text=keyword;

					this.lblSearchResult.Text=cd.searchQuestion(keyword,type,"search.aspx",page,30);
					if(this.lblSearchResult.Text.Trim()=="")
					{
						this.lblSearchResult.Text="没有找到任何相关记录!请继续使用搜索.<br><b>搜索技巧:</b><br>1、可以用逗号或者空格分隔多个关键字进行“或”查询;<br>2、可以用“&”号分隔多个关键字,进行“与”查询!";
					}

					//添加到字典否
					cd.addToWordbook(keyword);

					//显示相关搜索词
					this.lblAboutSearchWord.Text=cd.aboutSearchWord(keyword,30);
				}
				catch(Exception)
				{
					//Response.Redirect("err.aspx?err=出现错误,可能执行了非法操作!<br>请联系管理员");
				}
			}
		}

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

		}
		#endregion

		private void btnSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			//查找
			try
			{
				
				string type=this.listLimite.SelectedValue;
				string keyword=this.txtSearchWord.Text.Trim();
				this.lblSearchResult.Text=cd.searchQuestion(keyword,type,"search.aspx",1,30);
				if(this.lblSearchResult.Text.Trim()=="")
				{
					this.lblSearchResult.Text="没有找到任何相关记录!请继续使用搜索.<br><b>搜索技巧:</b><br>1、可以用逗号或者空格分隔多个关键字进行“或”查询;<br>2、可以用“&”号分隔多个关键字,进行“与”查询!";
				}

				//添加到字典否
				cd.addToWordbook(keyword);

				//显示相关搜索词
				this.lblAboutSearchWord.Text=cd.aboutSearchWord(keyword,30);

				//显示热门搜索词
				this.lblHotSearchWord.Text=cd.hotSearchWord(25);

			}
			catch(Exception)
			{
				Response.Redirect("err.aspx?err=出现错误,可能执行了非法操作");
				//Response.Write(ee.ToString());
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -