-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathCart.aspx.cs
More file actions
119 lines (108 loc) · 4.29 KB
/
Cart.aspx.cs
File metadata and controls
119 lines (108 loc) · 4.29 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Cart : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCartProducts();
}
}
private void BindCartProducts()
{
if (Request.Cookies["CartPID"] != null)
{
string CookieData = Request.Cookies["CartPID"].Value.Split('=')[1];
string[] CookieDataArray = CookieData.Split(',');
if (CookieDataArray.Length > 0)
{
h5NoItems.InnerText = "MY CART (" + CookieDataArray.Length + " Items)";
DataTable dtBrands = new DataTable();
Int64 CartTotal = 0;
Int64 Total = 0;
for (int i = 0; i < CookieDataArray.Length; i++)
{
string PID = CookieDataArray[i].ToString().Split('-')[0];
string SizeID = CookieDataArray[i].ToString().Split('-')[1];
String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
using (SqlCommand cmd = new SqlCommand("select A.*,dbo.getSizeName(" + SizeID + ") as SizeNamee,"
+ SizeID + " as SizeIDD,SizeData.Name,SizeData.Extention from tblProducts A cross apply( select top 1 B.Name,Extention from tblProductImages B where B.PID=A.PID ) SizeData where A.PID="
+ PID + "", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dtBrands);
}
}
}
CartTotal += Convert.ToInt64(dtBrands.Rows[i]["PPrice"]);
Total += Convert.ToInt64(dtBrands.Rows[i]["PSelPrice"]);
}
rptrCartProducts.DataSource = dtBrands;
rptrCartProducts.DataBind();
divPriceDetails.Visible = true;
spanCartTotal.InnerText = CartTotal.ToString();
spanTotal.InnerText = "Rs. " + Total.ToString();
spanDiscount.InnerText = "- " + (CartTotal - Total).ToString();
}
else
{
//TODO Show Empty Cart
h5NoItems.InnerText = "Your Shopping Cart is Empty";
divPriceDetails.Visible = false;
}
}
else
{
//TODO Show Empty Cart
h5NoItems.InnerText = "Your Shopping Cart is Empty";
divPriceDetails.Visible = false;
}
}
protected void btnRemoveItem_Click(object sender, EventArgs e)
{
string CookiePID = Request.Cookies["CartPID"].Value.Split('=')[1];
Button btn = (Button)(sender);
string PIDSIZE = btn.CommandArgument;
List<String> CookiePIDList = CookiePID.Split(',').Select(i => i.Trim()).Where(i => i != string.Empty).ToList();
CookiePIDList.Remove(PIDSIZE);
string CookiePIDUpdated = String.Join(",", CookiePIDList.ToArray());
if (CookiePIDUpdated == "")
{
HttpCookie CartProducts = Request.Cookies["CartPID"];
CartProducts.Values["CartPID"] = null;
CartProducts.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(CartProducts);
}
else
{
HttpCookie CartProducts = Request.Cookies["CartPID"];
CartProducts.Values["CartPID"] = CookiePIDUpdated;
CartProducts.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(CartProducts);
}
Response.Redirect("~/Cart.aspx");
}
protected void btnBuyNow_Click(object sender, EventArgs e)
{
if (Session["USERNAME"] != null)
{
Response.Redirect("~/Payment.aspx");
}
else
{
Response.Redirect("~/SignIn.aspx?rurl=cart");
}
}
}