基于网络的火车售票系统

时间:2022-02-28 11:09:32

基于网络的火车售票系统

摘要:基于网络的火车售票系统是通过网络查询信息,进行火车票的预定、购买、支付的信息管理系统。订票在本系统中扮演着十分重要的角色,设计和实现一个完整的基于网络的基于网络的火车售票系统能够为旅客提供一个快捷、便利的购票渠道,对促进火车票务事业的发展具有十分重要的意义。本系统采用模块化程序设计方法,既便于系统功能的各种组合和修改,又便于未参与开发的技术维护人员补充、维护。本系统主要包括管理员管理模块、业务收费班次票单管理模块、 用户注册模块、票单订购模块。最终实现了管理员对车次的添加、删除、修改,客户进行网上查询、订票、退票等功能。

关键词:火车售票系统;数据库;面向对象编程

中图分类号:TP315文献标识码:A文章编号:1009-3044(2007)17-31223-03

Ticket Sale System of Train Based on Web

XU Yong-hui1, HU Lin1, LIU Ping2

(1.Jiangxi Modern College, Nanchang 330012, China; 2.Jiangxi Dayu Vocational Institute, Nanchang 330043, China)

Abstract: The train ticket-selling system based on web is a kind of information management system which prearranges, purchases and pays for traffic tickets through network inquiry information. Ticket-selling system plays a key part in the system. Designing and realizing a train ticket-selling system based on the network can provide a quick and convenience channel in buying tickets for the passenger. It is very significant that the development promotes the train ticket clerk enterprise. This system uses the modularized program design method, which is advantageous for each kind of combination and the revision of system function, and is advantageous for servicing personnel who has not participated in the development to supplement and maintenance. This system mainly includes the managing module, servicing charge school grade order ticket list administration, module user registration module, and the train-booking module. Finally it has realized the functions that are the management of the coach-number increasing, the deletion, the revision, the customer carried for inquiring, the order form, returning ticket and so on.

Key words: Train Booking System; Database; Object-Oriented Programming

1 引言

随着计算机网络技术等高科技的迅猛突破与广泛普及,将会有越来越多得家庭通过进入Internet网或Intranet局域网来获取信息和资讯。火车客运是交通运输业中的一个重要组成部分,为了更加方便对乘客服务,采用网络技术进行网上售票和公布一些信息是很有必要的。该软件所欲达到的目标即实现用户分权限管理、售票员和车次的添加、删除、修改、车次信息查询等功能。系统具有开放性、面向对象性、独立性和可维护性等特性。

2 设计方案

“基于网络的火车售票系统”对数据库的操作是通过MFC的ODBC类来实现的。除主框架,系统的所有其他界面都是模式对话框型。考虑到该软件应用的广泛性和安全性,任何用户可注册进入该系统进行浏览,但只有系统管理员可以对系统进行维护。可以对售票员和车次进行添加、删除、修改操作,售票员进入系统可以进行车次查询、卖票、票单结款。客户注册后可以进入系统进行查询、订票、退票。该系统采用了较方便的查询操作,用户只需选择一种查询方式或输入几个关键字便可查到与其相关的结果。用户可以订购一定日期里的车票。系统自动记录客户输入的信息,售票员根据客户注册信息中的地址送票。除此之外,系统还提供了对客户信息的统计分析功能,以便管理人员更好的了解客户的基本状况。系统的可靠性是靠数据库的维护来完成,数据库备份和恢复可对整个数据库进行拷贝,这样大大减少因为误操作或人为原因带来的损害程度。系统的基本框架如图1所示。

3 关键技术

3.1 用户登录

该模块的用户类型包括管理员、售票员、客户。选择用户类型 ,输入编号和响应的密码点确定就可以进入操作界面进行操作了。第一登录的客户应先注册再返回登录截面进入系统。用户类型ComboBox1.SelectedItem选择不同的选项时,mreader.Read()函数调用相应的数据表。不同的用户类型访问的权限不同。界面如图1所示。

图1 系统框架图2 用户登录

客户登录模块作为系统入口,先验证用户信息,根据用户类型给出系统功能入口。在“项目”中新建窗体,用户选择用户类型后,用户类型赋值给全局变量ComboBox1.SelectedItem,并根据该用户类型调用相应的数据表进入相应的管理功能,也就是使相应的功能菜单可用。代码如下:

Public Class Form1

Inherits System.Windows.Forms.Form

Dim mconnection As New SqlClient.SqlConnection

Dim a As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.Text = TextBox1.Text.Trim

TextBox2.Text = TextBox2.Text.Trim

If ComboBox1.SelectedItem Is Nothing Then '如果用户类型为空

MsgBox("请选择用户类型!")

Exit Sub

End If

Try

'连接数据库

mconnection.ConnectionString = connstr

mconnection.Open()

Dim mcommand As New SqlClient.SqlCommand

mcommand.Connection = mconnection

If ComboBox1.SelectedItem = "管理员" Then '管理员

'在数据库中查找相应的编号和密码

mandText = "select 编号,密码 from 管理员信息 where 编号 like '"

mandText += TextBox1.Text + "'"

Dim mreader As SqlClient.SqlDataReader

mreader = mcommand.ExecuteReader()

If Not (mreader.Read()) Then '如果找不到

MsgBox("不存在本编号的管理员,请确认!")

Exit Sub

End If

' 如果找到

If Trim(mreader("密码").ToString) = Trim(TextBox2.Text).ToString Then

cdct_id = Trim(TextBox1.Text).ToString

Dim f2 As New Form2

f2.Show()

f2.TabPage4.Enabled = False

f2.TabPage5.Enabled = False

f2.TabPage6.Enabled = False

f2.TabPage7.Enabled = False

Me.Hide()

Else

If a = 3 Then

MsgBox("对不起,你无权使用,再见!")

Me.Close()

Else

MsgBox("密码错误,请确认!")

TextBox2.Text = ""

TextBox2.Focus()

a = a + 1

End If

End If

ElseIf ComboBox1.SelectedItem = "售票员" Then '售票员

'在数据库中查找相应的编号和密码

mandText = "select 编号,密码 from 售票员信息 where 编号 like '"

mandText += TextBox1.Text + "'"

Dim mreader As SqlClient.SqlDataReader

mreader = mcommand.ExecuteReader()

If Not (mreader.Read()) Then '如果找不到

MsgBox("不存在本编号的售票员,请确认!")

Exit Sub

End If

' 如果找到

If Trim(mreader("密码").ToString) = Trim(TextBox2.Text).ToString Then

cdct_id = Trim(TextBox1.Text).ToString

Dim f2 As New Form2

f2.Show()

f2.TabPage1.Enabled = False

f2.TabPage2.Enabled = False

f2.TabPage8.Enabled = False

f2.TabPage3.Enabled = False

Me.Hide()

Else

If a = 3 Then

MsgBox("对不起,你无权使用,再见!")

Me.Close()

Else

MsgBox("密码错误,请确认!")

TextBox2.Text = ""

TextBox2.Focus()

a = a + 1

End If

End If

Else If ComboBox1.SelectedItem = "客户" Then '客户

'在数据库中查找相应的编号和密码

mandText = "select 编号,密码 from 客户信息 where 编号 like '"

mandText += TextBox1.Text + "'"

Dim mreader As SqlClient.SqlDataReader

mreader = mcommand.ExecuteReader()

If Not (mreader.Read()) Then'如果找不到

MsgBox("不存在本编号的客户,请确认!")

Exit Sub

End If

'如果找到

If Trim(mreader("密码").ToString) = Trim(TextBox2.Text).ToString Then

cdct_id = Trim(TextBox1.Text).ToString

Dim f2 As New Form2

f2.Show()

f2.TabPage1.Enabled = False

f2.TabPage2.Enabled = False

f2.TabPage3.Enabled = False

f2.TabPage4.Enabled = False

f2.TabPage7.Enabled = False

f2.TabPage8.Enabled = False

Me.Hide()

Else

If a = 3 Then

MsgBox("对不起,你无权使用,再见!")

Me.Close()

Else

MsgBox("密码错误,请确认!")

TextBox2.Text = ""

TextBox2.Focus()

a = a + 1

End If

End If

End If

Catch ex As Exception

Debug.WriteLine(ex.Message)

Finally

mconnection.Close()

End Try

End Sub

3.2 售票窗体

在信息框中输入所需车票的相关信息进行查询,DataGrid1中将显示满足客户要求的车辆,选择具体车票即可卖票。tuipiao查询此前是否有人退票,yizuo查询已售车票。如果有剩余车票打印车票并计算金额。界面如图3所示。

图3 售票窗体

售票员模块主要由卖票和订票结款组成,包括查询、卖票、金额计算、结账等。

查询满足客户要求的车次代码如下:

'查找相应车次

Dim ds As New DataSet

sqlstr = "select * from 车次表 where途经 like '%" + txt起点站.Text + "%" + txt终点站.Text + "%' and 车型 like '%" + cmb车型.SelectedItem + "%'"

上一篇:P2P网络中Windows系统安全策略研究 下一篇:基于B/S模式的电子病历与医学影像系统集成研究