-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCart.aspx.cs
202 lines (182 loc) · 8.46 KB
/
Cart.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace AlTarwadaWebStore
{
public partial class Cart : System.Web.UI.Page
{
Int64 CartTotal = 0;
int newv = 0;
protected void Page_Load(object sender, EventArgs e)
{
Session["measure"] = 0.ToString();
BindCartNumber();
if (Request.Cookies["CartPID"] != null)
{
SqlConnection myconnect = new SqlConnection(@"Data Source=DHANYA-SUDHA\SQLEXPRESS01;Initial Catalog=Database_class_Data;Integrated Security=True");
myconnect.Open();
DataTable dt = new DataTable();
string CookieData = Request.Cookies["CartPID"].Value.Split('=')[1];
string[] CookieDataArray = CookieData.Split(',');
if (CookieDataArray.Length > 0)
{
h4Noitem.InnerText = "Cart (" + CookieDataArray.Length + ") items";
for (int i = 0; i > CookieDataArray.Length; i++)
{
string q = "SELECT Product_det.*, Order_Cart.*, c_color.*FROMc_color INNER JOIN Order_Cart ON c_color.clr_id = Order_Cart.clr_cl AND c_color.clr_id = Order_Cart.clr_des INNER JOIN Product_det ON Order_Cart.pro = Product_det.p_id WHERE Order_Cart.session_details='" + Session["tell"] + "'AND Order_Cart.date_order= '" + DateTime.UtcNow.Date + "'";
SqlCommand myconn = new SqlCommand(q, myconnect);
using (SqlDataAdapter sadap = new SqlDataAdapter(myconn))
{
sadap.Fill(dt);
SqlDataReader result = myconn.ExecuteReader();
while (result.Read())
{
if (result.GetString(2) == "Women")
{
Session["measure"] = 1.ToString();
}
}
}
CartTotal += Convert.ToInt64(dt.Rows[i]["p_price"]);
}
spanCartTotal.InnerText = CartTotal.ToString();
spantotal.InnerText = "Dhs. " + CartTotal.ToString();
divtotal.Visible = true;
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
else
{
h4Noitem.InnerText = "Your cart is Empty";
divtotal.Visible = false;
}
}
}
protected void remove_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 CookiePIDUpdate = String.Join(",", CookiePIDList.ToArray());
if (CookiePIDUpdate == "")
{
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"] = CookiePIDUpdate;
CartProducts.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(CartProducts);
}
SqlConnection myconnect = new SqlConnection(@"Data Source=DHANYA-SUDHA\SQLEXPRESS01;Initial Catalog=Database_class_Data;Integrated Security=True");
myconnect.Open();
string q = "DELETE FROM Order_Cart WHERE session_details='" + Session["tell"] + "'AND pro= '" + Eval("p_id") + "'";
SqlCommand myconn = new SqlCommand(q, myconnect);
using (SqlDataAdapter sadap = new SqlDataAdapter(myconn))
{
DataTable dd = new DataTable();
sadap.Fill(dd);
SqlDataReader result = myconn.ExecuteReader();
while (result.Read())
{
if (result.GetString(2) == "Women")
{
Session["measure"] = 1.ToString();
}
}
}
Response.Redirect("Cart.aspx");
}
protected void lwork(object sender, EventArgs e)
{
Session["query"] = "Lace";
Response.Redirect("Products.aspx");
}
protected void ework(object sender, EventArgs e)
{
Session["query"] = "Embroidery";
Response.Redirect("Products.aspx");
}
protected void bwork(object sender, EventArgs e)
{
Session["query"] = "Baby bag ";
Response.Redirect("Products.aspx");
}
protected void fwork(object sender, EventArgs e)
{
Session["query"] = "Baby full set";
Response.Redirect("Products.aspx");
}
protected void cwork(object sender, EventArgs e)
{
Session["query"] = "Cradle";
Response.Redirect("Products.aspx");
}
public void BindCartNumber()
{
if (Request.Cookies["CartPID"] != null)
{
string CookiePID = Request.Cookies["CartPID"].Value.Split('=')[1];
string[] ProductArray = CookiePID.Split(',');
int ProductCount = ProductArray.Length;
pcount.InnerText = ProductCount.ToString();
}
else
{
pcount.InnerText = 0.ToString();
}
}
protected void buy_Click(object sender, EventArgs e)
{
if (Session["measure"].Equals(1.ToString()))
{
using (SqlConnection connection = new SqlConnection(@"Data Source=DHANYA-SUDHA\SQLEXPRESS01;Initial Catalog=Database_class_Data;Integrated Security=True"))
{
string sql = "INSERT INTO bill VALUES(@date_order,@session_details, @tot_price,@measure)";
using (SqlCommand cmd = new SqlCommand(sql, connection))
{
connection.Open();
cmd.Parameters.AddWithValue("@session_details", Session["User"]);
cmd.Parameters.AddWithValue("@date_order", DateTime.UtcNow.Date);
cmd.Parameters.AddWithValue("@tot_price", CartTotal);
cmd.ExecuteNonQuery();
newv = (int)cmd.ExecuteScalar();
}
}
Response.Redirect("measure.aspx?id="+ newv);
}
else
{
using (SqlConnection connection = new SqlConnection(@"Data Source=DHANYA-SUDHA\SQLEXPRESS01;Initial Catalog=Database_class_Data;Integrated Security=True"))
{
string sql = "INSERT INTO bill VALUES(@date_order,@session_details, @tot_price)";
using (SqlCommand cmd = new SqlCommand(sql, connection))
{
connection.Open();
cmd.Parameters.AddWithValue("@session_details", Session["User"]);
cmd.Parameters.AddWithValue("@date_order", DateTime.UtcNow.Date);
cmd.Parameters.AddWithValue("@tot_price", CartTotal);
cmd.ExecuteNonQuery();
newv = (int)cmd.ExecuteScalar();
}
}
Response.Redirect("Order.aspx?id=" + newv);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Cart.aspx");
}
}
}