-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooking.aspx.cs
272 lines (215 loc) · 8.58 KB
/
Booking.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
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
public partial class Booking : System.Web.UI.Page
{
Boolean flag;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Label1.Visible )
{
LinkButton1.Visible = false;
}
else
{
string constr = " Data Source=omisbi3.niunt.niu.edu;Initial Catalog=Z1781921;Initial Catalog=Z1781921;User ID=z1781921;Password=Bw1243$h11";
using (SqlConnection con = new SqlConnection(constr))
{
try
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT max(CustNo) FROM CUSTINFO ";
con.Open();
cmd.Connection = con;
int count = (int)cmd.ExecuteScalar();
int count3;
count3 = count + 1;
using (var cmd1 = new SqlCommand("INSERT INTO[CustInfo]([CustNo],[Name],[Phone],[email],[Address],[PickUpDate],[DropDate],[NoOfDays],[PickInCIty],[DropOffCity],[CarModel],[Rent]) VALUES(@CustNo, @Name, @Phone, @email, @Address, @PickUpDate, @DropDate, @NoOfDays, @PickInCIty, @DropOffCity, @CarModel,@Rent)"))
{
//String query = "insert into CUSTINFO values(" + count3 + ",'" + CustomerName.Text + "', '" + PhoneNumber.Text + "', '" + EmailID.Text + "', '" + Address.Text + "', '" + TextBox2.Text + "','" + TextBox3.Text + "','" + Days.Text + "','" + DropDownList11.Text + "','" + DropDownList2.Text + "',' " + DropDownList1.Text + "', '" + Rent.Text + ")";
cmd1.Connection = con;
cmd1.Parameters.AddWithValue("@CustNo", count3);
cmd1.Parameters.AddWithValue("@Name", CustomerName.Text);
cmd1.Parameters.AddWithValue("@Phone", PhoneNumber.Text);
cmd1.Parameters.AddWithValue("@email", EmailID.Text);
cmd1.Parameters.AddWithValue("@Address", Address.Text);
cmd1.Parameters.AddWithValue("@PickUpDate", TextBox2.Text);
cmd1.Parameters.AddWithValue("@DropDate", TextBox3.Text);
cmd1.Parameters.AddWithValue("@NoOfDays", Days.Text);
cmd1.Parameters.AddWithValue("@PickInCity", DropDownList11.Text);
cmd1.Parameters.AddWithValue("@DropOffCity", DropDownList2.Text);
cmd1.Parameters.AddWithValue("@CarModel", DropDownList1.Text);
cmd1.Parameters.AddWithValue("@Rent", Rent.Text);
cmd1.ExecuteNonQuery();
//to update the vehicle availabiltiy
String query2 = "update vehicle set Availability=0 where CarModel='" + DropDownList1.Text + "' ";
SqlCommand cmd2 = new SqlCommand(query2);
cmd2.Connection = con;
cmd2.ExecuteNonQuery();
Label2.Visible = true;
Label3.Visible = true;
Label3.Text = count3.ToString();
Button1.Visible = true;
LinkButton1.Visible = false;
}
}
}
catch (Exception E)
{
String s = E.Message;
}
finally
{
if (con != null)
{
con.Close();
}
}
}
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Calendar1.Visible = true;
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
Calendar1.Visible = false;
Calendar2.Visible = true;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox2.Text = Calendar1.SelectedDate.ToShortDateString();
Calendar1.Visible = false;
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("MODELS.aspx");
}
protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
TextBox3.Text = Calendar2.SelectedDate.ToShortDateString();
Calendar2.Visible = false;
TimeSpan ts;
DateTime a, b;
a = Calendar1.SelectedDate;
b = Calendar2.SelectedDate;
ts = b - a;
string str1 = ts.ToString();
int l1 = str1.Length;
if (l1 == 10)
{
str1 = str1.Remove(1);
}
else
{
str1 = str1.Remove(2);
}
int ts2 = Int16.Parse(str1);
if (ts2 < 0)
{
Days.Text = " ";
TextBox3.Text = " ";
Label5.Visible = true;
Calendar2.Visible = true;
}
if (ts2 == 0)
{
Days.Text = "1";
TextBox3.Text = Calendar2.SelectedDate.ToShortDateString();
Label5.Visible = false;
Calendar2.Visible = false;
}
if (ts2 >= 1)
{
ts2 = ts2 + 1;
Days.Text = ts2.ToString();
TextBox3.Text = Calendar2.SelectedDate.ToShortDateString();
Calendar2.Visible = false;
Label5.Visible = false;
}
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
string constr = "Data Source=omisbi3.niunt.niu.edu;Initial Catalog=Z1781921;Initial Catalog=Z1781921;User ID=z1781921;Password=Bw1243$h11";
using (SqlConnection con = new SqlConnection(constr))
{
try
{
using (SqlCommand cmd3 = new SqlCommand())
{
cmd3.CommandText = "select * from vehicle where Carmodel='" + DropDownList1.Text + "' and Availability=1";
con.Open();
cmd3.Connection = con;
SqlDataReader dr;
SqlDataReader dr1;
dr1 = cmd3.ExecuteReader();
if (!(dr1.Read()))
{
Label1.Visible = true;
}
else
{ Label1.Visible = false;
}
dr1.Close();
dr = cmd3.ExecuteReader();
if (dr.Read())
{
int a = Int32.Parse(Days.Text);
String b= dr["price"].ToString();
string c = Regex.Replace(b, @"[^\d]", string.Empty);
int price = Int32.Parse(c);
int total = a * price;
Rent.Text = total.ToString();
}
}
}
catch (Exception E)
{
String s = E.Message;
}
finally
{
if (con != null)
{
con.Close();
}
}
}
}
protected void CustomValidator1_ServerValidate1(object source, ServerValidateEventArgs args)
{
DateTime a;
a = Calendar1.TodaysDate;
if (Convert.ToDateTime(args.Value) >= a)
{
args.IsValid = true;
flag = true;
}
else
{
args.IsValid = false;
TextBox2.Text = "";
Calendar1.Visible = true;
Calendar2.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("payment.aspx");
}
}