温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:明日网上商城购物系统源码
当前文件:
MingriNetShop/User/index.aspx.cs,打开代码结构图
MingriNetShop/User/index.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class index : System.Web.UI.Page 14
{ 15
UserInfoClass ucObj = new UserInfoClass(); 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
19
if (!IsPostBack) 20
{ 21
RefineBind(); 22
HotBind(); 23
DiscountBind(); 24
25
26
} 27
} 28
//绑定市场价格 29
public string GetMKPStr(string P_Str_MarketPrice) 30
{ 31
return ucObj.VarStr(P_Str_MarketPrice, 2); 32
} 33
//绑定会员价格 34
public string GetMBPStr(string P_Str_MemberPrice) 35
{ 36
return ucObj.VarStr(P_Str_MemberPrice, 2); 37
} 38
39
//当购买商品时,获取商品信息 40
public SaveSubGoodsClass GetSubGoodsInformation(DataListCommandEventArgs e, DataList DLName) 41
{ 42
//获取购物车中的信息 43
SaveSubGoodsClass Goods = new SaveSubGoodsClass(); 44
Goods.GoodsID = int.Parse(DLName.DataKeys[e.Item.ItemIndex].ToString()); 45
string GoodsStyle = e.CommandArgument.ToString(); 46
int index = GoodsStyle.IndexOf("|"); 47
if (index < -1 || index + 1 >= GoodsStyle.Length) 48
return Goods; 49
Goods.GoodsWeight = float.Parse(GoodsStyle.Substring(0, index)); 50
Goods.MemberPrice =float.Parse( GoodsStyle.Substring(index + 1)); 51
return (Goods); 52
53
} 54
public void AddShopCart(DataListCommandEventArgs e, DataList DLName) 55
{ 56
if (Session["UID"] != null) 57
{ 58
SaveSubGoodsClass Goods = null; 59
Goods = GetSubGoodsInformation(e,DLName); 60
if (Goods == null) 61
{ 62
//显示错误信息 63
Response.Write("<script>alert('没有可用的数据');</script>"); 64
return; 65
} 66
else 67
{ 68
ucObj.AddShopCart(Goods.GoodsID, Goods.MemberPrice, Convert.ToInt32(Session["UID"].ToString()),Goods.GoodsWeight); 69
Response.Write("<script>alert('恭喜您,添加成功!')</script>"); 70
71
} 72
} 73
else 74
{ 75
Response.Write("<script>alert('请先登录,谢谢合作!');</script>"); 76
77
} 78
79
} 80
81
public void RefineBind() 82
{ 83
ucObj.DGIBind(1, "Refine", DLrefinement); 84
} 85
public void HotBind() 86
{ 87
ucObj.DGIBind(2, "Hot", DLHot); 88
} 89
public void DiscountBind() 90
{ 91
ucObj.DGIBind(3, "Discount", DLDiscount); 92
} 93
protected void DLrefinement_ItemCommand(object source, DataListCommandEventArgs e) 94
{ 95
if (e.CommandName == "detailSee") 96
{ 97
Session["address"] = ""; 98
Session["address"] = "index.aspx"; 99
Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(DLrefinement.DataKeys[e.Item.ItemIndex].ToString())); 100
} 101
else if (e.CommandName == "buyGoods") 102
{ 103
AddShopCart(e,DLrefinement); 104
} 105
} 106
protected void DLHot_ItemCommand(object source, DataListCommandEventArgs e) 107
{ 108
if (e.CommandName == "detailSee") 109
{ 110
Session["address"] = ""; 111
Session["address"] = "index.aspx"; 112
Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(DLHot.DataKeys[e.Item.ItemIndex].ToString())); 113
} 114
else if (e.CommandName == "buyGoods") 115
{ 116
117
AddShopCart(e,DLHot); 118
} 119
} 120
protected void DLDiscount_ItemCommand(object source, DataListCommandEventArgs e) 121
{ 122
if (e.CommandName == "detailSee") 123
{ 124
Session["address"] = ""; 125
Session["address"] = "index.aspx"; 126
Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(DLDiscount.DataKeys[e.Item.ItemIndex].ToString())); 127
} 128
else if (e.CommandName == "buyGoods") 129
{ 130
AddShopCart(e,DLDiscount); 131
} 132
} 133
} 134




UserInfoClass ucObj 
}
}