-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHome.aspx.cs
400 lines (374 loc) · 15.4 KB
/
CHome.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data;
public partial class CHome : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(
WebConfigurationManager.ConnectionStrings["Connect"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["EmailID"] == null)
{ Response.Redirect("DEfault.aspx"); }
else
{
HyperLink login = (HyperLink)Master.FindControl("login");
login.Text = "My Accounts";
login.NavigateUrl = "Account.aspx";
HyperLink reg = (HyperLink)Master.FindControl("register");
reg.Visible = false;
HyperLink home = (HyperLink)Master.FindControl("home");
home.NavigateUrl = "CHome.aspx";
//BindGrid();
RepeaterCar();
BindRepeater1();
BindRepeater2();
BindRepeater3();
}
}
}
private void BindRepeater1()
{
con.Open();
SqlCommand cmd = new SqlCommand("select Distinct (VehicleType) from Vehicle where Status=1", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
outerRep.DataSource = ds;
outerRep.DataBind();
con.Close();
}
private void BindRepeater2()
{
con.Open();
SqlCommand cmd = new SqlCommand("select Distinct (FuelType) from Vehicle where Status=1", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
Repeater2.DataSource = ds;
Repeater2.DataBind();
con.Close();
}
private void BindRepeater3()
{
con.Open();
SqlCommand cmd = new SqlCommand("select Distinct (Transmission) from Vehicle where Status=1", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
Repeater3.DataSource = ds;
Repeater3.DataBind();
con.Close();
}
private void RepeaterCar()
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT VehicleID, Model,Price,Image,FuelType,Transmission,VehicleType FROM Vehicle where Status=1"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ViewCars.DataSource = dt;
ViewCars.DataBind();
con.Close();
}
}
}
}
// private void BindGrid()
// {
// using (SqlCommand cmd = new SqlCommand("SELECT VehicleID, Model, Color,Price,Image, FuelType,Transmission , VehicleType FROM Vehicle where Status=1"))
// {
// using (SqlDataAdapter sda = new SqlDataAdapter())
// {
// cmd.Connection = con;
// sda.SelectCommand = cmd;
// using (DataTable dt = new DataTable())
// {
// sda.Fill(dt);
// vehicle.DataSource = dt;
// vehicle.DataBind();
// }
// }
// }
// }
// //protected void Unnamed_Click(object sender, EventArgs e)
// //{
// // string text = Find.Text.ToString().Trim();
// // con.Open();
// // using (SqlCommand cmd = new SqlCommand("SELECT VehicleID, Model, Color,Price, Image, FuelType, Transmission , VehicleType FROM Vehicle where Status=1 and Model like '%" + text + "%'", con))
// // {
// // using (SqlDataAdapter sda = new SqlDataAdapter())
// // {
// // cmd.Connection = con;
// // sda.SelectCommand = cmd;
// // using (DataTable dt = new DataTable())
// // {
// // sda.Fill(dt);
// // vehicle.DataSource = dt;
// // vehicle.DataBind();
// // }
// // }
// // }
// //}
protected void vehicletype(object sender, EventArgs e)
{
LinkButton link = (LinkButton)sender;
string text = link.Text.Trim();
con.Open();
using (SqlCommand cmd = new SqlCommand("select vehicleid, model, color,price,image, fueltype,transmission , vehicletype from vehicle where status=1 and vehicletype='" + text + "'"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ViewCars.DataSource = dt;
ViewCars.DataBind();
con.Close();
}
}
}
}
// }
// protected void BOOK_Click(object sender, EventArgs e)
// {
// string email = Session["EmailID"].ToString().Trim();
// con.Open();
// SqlCommand cmd = new SqlCommand("Select CustomerID from Customer where EmailID='"+email+"'", con);
// int eid = Convert.ToInt32(cmd.ExecuteScalar());
// Button clickedbutton = (Button)sender; //get clicked button
// GridViewRow row = (GridViewRow)clickedbutton.NamingContainer; //get the row where the button clicked
// int ind = row.RowIndex;
// int vid = Convert.ToInt32(vehicle.DataKeys[ind].Values[0]);
// var date= DateTime.Now.ToString("yyyy-MM-dd");
// Label prc = (Label)vehicle.Rows[ind].FindControl("vcPrice");
// SqlCommand cmd2 = new SqlCommand("Insert into Orders(Date, Amount , OrderStatus, CustomerID,VehicleID ) Values(@date,@amount,@status,@cid,@vid)", con);
// cmd2.Parameters.AddWithValue("@date", date);
// cmd2.Parameters.AddWithValue("@amount", prc.Text);
// cmd2.Parameters.AddWithValue("@status", 0);
// //cmd2.Parameters.AddWithValue("@eid", null);
// cmd2.Parameters.AddWithValue("@cid", eid);
// cmd2.Parameters.AddWithValue("@vid", vid);
// int status = cmd2.ExecuteNonQuery();
// if (status == 1)
// {
// ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Car booked successfully. You will redirected to my accounts ');window.location='Account.aspx'", true);
// }
// else
// {
// ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Couldnot book. Try again later');", true);
// }
// con.Close();
// }
protected void sortby_Click(object sender, ImageClickEventArgs e)
{
string text = null ;
string text1 = Find.Text.ToString().Trim();
con.Open();
text = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text1 + "%'";
int s = int.Parse(dropdownlist1.SelectedValue);
if (s == 0)
{
text = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text1 + "%' ";
}
if (s == 1)
{
text = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text1 + "%' Order by Price desc";
}
if (s == 2)
{
text = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text1 + "%' Order by Price asc";
}
if (s == 3)
{
text = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text1 + "%' Order by VehicleID desc";
}
using (SqlDataAdapter sda = new SqlDataAdapter())
{
SqlCommand cmd = new SqlCommand(text);
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ViewCars.DataSource = dt;
ViewCars.DataBind();
con.Close();
}
}
}
protected void find_Click(object sender, ImageClickEventArgs e)
{
string trans = null;
string fuel = null;
string type = null;
string text = Find.Text.ToString().Trim();
con.Open();
string text2 = "";
int s = int.Parse(dropdownlist1.SelectedValue);
int t = int.Parse(dropdownlist2.SelectedValue);
if (t == 0)
{ trans = "%"; }
else if (t == 1)
{ trans = "Manual"; }
else if (t == 2) { trans = "Automatic"; }
int f = int.Parse(dropdownlist3.SelectedValue);
int tp = int.Parse(dropdownlist4.SelectedValue);
if (f == 0)
{ fuel = "%"; }
else if (f == 1)
{ fuel = "Petrol"; }
else if (f == 2) { fuel = "Diesel"; }
else if (f == 3) { fuel = "Gas"; }
if (tp == 0)
{ type = "%"; }
else if (tp == 1)
{ type = "Sedan"; }
else if (tp == 2)
{ type = "Hatchback"; }
else if (tp == 3)
{ type = "SUV"; }
else if (tp == 4)
{ type = "Wagon"; }
else if (tp == 5)
{ type = "MiniVan"; }
else if (tp == 6)
{ type = "CrossOver"; }
else if (tp == 7)
{ type = "Convertible"; }
else if (tp == 8)
{ type = "Sports"; }
if (s == 0)
{
text2 = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text + "%' and Transmission like '%" + trans + "%' and FuelType like '%" + fuel + "%' and VehicleType like '%" + type + "%'";
}
if (s == 1)
{
text2 = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text + "%' and Transmission like '%" + trans + "%' and FuelType like '%" + fuel + "%' and VehicleType like '%" + type + "%' Order by Price desc";
}
if (s == 2)
{
text2 = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text + "%' and Transmission like '%" + trans + "%' and FuelType like '%" + fuel + "%' and VehicleType like '%" + type + "%' Order by Price asc";
}
if (s == 3)
{
text2 = "SELECT VehicleID, Model, Color, Price, Image, FuelType, Transmission, VehicleType FROM Vehicle where Status = 1 and Model like '%" + text + "%' and Transmission like '%" + trans + "%' and FuelType like '%" + fuel + "%' and VehicleType like '%" + type + "%' Order by VehicleID desc";
}
using (SqlCommand cmd = new SqlCommand(text2, con))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ViewCars.DataSource = dt;
ViewCars.DataBind();
con.Close();
}
}
}
}
protected void VehicleType_Click(object sender, EventArgs e)
{
Find.Text = null;
dropdownlist1.SelectedIndex = 0;
dropdownlist2.SelectedIndex = 0;
dropdownlist3.SelectedIndex = 0;
dropdownlist4.SelectedIndex = 0;
LinkButton link = (LinkButton)sender;
string text = link.Text;
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT VehicleID, Model,Price,Image,FuelType,Transmission,VehicleType FROM Vehicle where Status=1 and VehicleType='" + text + "'"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ViewCars.DataSource = dt;
ViewCars.DataBind();
con.Close();
}
}
}
}
protected void FuelType_Click(object sender, EventArgs e)
{
Find.Text = null;
dropdownlist1.SelectedIndex = 0;
dropdownlist2.SelectedIndex = 0;
dropdownlist3.SelectedIndex = 0;
dropdownlist4.SelectedIndex = 0;
LinkButton link = (LinkButton)sender;
string text = link.Text;
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT VehicleID, Model,Price,Image,FuelType,Transmission,VehicleType FROM Vehicle where Status=1 and FuelType='" + text + "'"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ViewCars.DataSource = dt;
ViewCars.DataBind();
con.Close();
}
}
}
}
protected void TransmissionType_Click(object sender, EventArgs e)
{
Find.Text = null;
dropdownlist1.SelectedIndex = 0;
dropdownlist2.SelectedIndex = 0;
dropdownlist3.SelectedIndex = 0;
dropdownlist4.SelectedIndex = 0;
LinkButton link = (LinkButton)sender;
string text = link.Text;
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT VehicleID, Model,Price,Image,FuelType,Transmission,VehicleType FROM Vehicle where Status=1 and Transmission='" + text + "'"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ViewCars.DataSource = dt;
ViewCars.DataBind();
con.Close();
}
}
}
}
protected void details_Click(object sender, EventArgs e)
{
LinkButton link = (LinkButton)sender;
RepeaterItem item = (RepeaterItem)link.NamingContainer;
int index = item.ItemIndex;
Label vid = (Label)item.FindControl("vcID");
Session["Vid"] = Convert.ToInt32(vid.Text);
Response.Redirect("CarDetails.aspx");
}
}