📄 search.aspx.cs
字号:
using System;
using System.Data;
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 Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write(this.RadioButtonList1.SelectedItem.Text);
if (Session["search"] == null)
{
Label7 .Text ="没有查询到相关结果,请重新输入";
}
else
{
string strSql;
string strkind = Session["search"].ToString();
Label7.Text = strkind;
strSql = "select * from Book where Bkind='" + strkind + "'";
OleDbConnection cnA = new OleDbConnection();
cnA = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + Server.MapPath("~/BDB/BookStore.mdb"));
cnA.Open();
OleDbCommand cmA = new OleDbCommand(strSql, cnA);//查询语句
OleDbDataReader drA = cmA.ExecuteReader();
DataList1.DataSource = drA;
this.DataBind();
cnA.Close();
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
if (this.RadioButtonList1.SelectedItem.Text == "书籍类型")
{
string strSql;
string strkind = TextBox1.Text;//
//Session.Remove("search");
Label7.Text = "搜索关于"+strkind+"的结果";
//SELECT * FROM [Book] WHERE ([BKind] LIKE '%' + ? + '%')
strSql = "select * from Book where Bkind LIKE '%' + '"+strkind +"' + '%'";
OleDbConnection cnA = new OleDbConnection();
cnA = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + Server.MapPath("~/BDB/BookStore.mdb"));
cnA.Open();
OleDbCommand cmA = new OleDbCommand(strSql, cnA);//查询语句
OleDbDataReader drA = cmA.ExecuteReader();
if (drA.Read())
{
DataList1.DataSource = drA;
this.DataBind();
}
else
{
this.Label8.Text = "没有查询到相关结果,请重新输入";
DataList1.DataSource = null;
this.DataBind();
}
cnA.Close();
}
else if (this.RadioButtonList1.SelectedItem.Text == "作者")
{
string strSql;
string strkind = TextBox1.Text;// Session["search"]=
Label7.Text = "搜索关于" + strkind + "的结果";
//SELECT * FROM [Book] WHERE ([BKind] LIKE '%' + ? + '%')
strSql = "select * from Book where BAuthor LIKE '%' + '" + strkind + "' + '%'";
OleDbConnection cnA = new OleDbConnection();
cnA = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + Server.MapPath("~/BDB/BookStore.mdb"));
cnA.Open();
OleDbCommand cmA = new OleDbCommand(strSql, cnA);//查询语句
OleDbDataReader drA = cmA.ExecuteReader();
if (drA.Read())
{
DataList1.DataSource = drA;
this.DataBind();
}
else
{
this.Label8.Text = "没有查询到相关结果,请重新输入";
DataList1.DataSource = null;
this.DataBind();
}
cnA.Close();
}
else if (this.RadioButtonList1.SelectedItem.Text == "出版社")
{
string strSql;
string strkind = TextBox1.Text;// Session["search"]=
Label7.Text = "搜索关于" + strkind + "的结果";
//SELECT * FROM [Book] WHERE ([BKind] LIKE '%' + ? + '%')
strSql = "select * from Book where BPress LIKE '%' + '" + strkind + "' + '%'";
OleDbConnection cnA = new OleDbConnection();
cnA = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + Server.MapPath("~/BDB/BookStore.mdb"));
cnA.Open();
OleDbCommand cmA = new OleDbCommand(strSql, cnA);//查询语句
OleDbDataReader drA = cmA.ExecuteReader();
if (drA.Read())
{
DataList1.DataSource = drA;
this.DataBind();
}
else
{
this.Label8.Text = "没有查询到相关结果,请重新输入";
DataList1.DataSource = null;
this.DataBind();
}
cnA.Close();
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session["search"] = "四六级考试";
Response.Redirect("search.aspx");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Session["search"] = "计算机考试";
Response.Redirect("search.aspx");
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Session["search"] ="动漫";
Response.Redirect("search.aspx");
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
Session["search"] = "小说";
Response.Redirect("search.aspx");
}
protected void LinkButton5_Click(object sender, EventArgs e)
{
Session["search"] = "艺术";
Response.Redirect("search.aspx");
}
protected void LinkButton6_Click(object sender, EventArgs e)
{
Session["search"] = "外语";
Response.Redirect("search.aspx");
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
Label BName = (Label)e.Item.FindControl("Label1");
string BBName = BName.Text.ToString();
Label BKind = (Label)e.Item.FindControl("Label2");
string BBKind = BKind.Text.ToString();
Label BAuthor = (Label)e.Item.FindControl("Label4");
string BBAuthor = BAuthor.Text.ToString();
Label BChuban = (Label)e.Item.FindControl("Label3");
string BBChuban = BChuban.Text.ToString();
Label BPrice = (Label)e.Item.FindControl("Label5");
string BBPrice = BPrice.Text.ToString();
//Response.Write(BBPrice );
string StrCoon = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath("BDB/BookStore.mdb");
OleDbConnection cnA = new OleDbConnection();
cnA.ConnectionString = StrCoon;
cnA.Open();
string sqlinsert = " INSERT INTO [BookCar] ([BName], [BKind],[BAuthor],[BChuban],[BPrice1],[BPrice2]) VALUES ('" + BBName + "','" + BBKind + "','" + BBAuthor + "','" + BBChuban + "','" + BBPrice + "','" + BBPrice + "')";
OleDbCommand ccma = new OleDbCommand(sqlinsert, cnA);
ccma.ExecuteNonQuery();
cnA.Close();
Response.Write("<script>alert('已加入到购物车!')</script>");
}
}
/*
private void ConOdb(string strsql)//搜索系统数据库中的货物项
{
}
protected void Button1_Click(object sender, EventArgs e)//按产品名称查询
{
string strSql;
strSql = "select * from goods where goodsname='" + TextBox1.Text + "'";
ConOdb(strSql);
}
protected void Button2_Click(object sender, EventArgs e)//按产品类型查询
{
string strSql;
if (DropDownList1.SelectedItem.Value == "0")
strSql = "select * from goods";
else
strSql = "select * from goods where type1='" + DropDownList1.SelectedItem.Text + "'";
ConOdb(strSql);
}
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -