-
Notifications
You must be signed in to change notification settings - Fork 0
/
CartProduct.aspx.cs
114 lines (100 loc) · 3.83 KB
/
CartProduct.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ShoppingHotspot
{
public partial class CartProduct : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
}
else
{
BindProducts();
diplayOrderSummary();
}
}
public void BindProducts()
{
string con = "";
con = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection sqlconn = new SqlConnection(con);
sqlconn.Open();
string CartUserId = Convert.ToString(Session["id"]);
SqlCommand cmdd = new SqlCommand("select * from tblCartProduct where UserId= '" + CartUserId + "'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
RepeaterCartProducts.DataSource = dtt;
RepeaterCartProducts.DataBind();
}
public void diplayOrderSummary()
{
string con = "";
con = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection sqlconn = new SqlConnection(con);
sqlconn.Open();
SqlCommand cmdd = new SqlCommand("SELECT SUM(CAST(TotalPrice as int)) FROM tblCartProduct", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
lblSubTotal.Text = Convert.ToString(dtt.Rows[0][0]);
lblGrandTotal.Text = Convert.ToString(dtt.Rows[0][0]);
}
[System.Web.Services.WebMethod]
public static string UpdateQuantity(string ID, string Quantity, string Price)
{
string conn = "";
conn = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection objsqlconn = new SqlConnection(conn);
objsqlconn.Open();
int totalPrice = Convert.ToInt32(Quantity) * Convert.ToInt32(Price);
string tp = Convert.ToString(totalPrice);
SqlCommand objcmd = new SqlCommand("update tblCartProduct set Quantity= '" + Quantity + "',TotalPrice= '" + tp + "' where id= '" + ID + "' ", objsqlconn);
try
{
objcmd.ExecuteNonQuery();
return "success";
}
catch (Exception ex)
{
throw ex;
}
finally
{
objsqlconn.Close();
}
}
[System.Web.Services.WebMethod]
public static string RemoveCart(string ID)
{
string conn = "";
conn = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection objsqlconn = new SqlConnection(conn);
objsqlconn.Open();
SqlCommand objcmd = new SqlCommand("delete from tblCartProduct where id= '" + ID + "' ", objsqlconn);
try
{
objcmd.ExecuteNonQuery();
return "success";
}
catch (Exception ex)
{
throw ex;
}
finally
{
objsqlconn.Close();
}
}
}
}