-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.aspx.cs
88 lines (80 loc) · 2.48 KB
/
Default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Data;
using System.Configuration;
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.SqlClient;
using System.Collections;
public partial class Default : System.Web.UI.Page
{
CommonClass ccObj = new CommonClass();
HatClass gcObj = new HatClass();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HotBind();
}
}
protected void HotBind()
{
gcObj.DLDisplayHat(1,this.dlHot, "Hot");
}
protected void Produc_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "chkDetail")
{
AddressBack(e);
}
else if (e.CommandName == "buy")
{
AddShopCart(e);
}
}
public void AddressBack(DataListCommandEventArgs e)
{
Session["address"] = "";
Session["address"] = "Default.aspx";
Response.Redirect("~/Pages/User/ProductDetails.aspx?id=" + Convert.ToInt32(e.CommandArgument.ToString()));
}
public void AddShopCart(DataListCommandEventArgs e)
{
/*If login*/
CheckIfLogin();
Hashtable hashCar;
if (Session["ShopCart"] == null)
{
//if no shopping cart
hashCar = new Hashtable();
hashCar.Add(e.CommandArgument,1);
Session["ShopCart"] = hashCar;
Response.Redirect("~/Pages/User/ShoppingCart.aspx");
}
else
{
//if has shopping cart
hashCar = (Hashtable)Session["ShopCart"];//get hash table of cart
if (hashCar.Contains(e.CommandArgument))//if this item in the cart, add 1
{
int count = Convert.ToInt32(hashCar[e.CommandArgument].ToString());//get the number of items
hashCar[e.CommandArgument] = (count + 1);//add 1 item
}
else
hashCar.Add(e.CommandArgument,1);
Response.Redirect("~/Pages/User/ShoppingCart.aspx");
}
}
public void CheckIfLogin()
{
if ((Session["UserName"] == null))
{
//Response.Write("<script>alert('Sorry, you are not member, please register first.');location='Default.aspx'</script>");
//Response.End();
Response.Redirect("~/Pages/User/Login.aspx");
}
}
}