📄 find.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 User_Find : System.Web.UI.Page
{
UserInfo ui=new UserInfo();
protected void Page_Load(object sender, EventArgs e)
{
DBConn dbconn = new DBConn();
OleDbConnection conn = dbconn.GetConnection();
string sql = "Select * from tb_GoodsInfo where GoodsName like '%" + Request.QueryString["find"] + "%'";
int num = ui.countLine(sql);
if (num > 0)
{
Label1.Text = "查询结果个数为:" + num.ToString();
}
else
{
Label1.Text = "对不起,找不到你需要的物品";
}
OleDbDataAdapter ad = new OleDbDataAdapter(sql, conn);
DataSet ds = new DataSet();
ad.Fill(ds, "find");
DataList1.DataSource = ds.Tables["find"].DefaultView;
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "detail")
{
Session["address"] = "";
Session["address"] = "~/User/kindsPage.aspx";
Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString()));
}
else if (e.CommandName == "buy")
{
addShopCart(e, DataList1);
}
}
public void addShopCart(DataListCommandEventArgs e, DataList dlName)
{
if (Session["UID"] != null)
{
SaveGoodsClass sgc = getSaveGoodsClass(e, dlName);
string userID = Session["UID"].ToString();
ui.addShopCart(sgc.GoodsID, sgc.MemberPrice, userID);
ui.MessageBox(Page, "添加成功");
}
}
public SaveGoodsClass getSaveGoodsClass(DataListCommandEventArgs e, DataList dlName)
{
SaveGoodsClass goods = new SaveGoodsClass();
goods.MemberPrice = Convert.ToDouble(e.CommandArgument.ToString());
goods.GoodsID = dlName.DataKeys[e.Item.ItemIndex].ToString();
return goods;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -