📄 goodsstyle.aspx.cs
字号:
using System;
using System.Data;
using System.Data.OleDb;
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;
public partial class User_GoodsStyle : System.Web.UI.Page
{
UserInfo ui = new UserInfo();
string type;
DataList dltmp;
protected void Page_Load(object sender, EventArgs e)
{
string tmp=Request["Type"].Trim();
if (tmp == "1")
{
dlRefinement.Visible = true;
refineBind();
//type = "Isrefinement";
dltmp = dlRefinement;
ViewState["dltmp"] = null;
ViewState["dltmp"] = "Isrefinement";
lblType.Text = "最新推介";
}
else if (tmp == "2")
{
dlHot.Visible = true;
hotBind();
//type = "IsHot";
dltmp = dlHot;
ViewState["dltmp"] = null;
ViewState["dltmp"] = "IsHot";
lblType.Text = "热销商品";
}
else if (tmp == "3")
{
dlDiscount.Visible = true;
hotDiscount();
//type = "IsDiscount";
dltmp = dlDiscount;
ViewState["dltmp"] = null;
ViewState["dltmp"] = "IsDiscount";
lblType.Text = "打折商品";
}
type = ViewState["dltmp"].ToString();
countPage();
}
public void refineBind()
{
ui.DGBind(1, "refine", dlRefinement, false);
}
public void hotBind()
{
ui.DGBind(2, "hot", dlHot, false);
}
public void hotDiscount()
{
ui.DGBind(3, "Discount", dlDiscount, false);
}
protected void dlRefinement_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "detail")
{
Session["address"] = "";
Session["address"] = "~/User/GoodsStyle.aspx?Type=1" + "&page=" + Request.QueryString["page"];
Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlRefinement.DataKeys[e.Item.ItemIndex].ToString()));
}
else if (e.CommandName == "buy")
{
addShopCart(e, dlRefinement);
}
}
protected void dlHot_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "detail")
{
Session["address"] = "";
Session["address"] = "~/User/GoodsStyle.aspx?Type=2" + "&page=" + Request.QueryString["page"];
Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlHot.DataKeys[e.Item.ItemIndex].ToString()));
}
else if (e.CommandName == "buy")
{
addShopCart(e, dlHot);
}
}
protected void dlDiscount_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "detail")
{
Session["address"] = "";
Session["address"] = "~/User/GoodsStyle.aspx?Type=3" + "&page=" + Request.QueryString["page"];
Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlDiscount.DataKeys[e.Item.ItemIndex].ToString()));
}
else if (e.CommandName == "buy")
{
addShopCart(e, dlDiscount);
}
}
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;
}
public void countPage()
{
DBConn dbconn = new DBConn();
OleDbConnection conn = dbconn.GetConnection();
changePage cp = new changePage();
string sql = "SELECT * from tb_GoodsInfo where " + type + "=1";
cp.TotalPicture = ui.countLine(sql); //总个数
cp.PageNow = Convert.ToInt32(Request.QueryString["page"]);
int start = (cp.PageNow - 1) * cp.PictureNum;
OleDbDataAdapter ad = new OleDbDataAdapter(sql, conn);
DataSet ds = new DataSet();
//显示的开始,结束.
if (cp.TotalPicture < cp.PictureNum)
{
ui.DGBind(Request.QueryString["Type"], dltmp, start, cp.TotalPicture,type);
}
else
{
ui.DGBind(Request.QueryString["Type"], dltmp, start, cp.PictureNum,type);
if (cp.TotalPicture % cp.PictureNum == 0)
{
cp.PageNum = cp.TotalPicture / cp.PictureNum;
}
else if (cp.TotalPicture % cp.PictureNum > 0)
{
cp.PageNum = (cp.TotalPicture / cp.PictureNum) + 1;
}
}
for (int i = 1; i <= cp.PageNum; ++i)
{
lblPage.Text += "[<a href='GoodsStyle.aspx?Type=" + Request.QueryString["Type"].ToString() + "&page=" + i.ToString() + "'>" + i.ToString() + "</a>]";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -