-
Notifications
You must be signed in to change notification settings - Fork 0
/
PassengerDetailsInfo.aspx.cs
331 lines (306 loc) · 16.3 KB
/
PassengerDetailsInfo.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BusBookingProject
{
public partial class PassengerDetailsInfo : System.Web.UI.Page
{
private static Random random = new Random();
#region Global Variable
SqlConnection connString = new SqlConnection(ConfigurationManager.ConnectionStrings["OnlineBusBookingConnectionString"].ToString());
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if(Session["UserID"] !=null)
{
paymentMode.Visible = false;
ViewState["Count"] = 1;
SetInitialRow();
}
else
{
string Url = "PassengerDetailsInfo.aspx";
Response.Redirect("Login.aspx?Url=" + Url);
}
}
}
public static string RandomGenerareOTP(int length)
{
const string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
//Define the Columns
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dt.Columns.Add(new DataColumn("Column3", typeof(string)));
dt.Columns.Add(new DataColumn("Column4", typeof(string)));
dt.Columns.Add(new DataColumn("Column5", typeof(string)));
//Add a Dummy Data on Initial Load
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Column1"] = string.Empty;
dr["Column2"] = string.Empty;
dr["Column3"] = string.Empty;
dr["Column4"] = string.Empty;
dr["Column5"] = string.Empty;
dt.Rows.Add(dr);
//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
//Bind the DataTable to the Grid
gdPassengerDetails.DataSource = dt;
gdPassengerDetails.DataBind();
//Extract and Fill the DropDownList with Data
// DropDownList ddl2 = (DropDownList)gdPassengerDetails.Rows[0].Cells[2].FindControl("ddlGender");
//FillDropDownList(ddl2);
}
private void AddNewRowToGrid()
{
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = dtCurrentTable.Rows.Count + 1;
//add new row to DataTable
dtCurrentTable.Rows.Add(drCurrentRow);
//Store the current data to ViewState
ViewState["CurrentTable"] = dtCurrentTable;
for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++)
{
//extract the DropDownList Selected Items
// DropDownList ddl1 = (DropDownList)Gridview1.Rows[i].Cells[1].FindControl("DropDownList1");
TextBox FName = (TextBox)gdPassengerDetails.Rows[i].Cells[1].FindControl("txtFName");
TextBox LName = (TextBox)gdPassengerDetails.Rows[i].Cells[2].FindControl("txtLName");
TextBox Email = (TextBox)gdPassengerDetails.Rows[i].Cells[3].FindControl("txtEmail");
TextBox Contact = (TextBox)gdPassengerDetails.Rows[i].Cells[4].FindControl("txtContact");
TextBox City = (TextBox)gdPassengerDetails.Rows[i].Cells[5].FindControl("txtCity");
//DropDownList ddl3 = (DropDownList)Gridview1.Rows[i].Cells[3].FindControl("DropDownList3");
// Update the DataRow with the DDL Selected Items
//dtCurrentTable.Rows[i]["Column1"] = ddl1.SelectedItem.Text;
dtCurrentTable.Rows[i]["Column1"] = FName.Text;
dtCurrentTable.Rows[i]["Column2"] = LName.Text;
dtCurrentTable.Rows[i]["Column3"] = Email.Text;
dtCurrentTable.Rows[i]["Column4"] = Contact.Text;
dtCurrentTable.Rows[i]["Column5"] = City.Text;
// dtCurrentTable.Rows[i]["Column3"] = ddl3.SelectedItem.Text;
}
//Rebind the Grid with the current data
gdPassengerDetails.DataSource = dtCurrentTable;
gdPassengerDetails.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData();
}
private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
//Set the Previous Selected Items on Each DropDownList on Postbacks
// DropDownList ddl1 = (DropDownList)Gridview1.Rows[rowIndex].Cells[1].FindControl("DropDownList1");
TextBox FName = (TextBox)gdPassengerDetails.Rows[rowIndex].Cells[1].FindControl("txtFName");
TextBox LName = (TextBox)gdPassengerDetails.Rows[rowIndex].Cells[2].FindControl("txtLName");
TextBox Email = (TextBox)gdPassengerDetails.Rows[rowIndex].Cells[3].FindControl("txtEmail");
TextBox Contact = (TextBox)gdPassengerDetails.Rows[rowIndex].Cells[4].FindControl("txtContact");
TextBox City = (TextBox)gdPassengerDetails.Rows[rowIndex].Cells[5].FindControl("txtCity");
FName.Text = dt.Rows[i]["Column1"].ToString();
LName.Text = dt.Rows[i]["Column2"].ToString();
Email.Text = dt.Rows[i]["Column3"].ToString();
Contact.Text = dt.Rows[i]["Column4"].ToString();
City.Text = dt.Rows[i]["Column5"].ToString();
//Fill the DropDownList with Data
//FillDropDownList(ddl1);
//FillDropDownList(ddl2);
// FillDropDownList(ddl3);
//if (i < dt.Rows.Count - 1)
//{
// //ddl1.ClearSelection();
// //ddl1.Items.FindByText(dt.Rows[i]["Column1"].ToString()).Selected = true;
// ddl2.ClearSelection();
// ddl2.Items.FindByText(dt.Rows[i]["Column2"].ToString()).Selected = true;
// // ddl3.ClearSelection();
// //ddl3.Items.FindByText(dt.Rows[i]["Column3"].ToString()).Selected = true;
//}
rowIndex++;
}
}
}
}
protected void ButtonAdd_Click(object sender, EventArgs e)
{
ViewState["Count"] = Convert.ToInt32(ViewState["Count"]) + 1;
string seatNo = Convert.ToString(Request.QueryString["SeatNo"]);
string[] seatArray = seatNo.Split(',').Select(str => str.Trim()).ToArray();
if (Convert.ToInt32(ViewState["Count"]) <= seatArray.Length)
{
AddNewRowToGrid();
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('you can not add passengers more than'+'" + seatArray.Length + "')", true);
}
}
private void addPNRDetails(string PNRNo)
{
string newFare = Convert.ToString(Request.QueryString["Fare"]);
string[] fareArray = newFare.Split(',').Select(str => str.Trim()).ToArray();
decimal amount = 0;
for (int i = 0; i < fareArray.Length; i++)
{
amount += Convert.ToDecimal(fareArray[i]);
}
SqlCommand sqlCmd = new SqlCommand();
if (connString.State == ConnectionState.Closed)
{
connString.Open();
}
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@PNRNo", PNRNo);
sqlCmd.Parameters.AddWithValue("@TotalAmount", Convert.ToDecimal(amount));
sqlCmd.Parameters.AddWithValue("@TotalTicket", Convert.ToInt32(fareArray.Length));
sqlCmd.Parameters.AddWithValue("@CreatedBy", Convert.ToInt32(Session["UserID"]));
sqlCmd.CommandText = "ispAddPNRDetails";
sqlCmd.Connection = connString;
sqlCmd.ExecuteNonQuery();
}
private int getBook()
{
int ResultCout = 0;
string seatNo = Convert.ToString(Request.QueryString["SeatNo"]);
string[] seatArray = seatNo.Split(',').Select(str => str.Trim()).ToArray();
int count=(seatArray.Length)-(gdPassengerDetails.Rows.Count);
if(gdPassengerDetails.Rows.Count<seatArray.Length)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Add Passenger Details For'+'"+gdPassengerDetails.Rows.Count+"'+'More Passengers')", true);
}
else
{
string PNRNO = RandomGenerareOTP(6);
addPNRDetails(PNRNO);
addCardDetails();
string Origin = Convert.ToString(Request.QueryString["Origin"]);
string Destination = Convert.ToString(Request.QueryString["Destination"]);
string travelDate = Convert.ToString(Request.QueryString["TravelDate"]);
string newFare = Convert.ToString(Request.QueryString["Fare"]);
string[] fareArray = newFare.Split(',').Select(str => str.Trim()).ToArray();
SqlCommand sqlCmd = new SqlCommand();
if (connString.State == ConnectionState.Closed)
{
connString.Open();
}
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add("@RegId", SqlDbType.Int);
sqlCmd.Parameters.Add("@BusId", SqlDbType.Int);
sqlCmd.Parameters.Add("@Fname", SqlDbType.VarChar, 50);
sqlCmd.Parameters.Add("@Lname", SqlDbType.VarChar, 50);
sqlCmd.Parameters.Add("@Email", SqlDbType.VarChar, 50);
sqlCmd.Parameters.Add("@Contact", SqlDbType.VarChar, 50);
sqlCmd.Parameters.Add("@City", SqlDbType.VarChar, 50);
sqlCmd.Parameters.Add("@SeatNo", SqlDbType.NVarChar, 50);
sqlCmd.Parameters.Add("@TravelDate", SqlDbType.VarChar, 50);
sqlCmd.Parameters.Add("@Origin", SqlDbType.VarChar, 50);
sqlCmd.Parameters.Add("@Destination", SqlDbType.VarChar, 50);
sqlCmd.Parameters.Add("@BoardingId", SqlDbType.Int);
sqlCmd.Parameters.Add("@Fare", SqlDbType.Decimal);
sqlCmd.Parameters.Add("@TotalSeats", SqlDbType.BigInt);
sqlCmd.Parameters.Add("@PNRNo", SqlDbType.VarChar, 50);
for (int i = 0; i < seatArray.Length; i++)
{
sqlCmd.Parameters[0].Value = Convert.ToInt32(Session["UserID"]);
sqlCmd.Parameters[1].Value = Convert.ToInt32(Request.QueryString["BusID"]);
TextBox Fname = (TextBox)gdPassengerDetails.Rows[i].Cells[1].FindControl("txtFName");
TextBox Lname = (TextBox)gdPassengerDetails.Rows[i].Cells[2].FindControl("txtLName");
TextBox Email = (TextBox)gdPassengerDetails.Rows[i].Cells[3].FindControl("txtEmail");
TextBox Contact = (TextBox)gdPassengerDetails.Rows[i].Cells[4].FindControl("txtContact");
TextBox City = (TextBox)gdPassengerDetails.Rows[i].Cells[5].FindControl("txtCity");
sqlCmd.Parameters[2].Value = Convert.ToString(Fname.Text);
sqlCmd.Parameters[3].Value = Convert.ToString(Lname.Text);
sqlCmd.Parameters[4].Value = Convert.ToString(Email.Text);
sqlCmd.Parameters[5].Value = Convert.ToString(Contact.Text);
sqlCmd.Parameters[6].Value = Convert.ToString(City.Text);
sqlCmd.Parameters[7].Value = Convert.ToString(seatArray[i]);
sqlCmd.Parameters[8].Value = Convert.ToString(travelDate);
sqlCmd.Parameters[9].Value = Convert.ToString(Origin);
sqlCmd.Parameters[10].Value = Convert.ToString(Destination);
sqlCmd.Parameters[11].Value = Convert.ToInt32(Request.QueryString["BoardingID"]);
sqlCmd.Parameters[12].Value = Convert.ToDecimal(fareArray[i]);
sqlCmd.Parameters[13].Value = Convert.ToDecimal(fareArray[i].Length);
sqlCmd.Parameters[14].Value = Convert.ToString(PNRNO);
sqlCmd.CommandText = "ispAddPassengerDetails";
sqlCmd.Connection = connString;
ResultCout = sqlCmd.ExecuteNonQuery();
}
}
return ResultCout;
}
protected void btnConirmBooking_Click(object sender, EventArgs e)
{
paymentMode.Visible = true;
}
private void addCardDetails()
{
string newFare = Convert.ToString(Request.QueryString["Fare"]);
string[] fareArray = newFare.Split(',').Select(str => str.Trim()).ToArray();
decimal amount=0;
for(int i=0;i<fareArray.Length;i++)
{
amount+=Convert.ToDecimal(fareArray[i]);
}
SqlCommand sqlCmd = new SqlCommand();
if (connString.State == ConnectionState.Closed)
{
connString.Open();
}
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@UserID",Convert.ToInt32(Session["UserID"]));
sqlCmd.Parameters.AddWithValue("@CardType", Convert.ToString(ddlCardType.SelectedItem.Text));
sqlCmd.Parameters.AddWithValue("@BankName", Convert.ToString(ddlBank.SelectedItem.Text));
sqlCmd.Parameters.AddWithValue("@CVVNo", Convert.ToString(txtCode.Text));
sqlCmd.Parameters.AddWithValue("@CardNo", Convert.ToString(txtCardNo.Text));
sqlCmd.Parameters.AddWithValue("@TotalAmount", Convert.ToDecimal(amount));
sqlCmd.CommandText = "ispAddCardDetails";
sqlCmd.Connection = connString;
sqlCmd.ExecuteNonQuery();
}
protected void btnSave_Click(object sender, EventArgs e)
{
int resultcount = getBook();
if (resultcount ==-1)
{
string Msg = "Booking Done Successfully,Please download your ticket from below";
Response.Redirect("BookingReport.aspx?Msg=" + Msg);
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Booking Failed ,Network Error,Please contact your system administrator')", true);
}
}
}
}