📄 searchresult.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication8.firstPage
{
/// <summary>
/// searchResult 的摘要说明。
/// </summary>
public class searchResult : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlTableCell a;
protected System.Web.UI.HtmlControls.HtmlTableCell b;
protected System.Web.UI.HtmlControls.HtmlGenericControl time;
protected System.Web.UI.HtmlControls.HtmlInputButton searching;
protected System.Web.UI.HtmlControls.HtmlInputHidden type;
protected System.Web.UI.HtmlControls.HtmlGenericControl key;
protected System.Web.UI.HtmlControls.HtmlInputText keyword;
protected System.Web.UI.HtmlControls.HtmlTableCell show;
protected System.Web.UI.HtmlControls.HtmlTableCell pages;
protected System.Web.UI.HtmlControls.HtmlTableCell c;
DataSet reader;
DataRowCollection rows;
Search search;
string html="";
protected System.Web.UI.HtmlControls.HtmlGenericControl total;
string typePrevious;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session["userName"]==null)
Response.Redirect("../login.aspx");
//if(reader)
//reader.Clear();
int timeSpace = System.DateTime.Now.Millisecond;
search = new Search(Application["market"].ToString());
typePrevious = Request["type"];
if(typePrevious == "网站")
{
a.Style.Add("font-weight","bold");
a.Style.Add("vertical-align","top");
reader = search.siteSearch(Request["keyword"]);
}
else if(typePrevious == "新闻")
{
b.Style.Add("font-weight","bold");
b.Style.Add("vertical-align","top");
reader = search.newsSearch(Request["keyword"]);
}
else
{
c.Style.Add("font-weight","bold");
c.Style.Add("vertical-align","top");
reader = search.adsSearch(Request["keyword"]);
}
timeSpace = System.DateTime.Now.Millisecond - timeSpace;
time.InnerText = timeSpace.ToString();
key.InnerText = Request["keyword"];
rows = reader.Tables[0].Rows;
total.InnerText = rows.Count.ToString();
if(rows.Count > 0)
Show();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.searching.ServerClick += new System.EventHandler(this.searching_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void searching_ServerClick(object sender, System.EventArgs e)
{
Response.Redirect("searchResult.aspx?keyword="+keyword.Value+"&type="+type.Value+"&page=1");
}
public void Show()
{
int recordPerPage = 9;
int total = rows.Count;
int page = (int)(new Int32Converter().ConvertFromString(Request["page"]));
int tempRecord = (recordPerPage+1)*(page-1);
int totalPages = (total+recordPerPage)/(recordPerPage+1);
int temp = 1;
html += "<div align='center'>结果页码: ";
while(temp <= totalPages)
{
if(temp == page)
html += "<A href='searchResult.aspx?keyword="+Request["keyword"]+"&type="+Request["type"]+"&page="+temp+"'><FONT color='#cc0033'>"+temp+" </FONT></A>";
else
html += "<A href='searchResult.aspx?keyword="+Request["keyword"]+"&type="+Request["type"]+"&page="+temp+"'>"+temp+" </A>";
temp++;
}
html += "<A href='searchResult.aspx?keyword="+Request["keyword"]+"&type="+Request["type"]+"&page="+(page+1)+"'>下一页</A>";
pages.InnerHtml = html;
html = "";
string title,body;
if(typePrevious == "网站")
{
title = "address";
body = "description";
}
else if (typePrevious == "新闻")
{
title = "title";
body = "body";
}
else
{
title = "title";
body = "description";
}
while(recordPerPage>=0 && tempRecord < total)
{
if(title.Equals("address"))
{
if(rows[tempRecord]["type"].ToString().Equals("2"))
{
html += "<P class=g><FONT color=#cc0033>"+Request["keyword"]+" </FONT><Font color='blue'><a href=../company/comSite.aspx?studentNO="+rows[tempRecord]["studentNO"]+" target=_blank>"+rows[tempRecord][title]+"</a></font> <B>...</B><BR>"+
"<FONT size='-1'>"+rows[tempRecord][body]+" <B>...</B></font></p><BR>";
}
else
{
html += "<P class=g><FONT color=#cc0033>"+Request["keyword"]+" </FONT><Font color='blue'><a href=../company/index.aspx?studentNO="+rows[tempRecord]["studentNO"]+" target=_blank>"+rows[tempRecord][title]+"</a></font> <B>...</B><BR>"+
"<FONT size='-1'>"+rows[tempRecord][body]+" <B>...</B></font></p><BR>";
}
}
else
html += "<P class=g><FONT color=#cc0033>"+Request["keyword"]+" </FONT><Font color='blue'>"+rows[tempRecord][title]+"</font> <B>...</B><BR>"+
"<FONT size='-1'>"+rows[tempRecord][body]+" <B>...</B></font></p><BR>";
recordPerPage--;
tempRecord++;
}
show.InnerHtml = html;
search.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -