-
Notifications
You must be signed in to change notification settings - Fork 0
/
shop.aspx.cs
266 lines (231 loc) · 11 KB
/
shop.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ShoppingHotspot
{
public partial class shop : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCategory();
BindSubCat1();
BindSubCat2();
BindSubCat3();
BindSubCat4();
}
if(Request.QueryString["scat"]!=null)
{
BindProductsFromTop();
ProductCountFromTop();
}
if (Request.QueryString["sbcat"] != null)
{
BindProductsFromSide();
ProductCountFromSide();
}
}
public void BindSubCat1()
{
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 * from tblSubCategory where mainCategoryId='1'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
Repeater2.DataSource = dtt;
Repeater2.DataBind();
}
public void BindSubCat2()
{
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 * from tblSubCategory where mainCategoryId='2'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
Repeater3.DataSource = dtt;
Repeater3.DataBind();
}
public void BindSubCat3()
{
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 * from tblSubCategory where mainCategoryId='3'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
Repeater4.DataSource = dtt;
Repeater4.DataBind();
}
public void BindSubCat4()
{
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 * from tblSubCategory where mainCategoryId='4'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
Repeater5.DataSource = dtt;
Repeater5.DataBind();
}
public void BindCategory()
{
for (int i = 1; i <= 4; i++)
{
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 * from tblCategory where pos='" + i + "'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
if (dtt.Rows.Count > 0)
{
if (i == 1)
{
lblCategoryname1.Text = dtt.Rows[0][1].ToString();
}
if (i == 2)
{
lblCategoryName2.Text = dtt.Rows[0][1].ToString();
}
if (i == 3)
{
lblCategoryName3.Text = dtt.Rows[0][1].ToString();
}
if (i == 4)
{
lblCategoryName4.Text = dtt.Rows[0][1].ToString();
}
}
}
}
public void BindProductsFromTop()
{
string con = "";
con = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection sqlconn = new SqlConnection(con);
sqlconn.Open();
string scat = Request.QueryString["scat"];
string mcat = Request.QueryString["mcat"];
SqlCommand cmdd = new SqlCommand("select * from [dbo].[tblProduct] as Prod inner join[dbo].[tblSubCategory] as Subcat " +
"on Subcat.id = Prod.subCat and Subcat.mainCategoryId = Prod.mainCat " +
"where Prod.subCat ='"+ scat + "' and Prod.mainCat ='" + mcat + "'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
RepeaterProducts.DataSource = dtt;
RepeaterProducts.DataBind();
}
public void ProductCountFromTop()
{
string con = "";
con = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection sqlconn = new SqlConnection(con);
sqlconn.Open();
string scat = Request.QueryString["scat"];
string mcat = Request.QueryString["mcat"];
SqlCommand cmdd = new SqlCommand("select COUNT(*) from [dbo].[tblProduct] as Prod inner join[dbo].[tblSubCategory] as Subcat " +
"on Subcat.id = Prod.subCat and Subcat.mainCategoryId = Prod.mainCat " +
"where Prod.subCat ='" + scat + "' and Prod.mainCat ='" + mcat + "'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
lblProductCount.Text = Convert.ToString(dtt.Rows[0][0]);
}
public void BindProductsFromSide()
{
string con = "";
con = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection sqlconn = new SqlConnection(con);
sqlconn.Open();
string scat = Request.QueryString["sbcat"];
string mcat = Request.QueryString["mncat"];
SqlCommand cmdd = new SqlCommand("select * from [dbo].[tblProduct] as Prod inner join[dbo].[tblSubCategory] as Subcat " +
"on Subcat.id = Prod.subCat and Subcat.mainCategoryId = Prod.mainCat " +
"where Prod.subCat ='" + scat + "' and Prod.mainCat ='" + mcat + "'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
RepeaterProducts.DataSource = dtt;
RepeaterProducts.DataBind();
}
public void ProductCountFromSide()
{
string con = "";
con = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection sqlconn = new SqlConnection(con);
sqlconn.Open();
string scat = Request.QueryString["sbcat"];
string mcat = Request.QueryString["mncat"];
SqlCommand cmdd = new SqlCommand("select COUNT(*) from [dbo].[tblProduct] as Prod inner join[dbo].[tblSubCategory] as Subcat " +
"on Subcat.id = Prod.subCat and Subcat.mainCategoryId = Prod.mainCat " +
"where Prod.subCat ='" + scat + "' and Prod.mainCat ='" + mcat + "'", sqlconn);
SqlDataAdapter daa = new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
lblProductCount.Text = Convert.ToString(dtt.Rows[0][0]);
}
protected void btncart_Click(object sender, EventArgs e)
{
RepeaterItem item = (sender as Button).NamingContainer as RepeaterItem;
//cannot access labels in repeater as we used to do like lblName.Text so following is the method.
string Productname = (item.FindControl("lblProductName") as Label).Text;
string Price = (item.FindControl("lblPrice") as Label).Text;
string Image = (item.FindControl("lblPic") as Label).Text;
string conn = "";
conn = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection objsqlconn = new SqlConnection(conn);
objsqlconn.Open();
SqlCommand objcmd = new SqlCommand("Insert into tblCartProduct(Image,productName,Price,Quantity,TotalPrice) Values('" + Image + "','" + Productname + "','" + Price + "','" + 1 + "','" + Price + "')", objsqlconn);
objcmd.ExecuteNonQuery();
Session["AddCart"] = "AddToCart";
Response.Redirect("Login.aspx");
}
protected void btnsearch_Click(object sender, EventArgs e)
{
string conn = "";
conn = @"Data Source=DESKTOP-536RKL2;Initial Catalog=DBshoppingHotspot;Integrated Security=True";
SqlConnection objsqlconn = new SqlConnection(conn);
objsqlconn.Open();
SqlCommand cmd = new SqlCommand("select id from [dbo].[tblSubCategory] WHERE subCategory Like '%"+txtSearch.Text+ "%'", objsqlconn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
string subcatId = Convert.ToString(dt.Rows[0][0]);
objsqlconn.Close();
SqlConnection sqlconn = new SqlConnection(conn);
sqlconn.Open();
SqlCommand cmdd = new SqlCommand("select * from tblProduct WHERE subCat='"+ subcatId + "'", sqlconn);
SqlDataAdapter daa= new SqlDataAdapter(cmdd);
DataTable dtt = new DataTable();
daa.Fill(dtt);
RepeaterProducts.DataSource = dtt;
RepeaterProducts.DataBind();
sqlconn.Close();
SqlConnection sqlconn1 = new SqlConnection(conn);
sqlconn1.Open();
SqlCommand cmdd1 = new SqlCommand("select count(*) from tblProduct WHERE subCat='" + subcatId + "'", sqlconn1);
SqlDataAdapter daaa = new SqlDataAdapter(cmdd1);
DataTable dttt = new DataTable();
daaa.Fill(dttt);
lblProductCount.Text = Convert.ToString(dttt.Rows[0][0]);
}
}
}