客車網上售票系統(分解五)
阿新 • • 發佈:2020-08-09
1、今日完成任務:
(1)改簽分解功能1:點選改簽根據當前訂單的出發地和目的地查詢車票資訊並顯示(發車日期可以改動,出發地和目的地是固定不能變得)
(2)改簽分解功能2:選好需要改動的車票點選查詢頁面的改簽,跳轉到詳情頁面分別顯示需要改簽前的車票資訊和需要改簽後的車票資訊
(3)改簽分解功能3:點選提交訂單,顯示當前訂單的詳細資訊並提醒使用者抓緊時間支付
(4)改簽分解功能4:點選立即改簽即改簽成功並跳轉回我的訂單頁面
2、核心原始碼:
(1)改簽功能前臺頁面效果
(1)改簽分解功能1前臺效果圖
(2)改簽分解功能1前臺程式碼
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0"> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <link href="../css/reset.css" rel="stylesheet" /> <link href="../css/iconfont.css" rel="stylesheet" /> <link href="../css/aa.css" rel="stylesheet" /> <script src="../js/jquery-1.9.1.min.js"></script> <script src="../js/f.js"></script> <script src="../js/laydate/laydate.js"></script> <script> //執行一個laydate例項 laydate.render({ elem: '#test1' //指定元素}); </script> <style type="text/css"> .icon-weibiaoti1:before { content: "\e695"; } .icon-xinxiliulan:before { content: "\e614"; } #test1{clear:both;border:1px solid #ccc;height:25px;position:relative; left:50px;bottom:20px;} .InputDiv{border:none;} #txtCfd,#txtMdd{border:1px solid #ccc;height:25px;} #btnSelect{color:#fff;} .auto-style1 { background: #fff; margin-left: 40px; } .headboxtext{ height:30px; line-height:30px; } #GridView1{ text-align:center; } </style> <title>產車票改簽</title> </head> <body> <form id="form1" runat="server"> <div class="PublicHead clearfix"> <div class="leftBox clearfix"> <!--<div class="companyLogo"> <img src="images/logo.jpg" /> </div>--> <!--<i class="iconfont icon-caidan"></i>--> <div class="companyText"> 客車網上售票系統 </div> </div> <div class="RightBox clearfix"> <div class="UserPhotoBox"> <div class="UserPic"> <img src="../Images/user.jpg"/> </div> <div class="UserName"> 使用者 </div> </div> <a href="Login.aspx"> <div class="dropOutBox"> <i class="iconfont icon-app_icons--"> </i> <span>退出</span> </div> </a> </div> </div> <div class="PublicDownWhole clearfix"> <!--左側--> <div class="leftBox"> <ul> <a href="UpdatePersonalInfo.aspx"> <li class=""><i class="iconfont icon-yonghuguanli"></i><span>使用者資訊</span></li></a> <a href="SelectTicket.aspx"> <li class="Select"><i class="iconfont icon-tubiao_dingdan"></i><span>票務查詢</span></li> </a> <a href="MyOrder.aspx"> <li><i class="iconfont icon-fenlei"></i><span>我的訂單</span></li> </a> </ul> </div> <!--右側--> <div class="RightBox"> <div class="PublicContentBox"> <!--公用指向頁面名字--> <div class="PublicPointToAgeText"> <span class="span1">客車網上售票系統 </span> <span class="span2">我的訂單</span> <span class="span2">改簽</span> </div> <!--查詢--> <div class="InquireBox clearfix"> <div class="InquireleftBox"> <div class="Text">出發地:</div> <div class="InputDiv"> <asp:TextBox ID="txtCfd" runat="server" ReadOnly="true"></asp:TextBox></div> </div> <div class="InquireleftBox"> <div class="Text">目的地:</div> <div class="InputDiv"> <asp:TextBox ID="txtMdd" runat="server" ReadOnly="true"></asp:TextBox></div> </div> <div class="InquireleftBox" > <div class="layui-inline"> <label class="layui-form-label">日期:</label> <div class="layui-input-inline"> <asp:textBox runat="server" class="layui-input" id="test1"></asp:textBox> </div> </div> </div> <div class="PublicBtnIcon Color1Btn fr"> <i class="iconfont icon-icon-chaxun"></i> <%--<span>查詢</span>--%> <asp:Button ID="btnSelect" runat="server" Text="查詢" style="width: 38px" OnClick="btnSelect_Click" /> </div> </div> <!--表修改--> <div class="auto-style1" style="margin-left:0px; height:700px;"> <div class="headbox"> <div class="headboxtext"> <%--<span class="span1">車票查詢</span>--%> <asp:Label ID="lblSelect" runat="server" Text="車票查詢"></asp:Label> </div> </div> <!--查詢到的表格--> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Height="293px" Width="826px" Font-Size="Medium" PageSize="5" DataKeyNames="Cid"> <Columns> <asp:BoundField DataField="Tname" HeaderText="車次" /> <asp:BoundField DataField="Begin_sta" HeaderText="出發站" /> <asp:BoundField DataField="End_sta" HeaderText="到達站" /> <asp:BoundField DataField="Start_date" HeaderText="出發日期" /> <asp:BoundField DataField="Start_time" HeaderText="出發時間" /> <asp:BoundField DataField="End_time" HeaderText="到站時間" /> <asp:BoundField DataField="Price" HeaderText="價格" /> <asp:TemplateField HeaderText="是否有票"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%#(int)Eval("Seatnum")>0?"有票":"無" %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="備註"> <ItemTemplate> <asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl='<%# Eval("Cid", "~/Member/GQInfo.aspx?cid={0}") %>'>改簽</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> <HeaderStyle BackColor="#fe7844" Font-Bold="True" ForeColor="White" /> <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /> <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#FFF1D4" /> <SortedAscendingHeaderStyle BackColor="#B95C30" /> <SortedDescendingCellStyle BackColor="#F1E5CE" /> <SortedDescendingHeaderStyle BackColor="#93451F" /> </asp:GridView> </div> </div> </div> </div> </form> </body> </html>
(3)改簽分解功能1後臺臺程式碼
1.點選改簽按鈕跳轉頁面 /// <summary> /// 改簽 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { int oid = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value); //跳轉到查詢車票頁面車票頁面 Response.Redirect("GQ.aspx?oid="+oid); } 2.根據傳遞的oid資訊查詢出出發地和目的地並顯示出所有滿足條件的車票資訊 public partial class GQ : System.Web.UI.Page { OrderinfoManager bll = new OrderinfoManager(); CarinfoManager carBll = new CarinfoManager(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //繫結控制元件 int oid = Convert.ToInt32(Request.QueryString["oid"]); //根據oid查詢資訊並繫結在文字框中 DataSet ds = bll.SelectByOid(oid); this.txtCfd.Text = ds.Tables[0].Rows[0]["Begin_sta"].ToString(); this.txtMdd.Text= ds.Tables[0].Rows[0]["End_sta"].ToString(); Session["oid"] = oid; this.GridView1.DataSource = carBll.GetData(); this.GridView1.DataBind(); } } 3.根據使用者輸入的查詢日期進行查詢 /// <summary> /// 查詢 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSelect_Click(object sender, EventArgs e) { //從前臺獲取資料 //出發地 string cfd = this.txtCfd.Text; //目的地 string mdd = this.txtMdd.Text; string date = DateTime.MinValue.ToString(); if (this.test1.Text != "") { //出發日期 date = this.test1.Text; } this.GridView1.DataSource = carBll.GetDataByInfo(cfd, mdd, date); this.GridView1.DataBind(); } } DAL層: public DataSet SelectByOid(int oid) { string sql = $"select *from Orderinfo inner join Carinfo on Orderinfo.Cid=Carinfo.Cid where Oid={oid}"; DataSet ds = dbHelper.GetData(sql); return ds; } public DataSet GetDataByInfo(string beginSta,string endSta,string date) { string sql = $"select * from Traininfo inner join Carinfo on Traininfo.Tid=Carinfo.Tid where Cmark=0 and 1=1 "; if (beginSta!="") { sql += $"and Begin_sta ='{beginSta}'"; } if (endSta!="") { sql += $"and End_sta='{endSta}'"; } if (date!=DateTime.MinValue.ToString()) { sql += $"and Start_date='{date}'"; } DataSet ds = dbHelper.GetData(sql); return ds; }
(1)改簽分解功能2前臺頁面效果圖
(2)改簽分解功能2前臺頁面程式碼
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0"> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <link href="../css/reset.css" rel="stylesheet" /> <link href="../css/iconfont.css" rel="stylesheet" /> <link href="../css/aa.css" rel="stylesheet" /> <script src="../js/jquery-1.9.1.min.js"></script> <script src="../js/f.js"></script> <script src="../js/laydate/laydate.js"></script> <script> //執行一個laydate例項 laydate.render({ elem: '#test1' //指定元素 }); </script> <style type="text/css"> .icon-weibiaoti1:before { content: "\e695"; } .icon-xinxiliulan:before { content: "\e614"; } #test1 { clear: both; border: 1px solid #ccc; height: 25px; position: relative; left: 50px; bottom: 20px; } .InputDiv { border: none; } #txtCfd, #txtMdd { border: 1px solid #ccc; height: 25px; } #btnSelect { color: #fff; } .auto-style1 { background: #fff; margin-left: 40px; } .headboxtext { height: 30px; line-height: 30px; } #GridView1 { text-align: center; } table { width: 800px; border-collapse: collapse; text-align: center; } table tr td { border: 1px solid #000; } .auto-style2 { width: 812px; height: 134px; } .auto-style3 { width: 810px; height: 80px; } #ts{ border:1px solid #000; } #ts tr td{ border:none; } .auto-style4 { height: 35px; } #btnSubmit{ color: #fff; background-color:#fd4c4c; height:30px; width:100px; margin-left:710px; margin-top:50px; } #lbl{ color:#ff0000; font-weight:bolder; font-size:25px; } #btnGQ{ color: #fff; background-color:#fd4c4c; height:30px; width:100px; margin-left:710px; } </style> <title>車票改簽</title> </head> <body> <form id="form1" runat="server"> <div class="PublicHead clearfix"> <div class="leftBox clearfix"> <!--<div class="companyLogo"> <img src="images/logo.jpg" /> </div>--> <!--<i class="iconfont icon-caidan"></i>--> <div class="companyText"> 客車網上售票系統 </div> </div> <div class="RightBox clearfix"> <div class="UserPhotoBox"> <div class="UserPic"> <img src="../Images/user.jpg" /> </div> <div class="UserName"> 使用者 </div> </div> <a href="Login.aspx"> <div class="dropOutBox"> <i class="iconfont icon-app_icons--"></i> <span>退出</span> </div> </a> </div> </div> <div class="PublicDownWhole clearfix"> <!--左側--> <div class="leftBox"> <ul> <a href="UpdatePersonalInfo.aspx"> <li class=""><i class="iconfont icon-yonghuguanli"></i><span>使用者資訊</span></li></a> <a href="SelectTicket.aspx"> <li class="Select"><i class="iconfont icon-tubiao_dingdan"></i><span>票務查詢</span></li> </a> <a href="MyOrder.aspx"> <li><i class="iconfont icon-fenlei"></i><span>我的訂單</span></li> </a> </ul> </div> <!--右側--> <div class="RightBox"> <div class="PublicContentBox"> <!--公用指向頁面名字--> <div class="PublicPointToAgeText"> <span class="span1">客車網上售票系統 </span> <span class="span2">我的訂單</span> <span class="span2">改簽</span> </div> <!--表修改--> <div class="auto-style1" style="margin-left: 0px; height: 700px;"> <div class="headbox"> <div class="headboxtext"> <%--<span class="span1">車票查詢</span>--%> <asp:Label ID="lblSelect" runat="server" Text="車票改簽"></asp:Label> </div> </div> <!--查詢到的表格--> <div style="width:810px;margin-left:10px; "> <%-- <div style="height:80px; color:#ff0000;font-weight:bolder; text-align:center; line-height:80px; font-size:20px;display:none;" id="divShow"> 席位已鎖定,改簽交易尚未完成請在45分鐘之內完成網上支付 </div>--%> <div> <asp:Label ID="lbl" runat="server" Text=" " ></asp:Label> </div> <table class="auto-style3" id="ts"> <tr style="background-color: #fe7844; height: 30px; color: #fff; text-align: left;"> <td colspan="5"> 列車資訊(以下餘票資訊僅供參考)</td> </tr> <tr style="font-weight:bolder;"> <td class="auto-style4"> <asp:Label ID="GlblData" runat="server" Text="Label"></asp:Label> </td> <td class="auto-style4"> <asp:Label ID="GlblCc" runat="server" Text="Label"></asp:Label> <td class="auto-style4"> </td> <td class="auto-style4"> <asp:Label ID="GlblZD" runat="server" Text="Label"></asp:Label> </td> <td class="auto-style4"> <asp:Label ID="GlblPrice" runat="server" Text="Label"></asp:Label> </td> </tr> </table> <div style="text-align:right;"> <asp:Label ID="lblChajia" runat="server" Text=""></asp:Label> </div> <br /> <div id="yuan"> <table class="auto-style2"> <tr style="background-color: #fe7844; height: 30px; color: #fff; text-align: left;"> <td colspan="11"> 改簽原票資訊</td> </tr> <tr> <td>序號</td> <td>姓名</td> <td>證件型別</td> <td>證件號</td> <td>發車日期</td> <td>出發地</td> <td>目的地</td> <td>票種</td> <td>車次</td> <td>座位號</td> <td>票價</td> </tr> <tr> <td>1</td> <td> <asp:Label ID="lblName" runat="server" Text="Label"></asp:Label> </td> <td> <asp:Label ID="lblType" runat="server" Text="二代身份證"></asp:Label> </td> <td> <asp:Label ID="lblCard" runat="server" Text="Label"></asp:Label> </td> <td> <asp:Label ID="lblBeginData" runat="server" Text="Label"></asp:Label> </td> <td> <asp:Label ID="lblBeginSta" runat="server" Text="Label"></asp:Label> <br /> <asp:Label ID="lblBeginTime" runat="server" Text="Label"></asp:Label> </td> <td> <asp:Label ID="lblEndSta" runat="server" Text="Label"></asp:Label> <br /> <asp:Label ID="lblEndTime" runat="server" Text="Label"></asp:Label> </td> <td> <asp:Label ID="lblTicketType" runat="server" Text="成人票"></asp:Label> </td> <td> <asp:Label ID="lblCc" runat="server" Text="Label"></asp:Label> </td> <td> <asp:Label ID="lblSeatnum" runat="server" Text="Label"></asp:Label> </td> <td> <asp:Label ID="lblPrice" runat="server" Text="Label"></asp:Label> </td> </tr> </table> </div> <asp:Button ID="btnSubmit" runat="server" Text="提交訂單" OnClick="btnSubmit_Click" /> <asp:Button ID="btnGQ" runat="server" Text="立即改簽" Visible="false" OnClick="btnGQ_Click"/> </div> </div> </div> </div> </div> </form> </body> </html>
(3)改簽分解功能2後臺程式碼
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //原車票資訊 int oid = Convert.ToInt32(Session["oid"]); DataSet ds = bll.SelectByOid(oid); string beginSta = ds.Tables[0].Rows[0]["Begin_sta"].ToString(); string endSta = ds.Tables[0].Rows[0]["End_sta"].ToString(); string startDate = ds.Tables[0].Rows[0]["Start_date"].ToString(); string startTime = ds.Tables[0].Rows[0]["Start_time"].ToString(); string endTime = ds.Tables[0].Rows[0]["End_time"].ToString(); string name = ds.Tables[0].Rows[0]["Name"].ToString(); double price = Convert.ToDouble(ds.Tables[0].Rows[0]["Price"]); string card = ds.Tables[0].Rows[0]["card"].ToString(); int Seatnum = Convert.ToInt32(ds.Tables[0].Rows[0]["Seatnum"]); int tid = Convert.ToInt32(ds.Tables[0].Rows[0]["Tid"]); this.lblName.Text = name; this.lblCard.Text = card; this.lblBeginData.Text = startDate; this.lblBeginSta.Text = beginSta; this.lblBeginTime.Text = startTime + "開"; this.lblEndSta.Text = endSta; this.lblEndTime.Text = endTime + "到"; this.lblSeatnum.Text = Seatnum.ToString(); this.lblPrice.Text = price.ToString(); DataSet ds2 = tBll.SelectByTid(tid); this.lblCc.Text = ds2.Tables[0].Rows[0]["Tname"].ToString(); //改簽資訊 int cid = Convert.ToInt32(Request.QueryString["cid"]); DataSet ds3 = carBll.SelectCarTrainInfoByCid(cid); string date = Convert.ToDateTime(ds3.Tables[0].Rows[0]["Start_date"]).ToShortDateString(); string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; string xingqi = Day[Convert.ToInt32(Convert.ToDateTime(ds3.Tables[0].Rows[0]["Start_date"]).DayOfWeek.ToString("d"))].ToString(); string cc = ds3.Tables[0].Rows[0]["Tname"].ToString(); string GbeginSta = ds3.Tables[0].Rows[0]["Begin_sta"].ToString(); string GendSta = ds3.Tables[0].Rows[0]["End_sta"].ToString(); string GstartTime = ds3.Tables[0].Rows[0]["Start_time"].ToString(); string GendTime = ds3.Tables[0].Rows[0]["End_time"].ToString(); double Gprice = Convert.ToDouble(ds3.Tables[0].Rows[0]["Price"]); this.GlblData.Text = date + "(" + xingqi + ")"; this.GlblCc.Text = cc + "次"; this.GlblZD.Text = GbeginSta + "站(" + GstartTime + "開) -- " + GendSta + "站(" + GendTime + "到)"; this.GlblPrice.Text = Gprice.ToString(); } } DAL層: public DataSet SelectByOid(int oid) { string sql = $"select *from Orderinfo inner join Carinfo on Orderinfo.Cid=Carinfo.Cid where Oid={oid}"; DataSet ds = dbHelper.GetData(sql); return ds; } public DataSet SelectCarTrainInfoByCid(int cid) { string sql = $"select * from Traininfo inner join Carinfo on Traininfo.Tid=Carinfo.Tid where Cid={cid}"; DataSet ds = dbHelper.GetData(sql); return ds; }
(1)改簽分解功能3前臺頁面效果圖
(2)改簽分解功能3後臺頁面程式碼
/// <summary> /// 提交訂單 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { string s = "<style>#yuan{display:none;}</style>"; Response.Write(s); this.lbl.Text = "席位已鎖定,改簽交易尚未完成請在45分鐘之內完成網上支付!!!"; this.btnGQ.Visible = true; this.btnSubmit.Visible = false; //判斷差價 int oid = Convert.ToInt32(Session["oid"]); int cid = Convert.ToInt32(Request.QueryString["cid"]); DataSet ds = bll.SelectByOid(oid); DataSet ds3 = carBll.SelectCarTrainInfoByCid(cid); double price = Convert.ToDouble(ds.Tables[0].Rows[0]["Price"]); double Gprice = Convert.ToDouble(ds3.Tables[0].Rows[0]["Price"]); double chajia = price - Gprice; if (chajia > 0) { this.lblChajia.Text = "退還票款差額:" + chajia + "元"; } else if (chajia < 0) { this.lblChajia.Text = "需要補票款差額:" + chajia + "元"; } else { this.lblChajia.Text = "兩次票款相同,沒有差價!!!"; } }
(1)改簽分解功能4前臺頁面效果圖
(2) 改簽分解功能4前臺頁面程式碼
/// <summary> /// 改簽 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnGQ_Click(object sender, EventArgs e) { int oid = Convert.ToInt32(Session["oid"]); int cid = Convert.ToInt32(Request.QueryString["cid"]); DataSet ds = bll.SelectByOid(oid); int tid = Convert.ToInt32(ds.Tables[0].Rows[0]["Tid"]); int Seatnum = Convert.ToInt32(tBll.SelectByTid(tid).Tables[0].Rows[0]["Seatnum"]); DataSet ds3 = carBll.SelectCarTrainInfoByCid(cid); string date = Convert.ToDateTime(ds3.Tables[0].Rows[0]["Start_date"]).ToShortDateString(); double Gprice = Convert.ToDouble(ds3.Tables[0].Rows[0]["Price"]); //當前座位數=總座位數-當前列車的訂單數 int num = Seatnum - bll.SelectCount(date, cid); bool boo = bll.GaiQian(cid, Gprice, Seatnum, oid); if (boo) { //改簽成功 Response.Write("<script>alert('改簽成功!')</script>"); bool mark = true; Response.Redirect("MyOrder.aspx?m=" + mark); } else { Response.Write("<script>alert('改簽失敗!')</script>"); } } DAL層: public bool GaiQian(int cid,double price,int seatNum,int oid) { string sql = $"update Orderinfo set Cid={cid},State=1,Odate=getdate(),Seatnum={seatNum} where Oid={oid}"; int num = dbHelper.ExecuteNonQuery(sql); if (num != 0) { return true; } else { return false; } }
3、遇到的問題:
(1)改簽功能需要考慮的東西比較多,容易漏寫功能
(2)很多想實現的效果因為能力有限沒辦法實現,需要前端技術
4、解決的方法:
(1)網上搜索12306改簽流程實現
(2)技術能力方面需要利用這個暑假做提升