📄 result.aspx.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
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.OleDb;
public partial class _Default : System.Web.UI.Page
{
string bookname;
protected void Page_Load(object sender, EventArgs e)
{
bookname = Request.QueryString["bookname"];
int page =Convert.ToInt16(Request.QueryString["page"]);
// TextBox1.Text = bookname;
get_data(bookname,page);
}
protected void AccessDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
protected void TextBox1_TextChanged1(object sender, EventArgs e)
{
}
public void get_data(string bookname,int page)
{
int resultNum = 0;
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\searcher\\GotoBuy.mdb";
string Sql = "SELECT [ztm], [ISBN],[ZZ],[CBS],[jg],[M_ID],[ddj],[zyj],[ztj] FROM [goods_mouse] WHERE ztm LIKE '%" + bookname + "%';";
OleDbConnection thisConnection = new OleDbConnection(ConnectionString);
OleDbCommand thisCommand = new OleDbCommand(Sql, thisConnection);
thisCommand.CommandType = CommandType.Text;
try
{
// 打开数据库连接
thisCommand.Connection.Open();
string Sql2 = "SELECT COUNT(*) FROM [goods_mouse] WHERE ztm LIKE '%" + bookname + "%';";
OleDbCommand thisCommand2 = new OleDbCommand(Sql2, thisConnection);
thisCommand2.CommandType = CommandType.Text;
resultNum = Convert.ToInt32(thisCommand2.ExecuteScalar());
// 执行SQL语句,并返回DataReader对象
OleDbDataReader dr = thisCommand.ExecuteReader();
Label1.Text = "图书 有" + resultNum + "项符合<B>" + Request.QueryString["bookname"] + "</B>的查询结果,以下是第" + page+ "页";
if (resultNum == 0) { Label1.Text="抱歉!没有找到关于<B>" + Request.QueryString["bookname"] + "</B>的查询结果";}
// 循环读取结果集
int i=1;
while (dr.Read())
{
if (i > page * 10 - 10)
{
//价格排序
string zy, dd, zt,str="";
int zyj, ddj, ztj;
zyj=Convert.ToInt16(dr["zyj"]);
ddj=Convert.ToInt16(dr["ddj"]);
ztj=Convert.ToInt16(dr["ztj"]);
//zy = "<image src=jlogo.gif bordor=0><font size=2 color=#2554C7><strong>¥" + dr["zyj"] + " (" + (Convert.ToDouble(dr["zyj"]) / Convert.ToDouble(dr["jg"]) * 10 + 0.0001).ToString().Substring(0, 3) + "折)</strong></font> ";
zy = "<a href='http://www.amazon.cn/mn/advancedSearchApp?type=book&isbn="+ dr["ISBN"] +"'><image src=jlogo.gif border=0><font size=2 color=#2554C7><strong>¥" + dr["zyj"] + " (" + (Convert.ToDouble(dr["zyj"]) / Convert.ToDouble(dr["jg"]) * 10 + 0.0001).ToString().Substring(0, 3) + "折)</strong></font></a> ";
//dd="<image src=dlogo.gif bordor=0><font size=2 color=#2554C7><strong>¥" + dr["ddj"] + " (" + (Convert.ToDouble(dr["zyj"]) / Convert.ToDouble(dr["jg"]) * 10 + 0.0001).ToString().Substring(0, 3) + "折)</strong></font> ";
dd = "<a href='http://search.book.dangdang.com/search.aspx?key=" + dr["ISBN"] + "&page=1'><image src=dlogo.gif border=0><font size=2 color=#2554C7><strong>¥" + dr["ddj"] + " (" + (Convert.ToDouble(dr["ddj"]) / Convert.ToDouble(dr["jg"]) * 10 + 0.0001).ToString().Substring(0, 3) + "折)</strong></font></a> ";
//zt = "<image src=bclogo.gif bordor=0><font size=2 color=#2554C7><strong>¥" + dr["ztj"] + " (" + (Convert.ToDouble(dr["zyj"]) / Convert.ToDouble(dr["jg"]) * 10 + 0.0001).ToString().Substring(0, 3) + "折)</strong></font> ";
zt = "<a href=' http://www.bookschina.com/book_find/bookFindResult.aspx?bookname=" + dr["ztm"] +"'><image src=bclogo.gif border=0><font size=2 color=#2554C7><strong>¥" + dr["ztj"] + " (" + (Convert.ToDouble(dr["ztj"]) / Convert.ToDouble(dr["jg"]) * 10 + 0.0001).ToString().Substring(0, 3) + "折)</strong></font> ";
if (zyj == 0) { zy = ""; }
if (ddj == 0) { dd = ""; }
if (ztj == 0) { zt = ""; }
if (zyj <= ddj && ddj <= ztj) { str = zy + dd + zt; }
if (zyj <= ztj && ztj <= ddj) { str = zy + zt + dd; }
if (ddj <= zyj && zyj <= ztj) { str = dd + zy + zt; }
if (ddj <= ztj && ztj <= zyj) { str = dd + zt + zy; }
if (ztj <= ddj && ddj <= zyj) { str = zt + dd + zy; }
if (ztj <= zyj && zyj <= ddj) { str = zt + zy + dd; }
Label2.Text += "<a href='product.aspx?id=" + dr["M_ID"] + "'><font color=#2554C7><strong>" + dr["ztm"] + "</strong></font></a><br><font size=2>作者:<font color=#2554C7>" + dr["ZZ"] + "</font> 出版社:<font color=#2554C7>" + dr["CBS"] + " </font><br>ISBN:<font color=#2554C7>" + dr["ISBN"] + " </font>定价:<font color=#2554C7>" + dr["jg"] + "</font></font><br>";
/*if (Convert.ToInt16(dr["zyj"]) != 0) { Label2.Text += "<image src=jlogo.gif bordor=0><font size=2 color=#2554C7><strong>¥" + dr["zyj"] + " (" + (Convert.ToDouble(dr["zyj"]) / Convert.ToDouble(dr["jg"]) * 10+0.0001).ToString().Substring(0, 3) + "折)</strong></font> "; }
if (Convert.ToInt16(dr["ddj"]) != 0) { Label2.Text += "<image src=dlogo.gif bordor=0><font size=2 color=#2554C7><strong>¥" + dr["ddj"] + " (" + (Convert.ToDouble(dr["zyj"]) / Convert.ToDouble(dr["jg"]) * 10 + 0.0001).ToString().Substring(0, 3) + "折)</strong></font> "; }
if (Convert.ToInt16(dr["ztj"]) != 0) { Label2.Text += "<image src=bclogo.gif bordor=0><font size=2 color=#2554C7><strong>¥" + dr["ztj"] + " (" + (Convert.ToDouble(dr["zyj"]) / Convert.ToDouble(dr["jg"]) * 10 + 0.0001).ToString().Substring(0, 3) + "折)</strong></font> "; }*/
Label2.Text += str;
Label2.Text += "<br><br><br>";
}
i++;
if (i > page * 10) {
break;
}
}
// 关闭DataReader
dr.Close();
}
catch (SqlException ex)
{
// 异常处理
Response.Write(ex.ToString());
}
finally
{
// 关闭数据库连接
thisCommand.Connection.Close();
}
page_manage(page, resultNum,bookname);
}
public void page_manage(int page,int resultNum,string bookname)
{
int pages,start,i;
pages=resultNum/10+1;
if (pages == 1) return;
start = page / 10;
start=start*10+1;
if (page % 10 == 0) { start = page - 9; }
if (page> 1)
{
Label2.Text += "<a href='result.aspx?bookname=" + bookname + "&page=" + (page - 1) + "'><font color=#2554C7><strong>上一页</strong></font></a> ";
}
for (i = start; i < start + 10; i++)
{
if (i == page)
{
Label2.Text += i + " ";
}
else
{
Label2.Text += "<a href='result.aspx?bookname=" + bookname + "&page=" + i + "'><font color=#2554C7><strong>[" + i + "]</strong></font></a> ";
}
if (i == pages) { break; }
}
if(page<pages) {
Label2.Text += "<a href='result.aspx?bookname=" + bookname + "&page=" + (page + 1) + "'><font color=#2554C7><strong>下一页</strong></font></a> ";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
Response.Redirect("result.aspx?page=1&bookname=" + TextBox1.Text);
}
else
{
Response.Redirect("index.aspx");
}
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -