-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReserve.aspx.cs
530 lines (496 loc) · 21.8 KB
/
Reserve.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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GourmetGuide;
using System.Text;
//TODO: Mandatory fields and email check if not null so that do not send mail
public partial class Account_Default : System.Web.UI.Page
{
string name, description, opentime, closetime, city, state, address1, address2, zip;
int nwdays, parkingCount;
int[] acount = new int[4];
bool val1;
List<DropDownList> ls = new List<DropDownList>();
OleDbDataReader oReader;
OleDbDataReader oReader1;
OleDbDataReader oReader2;
OleDbDataReader oReader3;
OleDbDataReader oReader4;
OleDbDataReader oReader5;
StringBuilder ConnectionString = new StringBuilder();
OleDbConnection conn;
List<RequiredFieldValidator> ddValidatorList;
protected void Page_Load(object sender, EventArgs e)
{
populateItems();
}
protected void datepicker_TextChanged(object sender, EventArgs e)
{
string[] date = datepicker.Text.Split('/');
DateTime dateval = new DateTime(System.Convert.ToInt32(date[2]), System.Convert.ToInt32(date[0]), System.Convert.ToInt32(date[1]));
int dayofweek = (int)dateval.DayOfWeek;
opentime = opentime.Replace(":", "");
int otime = System.Convert.ToInt32(opentime);
closetime = closetime.Replace(":", "");
int ctime = System.Convert.ToInt32(closetime);
DropDownList5.Items.Clear();
if (dayofweek == nwdays % 7)
{
DropDownList5.Items.Add(new ListItem("Restaurant Holiday", "Restaurant Holiday", true));
DropDownList5.Enabled = false;
Button1.Enabled = false;
}
else
{
Button1.Enabled = true;
DropDownList5.Enabled = true;
DropDownList5.Items.Add(new ListItem("-select-", "0", true));
string val;
if (ctime > otime)
for (int i = otime; i < ctime; i += 100)
{
val = i.ToString("D4");
DropDownList5.Items.Add(new ListItem(val.Insert(2, ":"), val, true));
}
else
{
for (int i = otime; i < 2400; i += 100)
{
val = i.ToString("D4");
DropDownList5.Items.Add(new ListItem(val.Insert(2, ":"), val, true));
}
otime = otime - (otime / 100) * 100;
for (int i = otime; i < ctime; i += 100)
{
val = i.ToString("D4");
DropDownList5.Items.Add(new ListItem(val.Insert(2, ":"), val, true));
}
}
}
//System.Diagnostics.Debug.WriteLine(date);
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
//ddValidator1.Enabled = false;
//ddValidator2.Enabled = false;
//ddValidator3.Enabled = false;
//ddValidator4.Enabled = false;
if (CheckBox1.Checked)
{
if (acount[0] != 0)
{
DropDownList1.Enabled = true;
ddValidator1.Enabled = true;
DropDownList1.Items.Clear();
DropDownList1.Items.Add(new ListItem("-select-", "0", true));
for (int i = 1; i <= acount[0]; i++)
{
DropDownList1.Items.Add(new ListItem(i.ToString(), i.ToString(), true));
}
}
//else
//{
// ddValidatorList[0].Text = "Sorry! No 2 seaters available. Uncheck this option and choose an alternate seating ";
//}
}
else
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(new ListItem("-select-", "0", true));
ddValidator1.Enabled = false;
//DropDownList1.Items.Add(new ListItem("-N/A-", "0", true));
DropDownList1.Enabled = false;
}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
//ddValidator1.Enabled = false;
//ddValidator2.Enabled = false;
//ddValidator3.Enabled = false;
//ddValidator4.Enabled = false;
if (CheckBox2.Checked)
{
if (acount[1] != 0)
{
DropDownList2.Enabled = true;
ddValidator2.Enabled = true;
DropDownList2.Items.Clear();
DropDownList2.Items.Add(new ListItem("-select-", "0", true));
for (int i = 1; i <= acount[1]; i++)
{
DropDownList2.Items.Add(new ListItem(i.ToString(), i.ToString(), true));
}
}
//else
//{
// ddValidatorList[1].Text = "Sorry! No 4 seaters available. Uncheck this option and choose an alternate seating ";
//}
}
else
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add(new ListItem("-select-", "0", true));
ddValidator2.Enabled = false;
//DropDownList2.Items.Add(new ListItem("-N/A-", "0", true));
DropDownList2.Enabled = false;
}
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
//ddValidator1.Enabled = false;
//ddValidator2.Enabled = false;
//ddValidator3.Enabled = false;
//ddValidator4.Enabled = false;
if (CheckBox3.Checked)
{
if (acount[2] != 0)
{
DropDownList3.Enabled = true;
ddValidator3.Enabled = true;
DropDownList3.Items.Clear();
DropDownList3.Items.Add(new ListItem("-select-", "0", true));
for (int i = 1; i <= acount[2]; i++)
{
DropDownList3.Items.Add(new ListItem(i.ToString(), i.ToString(), true));
}
}
//else
//{
// ddValidatorList[2].Text = "Sorry! No 6 seaters available. Uncheck this option and choose an alternate seating ";
//}
}
else
{
DropDownList3.Items.Clear();
DropDownList3.Items.Add(new ListItem("-select-", "0", true));
ddValidator3.Enabled = false;
//DropDownList3.Items.Add(new ListItem("-N/A-", "0", true));
DropDownList3.Enabled = false;
}
}
protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
{
//ddValidator1.Enabled = false;
//ddValidator2.Enabled = false;
//ddValidator3.Enabled = false;
//ddValidator4.Enabled = false;
if (CheckBox4.Checked)
{
if (acount[3] != 0)
{
DropDownList4.Enabled = true;
ddValidator4.Enabled = true;
DropDownList4.Items.Clear();
DropDownList4.Items.Add(new ListItem("-select-", "0", true));
for (int i = 1; i <= acount[3]; i++)
{
DropDownList4.Items.Add(new ListItem(i.ToString(), i.ToString(), true));
}
}
//else
//{
// ddValidatorList[3].Text = "Sorry! No 8 seaters available. Uncheck this option and choose an alternate seating ";
//}
}
else
{
DropDownList4.Items.Clear();
DropDownList4.Items.Add(new ListItem("-select-", "0", true));
ddValidator4.Enabled = false;
//DropDownList4.Items.Add(new ListItem("-N/A-", "0", true));
DropDownList4.Enabled = false;
}
}
private void populateItems()
{
if (Request.QueryString["restaurant"] != null)
{
ddValidatorList = new List<RequiredFieldValidator>();
List<CheckBox> checkBoxList = new List<CheckBox>();
ddValidatorList.Clear();
ddValidatorList.Add(ddValidator1);
ddValidatorList.Add(ddValidator2);
ddValidatorList.Add(ddValidator3);
ddValidatorList.Add(ddValidator4);
ddValidatorList.Add(rfvParkingValidator);
checkBoxList.Clear();
checkBoxList.Add(CheckBox1);
checkBoxList.Add(CheckBox2);
checkBoxList.Add(CheckBox3);
checkBoxList.Add(CheckBox4);
checkBoxList.Add(CheckParking);
ls.Clear();
ls.Add(DropDownList1);
ls.Add(DropDownList2);
ls.Add(DropDownList3);
ls.Add(DropDownList4);
//ddValidator1.Enabled = false;
//ddValidator2.Enabled = false;
//ddValidator3.Enabled = false;
//ddValidator4.Enabled = false;
val1 = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
if (val1)
{
EMailID.Enabled = false;
rfvEmail.Enabled = false;
EMailDiv.Visible = false;
}
else
{
EMailID.Visible = true;
EMailLabel.Visible = true;
}
string restaurant_id = Request.QueryString["restaurant"];
string cmd = "select name,description,opentime,closetime,city,state,address1,address2,zip,nonworkingdays from " + ProjectSettings.schema + ".restaurant where restaurantid = " + restaurant_id;
string cmd1 = "select availabilitycount from " + ProjectSettings.schema + ".tables where groupid = 2 and restaurantid = " + restaurant_id;
string cmd2 = "select availabilitycount from " + ProjectSettings.schema + ".tables where groupid = 4 and restaurantid = " + restaurant_id;
string cmd3 = "select availabilitycount from " + ProjectSettings.schema + ".tables where groupid = 6 and restaurantid = " + restaurant_id;
string cmd4 = "select availabilitycount from " + ProjectSettings.schema + ".tables where groupid = 8 and restaurantid = " + restaurant_id;
string cmd5 = "select availability from " + ProjectSettings.schema + ".parking where restaurantid = " + restaurant_id;
//System.Diagnostics.Debug.WriteLine(cmd5);
ConnectionString.Append("Provider=").Append(ProjectSettings.dbProvider).Append(";")
.Append(" DATA SOURCE=").Append(ProjectSettings.dbHost).Append(":")
.Append(ProjectSettings.dbPort).Append("/").Append(ProjectSettings.dbSid).Append(";")
.Append("PASSWORD=").Append(ProjectSettings.dbKey).Append(";")
.Append("USER ID=").Append(ProjectSettings.dbUser);
//System.Diagnostics.Debug.WriteLine(ConnectionString.ToString());
conn = new OleDbConnection(ConnectionString.ToString());
conn.Open();
OleDbCommand select_restaurants = new OleDbCommand(cmd, conn);
OleDbCommand select_tables_2 = new OleDbCommand(cmd1, conn);
OleDbCommand select_tables_4 = new OleDbCommand(cmd2, conn);
OleDbCommand select_tables_6 = new OleDbCommand(cmd3, conn);
OleDbCommand select_tables_8 = new OleDbCommand(cmd4, conn);
OleDbCommand select_parking = new OleDbCommand(cmd5, conn);
oReader = select_restaurants.ExecuteReader();
oReader1 = select_tables_2.ExecuteReader();
oReader2 = select_tables_4.ExecuteReader();
oReader3 = select_tables_6.ExecuteReader();
oReader4 = select_tables_8.ExecuteReader();
oReader5 = select_parking.ExecuteReader();
oReader.Read();
oReader1.Read();
oReader2.Read();
oReader3.Read();
oReader4.Read();
oReader5.Read();
name = oReader[0].ToString();
description = oReader[1].ToString();
opentime = oReader[2].ToString();
closetime = oReader[3].ToString();
city = oReader[4].ToString();
state = oReader[5].ToString();
address1 = oReader[6].ToString();
address2 = oReader[7].ToString();
zip = oReader[8].ToString();
nwdays = System.Convert.ToInt32(oReader[9].ToString());
if (oReader1.HasRows)
acount[0] = System.Convert.ToInt32(oReader1[0].ToString());
//System.Diagnostics.Debug.WriteLine(acount[0]);
if (oReader2.HasRows)
acount[1] = System.Convert.ToInt32(oReader2[0].ToString());
if (oReader3.HasRows)
acount[2] = System.Convert.ToInt32(oReader3[0].ToString());
if (oReader4.HasRows)
acount[3] = System.Convert.ToInt32(oReader4[0].ToString());
if (oReader5.HasRows)
parkingCount = System.Convert.ToInt32(oReader5[0].ToString());
r_name.Text = name;
r_address.Text = address1 + "\n" + address2 + "\n" + city + ", " + state + " - " + zip;
bool[] en = { CheckBox1.Checked, CheckBox2.Checked, CheckBox3.Checked, CheckBox4.Checked, CheckParking.Checked };
DropDownList1.Enabled = en[0];
DropDownList2.Enabled = en[1];
DropDownList3.Enabled = en[2];
DropDownList4.Enabled = en[3];
ParkingDropDownList.Enabled = en[4];
if (parkingCount == 0)
{
Parking.Visible = false;
CheckParking.Enabled = false;
rfvParkingValidator.Enabled = false;
ParkingFull.Visible = true;
}
//Disable checkbox when the number of tables is zero
int disabledCount = 0;
for (int i = 0; i < acount.Length; i++ )
{
if (acount[i] == 0)
{
checkBoxList[i].Enabled = false;
ddValidatorList[i].Enabled = false;
ls[i].Enabled = false;
disabledCount++;
}
}
//If none of checkboxes is checked, generate error
int uncheckedCount = 0;
for (int i = 0; i < checkBoxList.Count; i++)
{
if (checkBoxList[i].Checked)
ddValidatorList[i].Enabled = true;
else if(checkBoxList[i].Enabled)
{
if(i < 4)
uncheckedCount++;
ddValidatorList[i].Enabled = false;
}
}
if (uncheckedCount == 4 - disabledCount)
{
ddValidatorList[0].Enabled = true;
ddValidatorList[0].Text = "Please select seats";
}
else
ddValidatorList[0].Enabled = false;
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string eMail;
if (val1)
{
string cmd = "select EMAILID from " + ProjectSettings.schema + ".RegisteredUser where userName='" + System.Web.HttpContext.Current.User.Identity.Name + "'";
//System.Diagnostics.Debug.WriteLine("UserName is " + System.Web.HttpContext.Current.User.Identity.Name);
OleDbCommand select_EMail = new OleDbCommand(cmd, conn);
conn.Open();
oReader = select_EMail.ExecuteReader();
oReader.Read();
eMail = oReader[0].ToString();
//System.Diagnostics.Debug.WriteLine("EMail is " + eMail);
oReader.Close();
conn.Close();
}
else
{
eMail = EMailID.Text;
}
bool[] en = { CheckBox1.Checked, CheckBox2.Checked, CheckBox3.Checked, CheckBox4.Checked };
int restaurantID = Int32.Parse(Request.QueryString["restaurant"]);
int groupID = 1;
string bookDetails = "";
//int[] AvailabilityCount={Int32.Parse(DropDownList1.SelectedValue),Int32.Parse(DropDownList2.SelectedValue),Int32.Parse(DropDownList3.SelectedValue),Int32.Parse(DropDownList4.SelectedValue)};
int avlCnt = 0;
int totalpersons = 0;
bookDetails += "Restaurant: " + name + "\n";
bookDetails += "Date and Time : " + datepicker.Text + " at " + DropDownList5.SelectedValue + "\n";
for (int i = 0; i < 4; i++)
{
avlCnt = 0;
if (en[i] == true)
{
groupID = (i + 1) * 2;
//System.Diagnostics.Debug.WriteLine("Value of Dropdown "+ls[i].Text);
avlCnt = Int32.Parse(ls[i].Text);
}
if (avlCnt != 0)
{
string insertcmd = "insert into " + ProjectSettings.schema + ".tablereserve values(?,?,?,?,?)";
OleDbTransaction tran = null;
conn.Open();
tran = conn.BeginTransaction();
OleDbCommand insert_Tblreserve = new OleDbCommand(insertcmd, conn, tran);
insert_Tblreserve.Parameters.Add("?", OleDbType.Integer).Value = restaurantID;
insert_Tblreserve.Parameters.Add("?", OleDbType.Integer).Value = groupID;
insert_Tblreserve.Parameters.Add("?", OleDbType.VarChar).Value = eMail;
insert_Tblreserve.Parameters.Add("?", OleDbType.Integer).Value = avlCnt;
insert_Tblreserve.Parameters.Add("?", OleDbType.VarChar).Value = DropDownList5.SelectedValue;
insert_Tblreserve.ExecuteNonQuery();
tran.Commit();
string updateAvlCnt = "update " + ProjectSettings.schema + ".tables set availabilitycount=? where groupID=? and restaurantID=?";
tran = null;
tran = conn.BeginTransaction();
OleDbCommand update_AvlCnt = new OleDbCommand(updateAvlCnt, conn, tran);
update_AvlCnt.Parameters.Add("?", OleDbType.Integer).Value = acount[i] - avlCnt;
update_AvlCnt.Parameters.Add("?", OleDbType.Integer).Value = groupID;
//System.Diagnostics.Debug.WriteLine(acount[i] - avlCnt);
update_AvlCnt.Parameters.Add("?", OleDbType.Integer).Value = restaurantID;
update_AvlCnt.ExecuteNonQuery();
tran.Commit();
bookDetails += "Table for " + groupID + " : " + avlCnt + " nos.\n";
totalpersons += groupID * avlCnt;
conn.Close();
}
}
bookDetails += "Party size : " + totalpersons + " persons.\n\n";
if (CheckParking.Checked)
{
string insertParkingcmd = "insert into " + ProjectSettings.schema + ".parkingreserve values(?,?)";
OleDbTransaction tran = null;
conn.Open();
tran = conn.BeginTransaction();
OleDbCommand insert_parkingreserve = new OleDbCommand(insertParkingcmd, conn, tran);
insert_parkingreserve.Parameters.Add("?", OleDbType.Integer).Value = restaurantID;
insert_parkingreserve.Parameters.Add("?", OleDbType.VarChar).Value = eMail;
insert_parkingreserve.ExecuteNonQuery();
tran.Commit();
string updatePrkCnt = "update " + ProjectSettings.schema + ".parking set availability=? where restaurantID=?";
tran = null;
tran = conn.BeginTransaction();
OleDbCommand update_PrkCnt = new OleDbCommand(updatePrkCnt, conn, tran);
System.Diagnostics.Debug.WriteLine("Selected Value is " + System.Convert.ToInt32(ParkingDropDownList.Text));
update_PrkCnt.Parameters.Add("?", OleDbType.Integer).Value = parkingCount - System.Convert.ToInt32(ParkingDropDownList.Text);
//System.Diagnostics.Debug.WriteLine(parkingCount - 1);
update_PrkCnt.Parameters.Add("?", OleDbType.Integer).Value = restaurantID;
update_PrkCnt.ExecuteNonQuery();
tran.Commit();
bookDetails += "Parking valet reserved for " + ParkingDropDownList.Text;
if (ParkingDropDownList.Text == "1")
bookDetails += " slot";
else
bookDetails += " slots";
bookDetails += ".\n\n";
}
string subject = "";
var content = "";
subject = "GourmetGuide reservation confirmation";
content = "Hi. \n\nHere are the details for your reservation done a few minutes ago:\n\n" + bookDetails + "\n\n"
+ "GourmetGuide team.";
SendMail sm = new SendMail(eMail, null, subject, content);
sm.send();
/*string subject;
var content = "";
subject = "GourmetGuide reservation confirmation";
content = "Hi. \n\nHere are the details for your reservation done a few minutes ago:\n\n" + bookDetails + "\n\n"
+ "GourmetGuide team.";
SendMail sm = new SendMail(eMail, null, subject, content);
sm.send();
*/
//Response.Redirect("/Account/Profile.aspx", true);
if (Preorder.Checked)
{
Session["eMail"] = eMail;
Response.Redirect("~/OrderFood.aspx?prev=reserve&restaurant=" + Request.QueryString["restaurant"]);
}
else
{
Response.Redirect("~/HomePage.aspx", true);
}
}
protected void CheckParking_CheckedChanged(object sender, EventArgs e)
{
if (CheckParking.Checked)
{
ParkingDropDownList.Enabled = true;
rfvParkingValidator.Enabled = true;
ParkingDropDownList.Items.Clear();
ParkingDropDownList.Items.Add(new ListItem("-select-", "0", true));
for (int i = 1; i <= parkingCount; i++)
{
ParkingDropDownList.Items.Add(new ListItem(i.ToString(), i.ToString(), true));
}
}
else
{
ParkingDropDownList.Items.Clear();
ParkingDropDownList.Items.Add(new ListItem("-select-", "0", true));
rfvParkingValidator.Enabled = false;
//DropDownList1.Items.Add(new ListItem("-N/A-", "0", true));
ParkingDropDownList.Enabled = false;
}
}
}