Skip to content
Loading
Passenger Reservation System(PRS)
Admin.aspx.cs
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. public partial class Admin : System.Web.UI.Page
  13. {
  14. ConnClass connect = new ConnClass();
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. if (!IsPostBack)
  18. {
  19. showTrainGrid();
  20. showPassengerGrid();
  21. }
  22. }
  23. #region ShowPassenger Info
  24. private DataSet showPassengerGrid()
  25. {
  26. string scon = connect.GetConnection();
  27. SqlConnection conn = new SqlConnection(scon);
  28. conn.Open();
  29. string qry = "select * from PassengerInfo";
  30. SqlCommand cmd = new SqlCommand(qry, conn);
  31. //SqlDataReader sdr = cmd.ExecuteReader();
  32. //if (sdr.HasRows)
  33. //{
  34. // while (sdr.Read())
  35. // {
  36. // grdPassengerInfo.DataSource = sdr;
  37. // grdPassengerInfo.DataBind();
  38. // }
  39. //}
  40. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  41. sda.TableMappings.Add("Table", "PassengerInfo");
  42. DataSet ds = new DataSet("PassengerInfo");
  43. sda.Fill(ds);
  44. grdPassengerInfo.DataSource = ds;
  45. grdPassengerInfo.DataBind();
  46. if (grdPassengerInfo.Columns.Count > 0)
  47. {
  48. grdPassengerInfo.Columns[1].Visible = false;
  49. }
  50. return ds;
  51. //conn.Close();
  52. }
  53. #endregion
  54. #region gridTrain rowEditing
  55. protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  56. {
  57. //GridViewRow grd = (GridViewRow)GridView1.Rows[e.NewEditIndex];
  58. GridView1.EditIndex = e.NewEditIndex;
  59. showTrainGrid();
  60. }
  61. #endregion
  62. #region show Train Info
  63. private DataSet showTrainGrid()
  64. {
  65. string scon = connect.GetConnection();
  66. SqlConnection conn = new SqlConnection(scon);
  67. conn.Open();
  68. string qry = "select * from Train";
  69. SqlCommand cmd = new SqlCommand(qry, conn);
  70. //SqlDataReader sdr = cmd.ExecuteReader();
  71. //if (sdr.HasRows)
  72. //{
  73. // while (sdr.Read())
  74. // {
  75. // GridView1.DataSource = sdr;
  76. // GridView1.DataBind();
  77. // }
  78. //}
  79. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  80. sda.TableMappings.Add("Table", "Train");
  81. DataSet ds = new DataSet("Train");
  82. sda.Fill(ds);
  83. GridView1.DataSource = ds;
  84. GridView1.DataBind();
  85. if (GridView1.Columns.Count > 0)
  86. {
  87. GridView1.Columns[1].Visible = false;
  88. }
  89. return ds;
  90. // conn.Close();
  91. }
  92. #endregion
  93. #region Gridrow deleting
  94. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  95. {
  96. ViewState["TrainID"] = GridView1.DataKeys[GridView1.SelectedIndex];
  97. string scon = connect.GetConnection();
  98. string query = "select * from TrainBookingDetails";
  99. SqlDataAdapter sda = new SqlDataAdapter(query, scon);
  100. DataSet ds = new DataSet();
  101. sda.Fill(ds);
  102. }
  103. #endregion
  104. #region Grid Updating
  105. protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  106. {
  107. string trainid=(GridView1.DataKeys[e.RowIndex].Value.ToString());
  108. string trainNo=((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
  109. string trainNm = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
  110. string source = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
  111. string destination = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
  112. string amt = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
  113. string scon = connect.GetConnection();
  114. SqlConnection conn=new SqlConnection(scon);
  115. conn.Open();
  116. string qry="Update Train set TrainNumber="+trainNo+" ,TrainName='"+trainNm+"',
  117. SourceStationName='"+source+"',DestinationStationName='"+destination+"',Amount="+amt+"
  118. where TrainID="+trainid+"";
  119. SqlCommand cmd = new SqlCommand(qry, conn);
  120. //cmd.ExecuteNonQuery();
  121. //conn.Close();
  122. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  123. DataSet ds = new DataSet();
  124. sda.Fill(ds);
  125. GridView1.EditIndex = -1;
  126. showTrainGrid();
  127. }
  128. #endregion
  129. #region grid Cancling
  130. protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  131. {
  132. GridView1.EditIndex = -1;
  133. showTrainGrid();
  134. }
  135. #endregion
  136. #region Add New Train
  137. protected void btnAddNew_Click(object sender, EventArgs e)
  138. {
  139. if (txtTrainNo.Text != "" && txtTrainName.Text != "" &&
  140. txtSourceStat.Text != "" && txtDestStat.Text != "" && txtAmt.Text != "")
  141. {
  142. int trainNo = Convert.ToInt32(txtTrainNo.Text);
  143. string trainNM = txtTrainName.Text;
  144. string sourceSta = txtSourceStat.Text;
  145. string DestStat = txtDestStat.Text;
  146. double amt = Convert.ToDouble(txtAmt.Text);
  147. string scon = connect.GetConnection();
  148. string qry = "Insert Into Train (TrainNumber,TrainName,
  149. SourceStationName,DestinationStationName,Amount)
  150. Values(" + trainNo + ",'" + trainNM + "','" + sourceSta + "','" + DestStat + "'," + amt + ")";
  151. SqlDataAdapter sda = new SqlDataAdapter(qry, scon);
  152. DataSet ds = new DataSet();
  153. sda.Fill(ds);
  154. txtTrainNo.Text = "";
  155. txtTrainName.Text = "";
  156. txtSourceStat.Text = "";
  157. txtDestStat.Text = "";
  158. txtAmt.Text = "";
  159. showTrainGrid();
  160. }
  161. else
  162. {
  163. this.ModalPopupExtender1.Show();
  164. }
  165. }
  166. #endregion
  167. #region Popup extender
  168. protected void Button1_Click(object sender, EventArgs e)
  169. {
  170. this.ModalPopupExtender1.Show();
  171. }
  172. #endregion
  173. #region gridTrain page indexing
  174. protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  175. {
  176. GridView1.PageIndex = e.NewPageIndex;
  177. showTrainGrid();
  178. }
  179. #endregion
  180. #region grid Passenger Page Indexing
  181. protected void grdPassengerInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
  182. {
  183. grdPassengerInfo.PageIndex = e.NewPageIndex;
  184. showPassengerGrid();
  185. }
  186. #endregion
  187. protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
  188. {
  189. LoginStatus n = new LoginStatus();
  190. n.Page.Session.Abandon();
  191. }
  192. protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
  193. {
  194. string sortExpression = e.SortExpression;
  195. if (GridViewSortDirection == SortDirection.Ascending)
  196. {
  197. GridViewSortDirection = SortDirection.Descending;
  198. SortGridTrainView(sortExpression, DESCENDING);
  199. }
  200. else
  201. {
  202. GridViewSortDirection = SortDirection.Ascending;
  203. SortGridTrainView(sortExpression, ASCENDING);
  204. }
  205. }
  206. private void SortGridTrainView(string sortExpression, string Direction)
  207. {
  208. DataTable dtable = showTrainGrid().Tables[0];
  209. DataView dv = new DataView(dtable);
  210. dv.Sort = sortExpression + Direction;
  211. GridView1.DataSource = dv;
  212. GridView1.DataBind();
  213. }
  214. private const string ASCENDING = " ASC";
  215. private const string DESCENDING = " DESC";
  216. protected void grdPassengerInfo_Sorting(object sender, GridViewSortEventArgs e)
  217. {
  218. string sortExpression = e.SortExpression;
  219. if (GridViewSortDirection == SortDirection.Ascending)
  220. {
  221. GridViewSortDirection = SortDirection.Descending;
  222. SortGridView(sortExpression, DESCENDING);
  223. }
  224. else
  225. {
  226. GridViewSortDirection = SortDirection.Ascending;
  227. SortGridView(sortExpression, ASCENDING);
  228. }
  229. }
  230. private void SortGridView(string sortExpression, string Direction)
  231. {
  232. DataTable dt = showPassengerGrid().Tables[0];
  233. DataView dv = new DataView(dt);
  234. dv.Sort = sortExpression + Direction;
  235. grdPassengerInfo.DataSource = dv;
  236. grdPassengerInfo.DataBind();
  237. }
  238. public SortDirection GridViewSortDirection
  239. {
  240. get
  241. {
  242. if (ViewState["sortDirection"] == null)
  243. ViewState["sortDirection"] = SortDirection.Ascending;
  244. return (SortDirection)ViewState["sortDirection"];
  245. }
  246. set
  247. {
  248. ViewState["sortDirection"] = value;
  249. }
  250. }
  251. }
  252. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="BookingDetails.aspx.cs" Inherits="BookingDetails" %>
  253. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
  254. Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  255. <html xmlns="http://www.w3.org/1999/xhtml" >
  256. <head runat="server">
  257. <title>Booking Details</title>
  258. <link href="CSS/StyleSheet.css" rel="stylesheet" type="text/css" />
  259. <link rel="shortcut icon" href="Image/Train.ico" />
  260. </head>
  261. <body>
  262. <form id="form1" runat="server">
  263. <h1>List of Trains are Booked by
  264. <asp:Label ID="lblsession" runat="server" ForeColor="RoyalBlue"></asp:Label>...</h1>
  265. <div>
  266. <asp:LoginStatus ID="LoginStatus1" runat="server"
  267. LogoutAction="Redirect" LogoutPageUrl="~/Default.aspx"
  268. Style="z-index: 100; left: 883px; position: absolute; top: 32px" LoginText="Logout" />
  269. <asp:GridView ID="grdPassengerInfo" runat="server"
  270. AutoGenerateColumns="False" AllowPaging="True" CssClass="mGrid"
  271. PageSize="5" OnPageIndexChanging="grdPassengerInfo_PageIndexChanging"
  272. OnRowDeleting="grdPassengernfo_RowDeleting" AllowSorting="True"
  273. AutoGenerateDeleteButton="True" OnSorting="grdPassengerInfo_Sorting">
  274. <Columns>
  275. <asp:BoundField DataField="TrainBookingID" HeaderText="TrainBookingID">
  276. <HeaderStyle CssClass="HideGridCol" />
  277. <ItemStyle CssClass="HideGridCol" />
  278. </asp:BoundField >
  279. <asp:BoundField DataField="FirstName" HeaderText="Fist Name" SortExpression="FirstName" />
  280. <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
  281. <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
  282. <asp:BoundField DataField="MobileNo" HeaderText="Mobile No." SortExpression="MobileNo" />
  283. <asp:BoundField DataField="TrainNumber" HeaderText="Train Number" SortExpression="TrainNumber" />
  284. <asp:BoundField DataField="TrainName" HeaderText="Train Name" SortExpression="TrainName" />
  285. <asp:BoundField DataField="SourceStation" HeaderText="Source Station" SortExpression="SourceStation" />
  286. <asp:BoundField DataField="DestinationStation"
  287. HeaderText="Destination Station" SortExpression="DestinationStation" />
  288. <asp:BoundField DataField="PaymentBy" HeaderText="Payment By" SortExpression="PaymentBy" />
  289. <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
  290. </Columns>
  291. </asp:GridView>
  292. </div>
  293. </form>
  294. </body>
  295. </html>
BookingDetails.aspx.cs
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. using System.Diagnostics;
  13. using System.Collections.Generic;
  14. public partial class BookingDetails : System.Web.UI.Page
  15. {
  16. ConnClass connect = new ConnClass();
  17. #region Page_Load
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. if (!IsPostBack)
  21. {
  22. string scon = connect.GetConnection();
  23. string uid = Request.QueryString["PassengerId"];
  24. string qry = "select * from TrainBookingDetails
  25. where status='" + 0 + "' and PassengerID=" + uid;
  26. SqlDataAdapter sda = new SqlDataAdapter(qry, scon);
  27. DataSet ds = new DataSet();
  28. sda.Fill(ds);
  29. grdPassengerInfo.DataSource = ds;
  30. grdPassengerInfo.DataBind();
  31. if (grdPassengerInfo.Columns.Count > 0)
  32. {
  33. grdPassengerInfo.Columns[0].Visible = false;
  34. }
  35. }
  36. Response.Cache.SetAllowResponseInBrowserHistory(true);
  37. lblsession.Text=Convert.ToString(Session["UserName"]);
  38. }
  39. #endregion
  40. #region fill grid
  41. private DataSet bindGrid()
  42. {
  43. string scon = connect.GetConnection();
  44. string uid = Request.QueryString["PassengerId"];
  45. string qry = "select * from TrainBookingDetails
  46. where status='" + false + "' and PassengerID=" + uid;
  47. SqlDataAdapter sda = new SqlDataAdapter(qry, scon);
  48. DataSet ds = new DataSet();
  49. sda.Fill(ds);
  50. grdPassengerInfo.DataSource = ds;
  51. grdPassengerInfo.DataBind();
  52. if (grdPassengerInfo.Columns.Count > 0)
  53. {
  54. grdPassengerInfo.Columns[1].Visible = false; //hide grid column at run time
  55. }
  56. return ds;
  57. }
  58. #endregion
  59. #region pageIndexing
  60. protected void grdPassengerInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
  61. {
  62. grdPassengerInfo.PageIndex = e.NewPageIndex;
  63. bindGrid();
  64. }
  65. #endregion
  66. protected void grdPassengerInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
  67. {
  68. //GridViewRow row = (GridViewRow)grdPassengerInfo.Rows[e.RowIndex-1];
  69. //string scon = connect.GetConnection();
  70. ////string qry = "delete from TrainBookingDetails
  71. where TrainBookingID=" + row.Cells[1].Text + "";
  72. //string qry = "Update TrainBookingDetails set [Status]='"+true+"'
  73. where TrainBookingID=" + row.Cells[1].Text + "";
  74. //SqlDataAdapter sda = new SqlDataAdapter(qry, scon);
  75. //DataSet ds = new DataSet();
  76. //sda.Fill(ds);
  77. //bindGrid();
  78. }
  79. #region grid row deleting
  80. protected void grdPassengernfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
  81. {
  82. GridViewRow row = (GridViewRow)grdPassengerInfo.Rows[e.RowIndex];
  83. string scon = connect.GetConnection();
  84. //string qry = "delete from TrainBookingDetails
  85. where TrainBookingID=" + row.Cells[1].Text + "";
  86. string qry = "Update TrainBookingDetails set [Status]='" + true + "'
  87. where TrainBookingID=" + row.Cells[1].Text + "";
  88. SqlDataAdapter sda = new SqlDataAdapter(qry, scon);
  89. DataSet ds = new DataSet();
  90. sda.Fill(ds);
  91. bindGrid();
  92. }
  93. #endregion
  94. private const string ASCENDING = " ASC";
  95. private const string DESCENDING = " DESC";
  96. protected void grdPassengerInfo_Sorting(object sender, GridViewSortEventArgs e)
  97. {
  98. string sortExpression = e.SortExpression;
  99. if (GridViewSortDirection == SortDirection.Ascending)
  100. {
  101. GridViewSortDirection = SortDirection.Descending;
  102. SortGridView(sortExpression, DESCENDING);
  103. }
  104. else
  105. {
  106. GridViewSortDirection = SortDirection.Ascending;
  107. SortGridView(sortExpression, ASCENDING);
  108. }
  109. }
  110. private void SortGridView(string sortExpression, string direction)
  111. {
  112. // You can cache the DataTable for improving performance
  113. DataTable dt = bindGrid().Tables[0];
  114. DataView dv = new DataView(dt);
  115. dv.Sort = sortExpression + direction;
  116. grdPassengerInfo.DataSource = dv;
  117. grdPassengerInfo.DataBind();
  118. }
  119. public SortDirection GridViewSortDirection
  120. {
  121. get
  122. {
  123. if (ViewState["sortDirection"] == null)
  124. ViewState["sortDirection"] = SortDirection.Ascending;
  125. return (SortDirection)ViewState["sortDirection"];
  126. }
  127. set { ViewState["sortDirection"] = value; }
  128. }
  129. }
  130. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="BookTrains.aspx.cs" Inherits="PassengerProfile" %>
  131. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
  132. Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  133. <html xmlns="http://www.w3.org/1999/xhtml" >
  134. <head runat="server">
  135. <title>Untitled Page</title>
  136. <link rel="shortcut icon" href="Image/Train.ico" />
  137. </head>
  138. <body>
  139. <form id="form1" runat="server">
  140. <div>
  141. <asp:Label ID="lblHi" runat="server" Text="Hi" style="z-index: 102; left:
  142. 662px; position: absolute; top: 18px"></asp:Label>
  143. <asp:Label ID="lblName" runat="server" Text="" style="z-index: 101; left: 687px;
  144. position: absolute; top: 17px"></asp:Label><br />
  145. <asp:LinkButton ID="lnkeditProfile" runat="server">Book Train</asp:LinkButton>
  146. <table>
  147. <tr>
  148. <td>
  149. <asp:Label ID="lblFName" runat="server" Text="First Name" Font-Bold="True"></asp:Label></td>
  150. <td style="width: 199px">
  151. <asp:TextBox ID="txtFName" runat="server" ReadOnly="True"></asp:TextBox></td>
  152. </tr>
  153. <tr>
  154. <td>
  155. <asp:Label ID="lblLName" runat="server" Text="Last Name" Font-Bold="True"></asp:Label></td>
  156. <td style="width: 199px">
  157. <asp:TextBox ID="txtLName" runat="server" ReadOnly="True"></asp:TextBox></td>
  158. </tr>
  159. <tr>
  160. <td>
  161. <asp:Label ID="lblCountry" runat="server" Text="Country" Font-Bold="True"></asp:Label></td>
  162. <td style="width: 199px">
  163. <asp:DropDownList ID="ddlCountry" runat="server"
  164. AutoPostBack="True" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
  165. </asp:DropDownList></td>
  166. </tr>
  167. <tr>
  168. <td>
  169. <asp:Label ID="lblState" runat="server" Text="State" Font-Bold="True"></asp:Label></td>
  170. <td style="width: 199px">
  171. <asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True"
  172. OnSelectedIndexChanged="ddlState_SelectedIndexChanged">
  173. </asp:DropDownList></td>
  174. </tr>
  175. <tr>
  176. <td>
  177. <asp:Label ID="lblCity" runat="server" Text="City" Font-Bold="True"></asp:Label></td>
  178. <td style="width: 199px">
  179. <asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="True" >
  180. </asp:DropDownList></td>
  181. </tr>
  182. <tr>
  183. <td>
  184. <asp:Label ID="lblPincode" runat="server" Text="PinCode" Font-Bold="True"></asp:Label></td>
  185. <td style="width: 199px">
  186. <asp:TextBox ID="txtPincode" runat="server" ReadOnly="True"></asp:TextBox></td>
  187. </tr>
  188. <tr>
  189. <td>
  190. <asp:Label ID="lblMob" runat="server" Text="Mobile Number" Font-Bold="True"></asp:Label></td>
  191. <td style="width: 199px">
  192. <asp:TextBox ID="txtMobNo" runat="server" ReadOnly="True"></asp:TextBox></td>
  193. </tr>
  194. <tr>
  195. <td>
  196. <asp:Label ID="lblEmail" runat="server" Text="Email" Font-Bold="True"></asp:Label></td>
  197. <td style="width: 199px">
  198. <asp:TextBox ID="txtEmail" runat="server" ReadOnly="True"></asp:TextBox></td>
  199. </tr>
  200. <tr>
  201. <td>
  202. <asp:Label ID="lblTrainName" runat="server" Text="Train Name"
  203. Font-Bold="True"></asp:Label></td>
  204. <td style="width: 199px">
  205. <asp:DropDownList ID="ddlTrainName" runat="server" AutoPostBack="True"
  206. OnSelectedIndexChanged="ddlTrainName_SelectedIndexChanged">
  207. </asp:DropDownList>
  208. <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
  209. runat="server" ControlToValidate="ddlTrainName"
  210. ErrorMessage=" Select Train Name"
  211. InitialValue="Select Train" ToolTip="Select Train Name">*</asp:RequiredFieldValidator></td>
  212. </tr>
  213. <tr>
  214. <td>
  215. <asp:Label ID="lblTrainNo" runat="server" Text="Train Number" Font-Bold="True"></asp:Label></td>
  216. <td style="width: 199px">
  217. <asp:TextBox ID="txtTrainNo" runat="server" ReadOnly="True"></asp:TextBox></td>
  218. </tr>
  219. <tr>
  220. <td>
  221. <asp:Label ID="lblSourceStation" runat="server"
  222. Text="Source Station" Font-Bold="True"></asp:Label></td>
  223. <td style="width: 199px">
  224. <asp:DropDownList ID="ddlSourceStation" runat="server">
  225. </asp:DropDownList></td>
  226. </tr>
  227. <tr>
  228. <td>
  229. <asp:Label ID="lblDestinationStation" runat="server"
  230. Text="Destination Station" Font-Bold="True"></asp:Label></td>
  231. <td style="width: 199px">
  232. <asp:DropDownList ID="ddlDestinationStation" runat="server">
  233. </asp:DropDownList></td>
  234. </tr>
  235. <tr>
  236. <td>
  237. <asp:Label ID="lblPaymentBy" runat="server" Text="Payment By" Font-Bold="True">
  238. </asp:Label></td>
  239. <td style="width: 199px">
  240. <asp:DropDownList ID="ddlPaymentBy" runat="server">
  241. </asp:DropDownList>
  242. <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
  243. runat="server" ControlToValidate="ddlPaymentBy"
  244. ErrorMessage=" Select Card Type" InitialValue="Select Card Type"
  245. ToolTip="Select Card Type">*</asp:RequiredFieldValidator></td>
  246. </tr>
  247. <tr>
  248. <td>
  249. <asp:Label ID="lblAmount" runat="server" Text="Amount" Font-Bold="True"></asp:Label></td>
  250. <td style="width: 199px">
  251. <asp:TextBox ID="txtAmount" runat="server" ReadOnly="True"></asp:TextBox></td>
  252. </tr>
  253. <tr>
  254. <td>
  255. <asp:Button ID="btnBKTrainTk" runat="server"
  256. Text="Book Train Ticket" OnClick="btnBKTrainTk_Click" Font-Bold="True" /></td>
  257. <td style="width: 199px">
  258. <asp:LinkButton ID="lnkEdit" runat="server" OnClick="lnkEdit_Click">
  259. Edit UserInfo</asp:LinkButton>
  260. <asp:LinkButton ID="lnkUpdate" runat="server" OnClick="lnkUpdate_Click">
  261. Update UserInfo</asp:LinkButton></td>
  262. </tr>
  263. </table>
  264. </div>
  265. <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
  266. </form>
  267. </body>
  268. </html>
BookTrains.aspx.cs
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. using System.Collections.Specialized;
  13. public partial class PassengerProfile : System.Web.UI.Page
  14. {
  15. ConnClass connect = new ConnClass();
  16. #region Page_Load
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. if (!IsPostBack)
  20. {
  21. string unm = Convert.ToString(Session["UserName"]);
  22. lblName.Text = unm;
  23. lnkEdit.Text = "Edit User Info";
  24. lnkUpdate.Visible = false;
  25. if (Request.QueryString["url1"] != "")
  26. {
  27. HttpRequest q = Request;
  28. NameValueCollection n = q.QueryString;
  29. if (n.HasKeys())
  30. {
  31. int uid = Convert.ToInt32(n.Get(0));
  32. string sqlCon = connect.GetConnection();
  33. SqlConnection scon = new SqlConnection(sqlCon);
  34. string qry = "select * from PassengerInfo where PassengerId=" + uid;
  35. SqlCommand cmd = new SqlCommand(qry, scon);
  36. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  37. DataTable dt = new DataTable();
  38. sda.Fill(dt);
  39. if (dt.Rows.Count > 0)
  40. {
  41. txtFName.Text = dt.Rows[0]["FirstName"].ToString();
  42. txtLName.Text = dt.Rows[0]["LastName"].ToString();
  43. ddlCountry.DataSource = dt;
  44. ddlCountry.DataTextField = "Country";
  45. ddlCountry.DataValueField = "PassengerId";
  46. ddlCountry.DataBind();
  47. ddlState.DataSource = dt;
  48. ddlState.DataTextField = "State";
  49. ddlState.DataValueField = "PassengerId";
  50. ddlState.DataBind();
  51. ddlCity.DataSource = dt;
  52. ddlCity.DataTextField = "City";
  53. ddlCity.DataValueField = "PassengerId";
  54. ddlCity.DataBind();
  55. txtPincode.Text = dt.Rows[0]["Pincode"].ToString();
  56. txtMobNo.Text = dt.Rows[0]["MobileNo"].ToString();
  57. txtEmail.Text = dt.Rows[0]["Email"].ToString();
  58. }
  59. }
  60. }
  61. fillTrainInfo();
  62. ddlPaymentBy.Items.Add("Credit Card");
  63. ddlPaymentBy.Items.Add("Debit Card");
  64. ddlPaymentBy.Items.Insert(0, "Select Card Type");
  65. }
  66. }
  67. #endregion
  68. #region Fill Train Dropdown
  69. private void fillTrainInfo()
  70. {
  71. string sqlCon = connect.GetConnection();
  72. SqlConnection scon = new SqlConnection(sqlCon);
  73. string query = "select * from Train";
  74. SqlCommand cmd = new SqlCommand(query, scon);
  75. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  76. DataTable dt = new DataTable();
  77. sda.Fill(dt);
  78. if (dt.Rows.Count > 0)
  79. {
  80. ddlTrainName.DataSource = dt;
  81. ddlTrainName.DataTextField = "TrainName";
  82. ddlTrainName.DataValueField = "TrainID";
  83. ddlTrainName.DataBind();
  84. ddlTrainName.Items.Insert(0, "Select Train");
  85. }
  86. }
  87. #endregion
  88. #region Fill All Train Info
  89. protected void ddlTrainName_SelectedIndexChanged(object sender, EventArgs e)
  90. {
  91. if (ddlTrainName.SelectedValue != "Select Train")
  92. {
  93. string sqlconn = connect.GetConnection();
  94. SqlConnection scon = new SqlConnection(sqlconn);
  95. string qry = "select * from Train where TrainID=" + ddlTrainName.SelectedValue;
  96. ViewState["TRAINID"] = ddlTrainName.SelectedValue;
  97. int trainid = Convert.ToInt32(ViewState["TRAINID"]);
  98. SqlCommand cmd = new SqlCommand(qry, scon);
  99. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  100. DataTable dt = new DataTable();
  101. sda.Fill(dt);
  102. if (dt.Rows.Count > 0)
  103. {
  104. txtTrainNo.Text = dt.Rows[0]["TrainNumber"].ToString();
  105. ddlSourceStation.DataSource = dt;
  106. ddlSourceStation.DataTextField = "SourceStationName";
  107. ddlSourceStation.DataValueField = "TrainID";
  108. ddlSourceStation.DataBind();
  109. ddlDestinationStation.DataSource = dt;
  110. ddlDestinationStation.DataTextField = "DestinationStationName";
  111. ddlDestinationStation.DataValueField = "TrainID";
  112. ddlDestinationStation.DataBind();
  113. txtAmount.Text = dt.Rows[0]["Amount"].ToString();
  114. }
  115. }
  116. }
  117. #endregion
  118. #region Insert Book Train info
  119. protected void btnBKTrainTk_Click(object sender, EventArgs e)
  120. {
  121. string fnm = txtFName.Text;
  122. string lnm = txtLName.Text;
  123. string country = Convert.ToString(ddlCountry.SelectedItem);
  124. string state = Convert.ToString(ddlState.SelectedItem);
  125. string city = Convert.ToString(ddlCity.SelectedItem);
  126. int pin = Convert.ToInt32(txtPincode.Text);
  127. string mob = txtMobNo.Text;
  128. string email = txtEmail.Text;
  129. string trainNm = Convert.ToString(ddlTrainName.SelectedItem);
  130. int trainNo = Convert.ToInt32(txtTrainNo.Text);
  131. string soureceStation= Convert.ToString(ddlSourceStation.SelectedItem);
  132. string DestStation= Convert.ToString(ddlDestinationStation.SelectedItem);
  133. string payBy = Convert.ToString(ddlPaymentBy.SelectedItem);
  134. double amt = Convert.ToDouble (txtAmount.Text);
  135. int trainid = Convert.ToInt32(ViewState["TRAINID"]);
  136. if (Request.QueryString["url1"] != "")
  137. {
  138. HttpRequest q = Request;
  139. NameValueCollection n = q.QueryString;
  140. if (n.HasKeys())
  141. {
  142. int uid = Convert.ToInt32(n.Get(0));
  143. string scon = connect.GetConnection();
  144. string query = "insert into TrainBookingDetails(FirstName,LastName,Country,State,City,
  145. MobileNo,Email,PinCode,TrainNumber,TrainName,SourceStation,DestinationStation,PaymentBy,
  146. Amount,TrainID,PassengerID,status)values('" + fnm + "','" + lnm + "','" + country + "',
  147. '" + state + "','" + city + "','" + mob + "','" + email + "'," + pin + "," + trainNo + ",
  148. '" + trainNm + "','" + soureceStation + "','" + DestStation + "',
  149. '" + payBy + "'," + amt + "," + trainid + "," + uid + ","+0+")";
  150. SqlDataAdapter sda = new SqlDataAdapter(query, scon);
  151. DataSet ds = new DataSet();
  152. sda.Fill(ds);
  153. Response.Write("<script language='javascript'
  154. type='text/javascript'>alert('Train Booked Successfully..')
  155. </script>");
  156. string url = "BookingDetails.aspx?PassengerId=" + uid;
  157. Response.Redirect(url);
  158. }
  159. }
  160. }
  161. private void ClaearForm()
  162. {
  163. txtFName.Text="";
  164. txtLName.Text="";
  165. ddlCountry.SelectedIndex = -1;
  166. ddlState.SelectedIndex = -1;
  167. ddlCity.SelectedIndex = -1;
  168. txtPincode.Text = "";
  169. txtMobNo.Text="";
  170. txtEmail.Text="";
  171. ddlTrainName.SelectedValue = "Select Train";
  172. txtTrainNo.Text = "";
  173. ddlSourceStation.SelectedIndex = -1;
  174. ddlDestinationStation.SelectedIndex = -1;
  175. ddlPaymentBy.SelectedValue = "Select Card Type";
  176. txtAmount.Text="";
  177. }
  178. #endregion
  179. #region edit user profile
  180. protected void lnkEdit_Click(object sender, EventArgs e)
  181. {
  182. txtFName.ReadOnly = false;
  183. txtLName.ReadOnly = false;
  184. string sqlconn = connect.GetConnection();
  185. string Qry = "select * from CountryMaster";
  186. SqlDataAdapter sda = new SqlDataAdapter(Qry, sqlconn);
  187. DataSet ds = new DataSet();
  188. sda.Fill(ds);
  189. ddlCountry.DataSource = ds;
  190. ddlCountry.DataTextField = "CountryName";
  191. ddlCountry.DataValueField = "CountryID";
  192. ddlCountry.DataBind();
  193. ddlCountry.Items.Insert(0, "Select Country");
  194. txtPincode.ReadOnly = false;
  195. txtMobNo.ReadOnly = false;
  196. txtEmail.ReadOnly = false;
  197. btnBKTrainTk.Visible = false;
  198. lnkEdit.Visible = false;
  199. lnkUpdate.Visible = true;
  200. }
  201. #endregion
  202. #region fill state
  203. protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
  204. {
  205. if (ddlCountry.SelectedValue != "Select Country")
  206. {
  207. string sqlconn = connect.GetConnection();
  208. string qry = "select * from StateMaster where
  209. CountryID=" + ddlCountry.SelectedValue;
  210. SqlDataAdapter sda = new SqlDataAdapter(qry, sqlconn);
  211. DataSet ds = new DataSet();
  212. sda.Fill(ds);
  213. ddlState.DataSource = ds;
  214. ddlState.DataTextField = "StateName";
  215. ddlState.DataValueField = "StateID";
  216. ddlState.DataBind();
  217. ddlState.Items.Insert(0, "Select State");
  218. }
  219. }
  220. #endregion
  221. #region Fill City
  222. protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
  223. {
  224. if (ddlCountry.SelectedValue != "Select State")
  225. {
  226. string sqlconn = connect.GetConnection();
  227. string qry = "select * from CityMaster
  228. where stateID=" + ddlState.SelectedValue + "and
  229. CountryID=" + ddlCountry.SelectedValue;
  230. SqlDataAdapter sda = new SqlDataAdapter(qry, sqlconn);
  231. DataSet ds = new DataSet();
  232. sda.Fill(ds);
  233. ddlCity.DataSource = ds;
  234. ddlCity.DataTextField = "CityName";
  235. ddlCity.DataValueField = "CityID";
  236. ddlCity.DataBind();
  237. ddlCity.Items.Insert(0, "Select City");
  238. }
  239. }
  240. #endregion
  241. #region update UserInfo
  242. protected void lnkUpdate_Click(object sender, EventArgs e)
  243. {
  244. if (Request.QueryString["url1"] != "")
  245. {
  246. HttpRequest q = Request;
  247. NameValueCollection n = q.QueryString;
  248. if (n.HasKeys())
  249. {
  250. int uid = Convert.ToInt32(n.Get(0));
  251. string fnm = txtFName.Text;
  252. string lnm = txtLName.Text;
  253. string country = Convert.ToString(ddlCountry.SelectedItem);
  254. string state = Convert.ToString(ddlState.SelectedItem);
  255. string city = Convert.ToString(ddlCity.SelectedItem);
  256. int pin = Convert.ToInt32(txtPincode.Text);
  257. string mob = txtMobNo.Text;
  258. string email = txtEmail.Text;
  259. string scon = connect.GetConnection();
  260. string qry="Update PassengerInfo Set FirstName='"+fnm+"',
  261. LastName='"+lnm+"',
  262. Country='"+country+"',State='"+state+"',City='"+city+"',
  263. Pincode="+pin+",MobileNo='"+mob+"',
  264. Email='"+email+"' where PassengerId="+uid+"";
  265. SqlDataAdapter sda = new SqlDataAdapter(qry, scon);
  266. DataSet ds = new DataSet();
  267. sda.Fill(ds);
  268. Response.Write("Updated....");
  269. }
  270. lnkEdit.Visible = true;
  271. btnBKTrainTk.Visible = true;
  272. lnkUpdate.Visible = false;
  273. }
  274. }
  275. #endregion
  276. protected void btnCancel_Click(object sender, EventArgs e)
  277. {
  278. // ClaearForm();
  279. }
  280. }