ASP.NET电子客票系统 第5页
ADO.NET是.NET框架中的数据访问组件,是一种新的数据访问对象模型。通过ADO.NET进行数据访问。ADO.NET提供了DataSet对象,它是一个与数据源无关的关系数据编程模型,它包含的对象和方法与关系数据模型相一致。ADO.NET连接的基本步骤如下:
1.声明一个连接对象;
2.提供一个连接字符串;
3.调用连接对象的OPEN方法;
4.只要ADO.NET方法需要,就指定连接对象的名称;
所谓的编码就是把软件结果翻译成用某种程序设计语言书写的程序。作为软件工程设计的一个阶段,编码是对设计进一步的具体化。因此,程序的质量主要取决于软件设计的质量。但是所选择的程序设计语言的特点及编码风格也将对程序的可靠性,可读性,可测试性和可文护性产生深远的影响。本系统运用VB.NET进行编程。
根据第三章需求分析和第四章总体设计,我们得到了系统的功能模块和系统的体系结构,详细设计阶段的根本目标是确定应该怎样具体地实现所要求的系统,而在编码阶段可以把这个描述翻译成用某种程序设计语言书写的程序。下面在此基础上,对各个进行详细设计以及编码实现。
用户通过登陆窗口进行身份验证(输入账号和密码,系统将获取的用户信息与数据库里相应的用户信息进行比较)。如登陆信息都正确则进入系统最初界面,不同的用户将获得不同的权限。如登陆信息不正确,则无法登陆系统。添加新的用户,需要填写用户名、密码、确认密码和真实姓名。当填写完毕后且无误后点击确认按钮,如系统中不存在该用户(账号),则系统弹出“注册成功!”的对话框即添加成功,系统将自动转为用这个注册用户登录。系统将自动调转到航班查询页面。
登录和注册用户界面如图5.1和图5.2所示
图5.1用户登录页面
代码:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myconnection As SqlConnection
myconnection = New SqlConnection("server=(local);uid=sa;password=123;database=电子客票")
Dim sql As String
sql = "select * from 客户信息表 where 用户名= '" & usename.Text & "'and 登陆密码='" & pwd.Text & "'"
Dim selectcommand As SqlCommand = New SqlCommand(sql, myconnection)
Dim reader As SqlDataReader
Dim temp As String
myconnection.Open()
reader = selectcommand.ExecuteReader()
temp = reader.Read()
If LCase(temp) <> "true" Then
Response.Write("<script languaage='javascript'>alert('帐号,密码不正确!')</script>")
Else
Session("用户名") = reader.Item("客户姓名")
Session("用户编号") = usename.Text
Response.Redirect("航班搜索.aspx")
End If
myconnection.Close()
End Sub
图5.2用户注册页面
代码:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If namebox.Text = "" Or num.Text = "" Or honenum.Text = "" Or mobnum.Text = "" Or e_mail.Text = "" Or work.Text = "" Or addr.Text = "" Or youbian.Text = "" Or fax.Text = "" Then
Else
Dim myconnection As SqlConnection
myconnection = New SqlConnection("server=(local);uid=sa;password=123;database=电子客票")
Dim sql As String
sql = "select 用户名 from 客户信息表 where 用户名='" & userid.Text & "'"
Dim selectcommand As SqlCommand = New SqlCommand(sql, myconnection)
Dim reader As SqlDataReader
Dim temp As String
myconnection.Open()
reader = selectcommand.ExecuteReader()
temp = reader.Read()
myconnection.Close()
If LCase(temp) = "true" Then
Response.Write("<script languaage='javascript'>alert('账号以存在!')</script>")
userid.Text = ""
pwd.Text() = ""
pwd1.Text = ""
Else
If pwd.Text <> pwd1.Text Then
Response.Write("<script languaage='javascript'>alert('密码不正确!')</script>")
pwd.Text = ""
pwd1.Text = ""
Else
Dim sql1 As String
sql1 = "insert into 客户信息表(用户名,客户姓名,客户性别,证件类型,证件号码,联系电话,手机,传真,电子邮箱,工作单位,通信地址,邮政编码,登陆密码) values ('" & userid.Text.Trim & "','" & namebox.Text.Trim & "','" & sex.SelectedItem.Text.Trim & "','" & post.SelectedItem.Text.Trim & "','" & num.Text.Trim & "','" & honenum.Text.Trim & "','" & mobnum.Text.Trim & "','" & fax.Text.Trim & "','" & e_mail.Text.Trim & "','" & work.Text.Trim & "','" & addr.Text.Trim & "','" & youbian.Text.Trim & "','" & pwd.Text.Trim & "')"
Dim selectcommand1 As SqlCommand = New SqlCommand(sql1, myconnection)
myconnection.Open()
selectcommand1.ExecuteNonQuery()
myconnection.Close()
Response.Write("<script languaage='javascript'>alert('注册成功!')</script>")
Session("用户名") = namebox.Text
Session("用户编号") = userid.Text
Response.Redirect("航班搜索.aspx")
End If
End If
End If
End Sub
用户使用先是用航班搜索页面搜索出所需要的航班信息,用户选择所需要的航班在预定页面中列出这个航班的航班信息和该用户的注册信息,然后调转到用户订票信息页,用户在这也可以查看自己订票的信息,用户选择了自己所订的客票以后跳转到付款退订页,用户单击付款后到网上银行付款。
用户预定页面设计如图5.3 至 图5.6 所示
图5.3 航班搜索页面
代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myconnection As SqlConnection
myconnection = New SqlConnection("server=(local);uid=sa;password=123;database=电子客票")
Dim sql As String
sql = "select * from 航线信息表 where 出发城市= '" & TextBox1.Text & "'and 到达城市='" & TextBox2.Text & "' "
Dim selectcommand As SqlCommand = New SqlCommand(sql, myconnection)
Dim mycommand As New SqlDataAdapter(sql, myconnection)
Dim reader As SqlDataReader
Dim ds As New DataSet
If TextBox3.Text = "" Then
Response.Write("<script languaage='javascript'>alert('选择你要订票的日期!')</script>")
Else
myconnection.Open()
reader = selectcommand.ExecuteReader()
myconnection.Close()
mycommand.Fill(ds, "Literature")
DataGrid1.DataSource = ds.Tables("Literature").DefaultView
DataGrid1.DataBind()
Session("日期") = TextBox3.Text
Session("舱位类型") = DropDownList1.SelectedItem.Text
End If
End Sub
Private Sub ImageButton6_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton6.Click
Calendar1.Visible = True
End Sub
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
TextBox3.Text = Calendar1.SelectedDate
Calendar1.Visible = False
End Sub
图5.4预定页面
代码:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
airnum.Text = Request.QueryString("a1")
takedate.Text = Session("日期")
cangwei.Text = Session("舱位类型")
userid.Text = Session("用户编号")
Dim conn As SqlConnection
conn = New SqlConnection("server=(local);uid=sa;password=123;database=电子客票")
Dim sql1 As String
sql1 = "select * from 航线信息表 where 航线编号= '" & airnum.Text & "'"
Dim selectcommand1 As SqlCommand = New SqlCommand(sql1, conn)
Dim reader1 As SqlDataReader
conn.Open()
reader1 = selectcommand1.ExecuteReader()
reader1.Read()
takeup.Text = reader1.Item("出发城市")
takedown.Text = reader1.Item("到达城市")
takeuptime.Text = reader1.Item("出发时间")
takedowntime.Text = reader1.Item("到达时间")
plannum.Text = reader1.Item("客机编号")
price.Text = reader1.Item(cangwei.Text)
conn.Close()
Dim sql2 As String
sql2 = "select * from 客户信息表 where 用户名='" & userid.Text & "'"
Dim selectcommand2 As SqlCommand = New SqlCommand(sql2, conn)
Dim reader2 As SqlDataReader
conn.Open()
reader2 = selectcommand2.ExecuteReader()
reader2.Read()
username.Text = reader2.Item("客户姓名")
zjleixing.Text = reader2.Item("证件类型")
zjnum1.Text = reader2.Item("证件号码")
conn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlConnection
conn = New SqlConnection("server=(local);uid=sa;password=123;database=电子客票")
Dim sql2 As String
sql2 = "insert into 订票信息表(客户编号,客户姓名,证件类型,证件号码,航线编号,出发城市,到达城市,舱位类型,出发日期,舱位价格,是否结算,登机) values ('" & userid.Text.Trim & "','" & username.Text.Trim & "','" & zjleixing.Text.Trim & "','" & zjnum.Text.Trim & "','" & airnum.Text.Trim & "','" & takeup.Text.Trim & "','" & takedown.Text.Trim & "','" & cangwei.Text.Trim & "','" & takedate.Text.Trim & "','" & price.Text.Trim & "','否','否')"
Dim selectcommand2 As SqlCommand = New SqlCommand(sql2, conn)
conn.Open()
selectcommand2.ExecuteNonQuery()
conn.Close()
Response.Write("<script languaage='javascript'>alert('订票成功!')</script>")
Response.Redirect("付款退定.aspx")
End Sub
图5.5 用户订票信息页面
代码:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
userid.Text = Session("用户编号")
Dim myconnection As SqlConnection
myconnection = New SqlConnection("server=(local);uid=sa;password=123;database=电子客票")
Dim sql As String
sql = "select * from 订票信息表 where 客户编号= '" & userid.Text & "'"
Dim selectcommand As SqlCommand = New SqlCommand(sql, myconnection)
Dim mycommand As New SqlDataAdapter(sql, myconnection)
Dim reader As SqlDataReader
Dim ds As New DataSet
myconnection.Open()
reader = selectcommand.ExecuteReader()
myconnection.Close()
mycommand.Fill(ds, "Literature")
DataGrid1.DataSource = ds.Tables("Literature").DefaultView
DataGrid1.DataBind()
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>