公交查询系统数据库课程设计报告Word格式.docx
- 文档编号:19772880
- 上传时间:2023-01-10
- 格式:DOCX
- 页数:20
- 大小:1.33MB
公交查询系统数据库课程设计报告Word格式.docx
《公交查询系统数据库课程设计报告Word格式.docx》由会员分享,可在线阅读,更多相关《公交查询系统数据库课程设计报告Word格式.docx(20页珍藏版)》请在冰豆网上搜索。
1、线路具体情况查询:
输入线路名称就可得到该线路的途经站点,发车和末班车时间,票价等相关信息。
2、经过此站点的所有路线查询:
输入站点名称即可得出经过该站点的所有线路名称。
3、站点间的点到点路线查询:
输入出发站点和目的站点即可输出可选择的线路,包括中间站的转乘。
2.3数据流图
2.4数据字典
1、数据项
名称
数据类型
长度
字段描述
name
varchar
5
公交车的名称
start_time
time
8
公交车每天的最早发车时间
end_time
公交车每天的收班时间
buslength1
int
2
公交线路去程的站点数
buslength2
公交线路回程的站点数
pt_price
float
3
普通车的票价
gd_price
高等级车的票价
disprice_pt
普通车刷卡后的价格
disprice_gd
高等级车刷卡后的价格
companyID
1
公司编号
company_name
30
公司名称
station_id
站点的编号
station_name
站点的名称
orderid
站点在一条线路中的位置
typeID
线路类型编号,共12类
type_name
线路类型名
direction
char
4
公交行驶方向,“去程”或“回程”
line
500
公交行驶途径的站点
2、数据流
说明
数据流来源
数据流去向
用户查询公交线路记录信息
记录公交车线路查询信息
线路+站点
查询结果输出
3、处理过程
简述
输入的数据流
处理
输出的数据流
线路查询
根据公交线路查询该线路上的所有站点
公交车编号
根据编号查询
查询出该线路上的所有公交车站点
站点查询
根据站点查询出经过该站点的所有公交车编号
站点名称
根据站点查询公交车的编号
路过该站点的所有公交车编号
站站查询
根据两个站点查询出所有线路
两个不同的站点
根据站点查询出所有线路
输出查询出的线路
三、数据库概念结构设计
根据需求分析,可知本系统有以下E-R图:
1、公交站点E-R图3、公交公司E-R图
2、公交车E-R图4、公交线路类型E-R图
5、合并E-R图
四、数据库逻辑结构设计
4.1关系表设计
根据ER模型,对本系统设计出5个关系表:
1、公交车表
bus(name,start_time,end_time,buslength1,buslength2,pt_price,dis_price,gd_price,company_id,type_id)
列名
NULL
约束
varchar(5)
notnull
primarykey
最早发车时间
收班时间
去程的站点数
回程的站点数
null
普通车刷卡
高等级车刷卡
foreignkeyreferencescompany(id),
Foreignkeyreferencesbus_type(id)
2、公交站点station(id,name)
id
varchar(30)
3、线路与站点关联表bus_station(bus_name,station_id,orderid)
记录公交线路经过站点的信息,并且按顺序记录各站点,以此记录线路与站点的关联信息。
bus_name
参照bus(name)
参照station(id)
4、公交公司表company(id,name)
Notnull
Varchar(5)
5、公交线路类型表bus_type(id,name)
Varchar(10)
6、公交线路表busline(bus_name,direction,line)
此表主要是为了方便依据线路来查询站点信息。
varchar(4)
varchar(500)
4.2数据表关系图
五、创建数据库及其对象
5.1建数据库和表
下面是创建数据库和表的过程,数据通过手动输入。
1、创建数据库
createdatabasebus
on
(
name='
bus_data1'
filename='
C:
\DocumentsandSettings\Administrator\桌面\bus\bus_data1.mdf'
)
logon
bus_log'
\DocumentsandSettings\Administrator\桌面\bus\bus_log.ldf'
2、创建表
公交公司表
createtablecompany
idintprimarykeynotnull,
namevarchar(30)notnull
公交线路类型表
createtablebus_type
namevarchar(5)notnull
公交站点
createtablestation
namevarchar(15)notnull
公交线路表
createtablebusline
(bus_namevarchar(5),
directionchar
(2)notnull,
linevarchar(200)notnull,
primarykey(bus_name,direction),
foreignkey(bus_name)referencesbus(name))
公交车表
createtablebus
(namevarchar(5)primarykeynotnull,
start_timedatetimenotnull,
end_timedatetimenotnull,
buslengthintnotnull,
pricefloatnotnull,
companyIDintnotnull,
typeIDintnotnull,
foreignkey(companyID)referencescompany(id),
foreignkey(typeID)referencesbus_type(id))
线路与站点关联表
createtablebus_station
bus_namevarchar(5),
station_idint,
orderidintnotnull,
primarykey(bus_name,station_id),
foreignkey(bus_name)referencesbus(name),
foreignkey(station_id)referencesstation(id)
5.2查询实现
这里只介绍线路查询和站站查询的存储过程实现,其它涉及到的功能通过SQLCommand或SqlDataAdapter实现,在后面的应用程序设计中实现。
ifexists(selectnamefromsysobjectswherename='
busline_info'
dropprocedurebusline_info
go
createprocedurebusline_info@inputvarchar(5),@outputvarchar(700)output
as
begin
select@output=line
frombusline
wherebusline.bus_name=@input
end
2、站点间的点到点路线查询:
station_station'
dropprocedurestation_station
createprocedurestation_station@input1varchar(30),@input2varchar(30),@output1varchar(5)output,@output2varchar(5)output,@output3varchar(5)output,@output4varchar(30)output,@output5varchar(30)output
declare@stationID1int,@stationID2int--换乘过程中的中间站点
declare@id1int,@id2int--记录起点和终点的ID
select@id1=idfromstationwherename=@input1
select@id2=idfromstationwherename=@input2
--查找直达线路
select@output1=a.bus_name
from
(selectbus_namefrombus_stationwherestation_id=@id1)a,
(selectbus_namefrombus_stationwherestation_id=@id2)b
wherea.bus_name=b.bus_name
--若不存在直达线路,则搜寻一次换乘路线
ifnotexists(select*frombuswherename=@output1)
begin
--查找中间站点
select@stationID1=c.station_idfrom
--@input1能直达的站点集合c
(selectdistinctstation_id
frombus_station
wherebus_namein(selectbus_namefrombus_stationwherestation_id=@id1))c,
--@input2能直达的站点集合d
wherebus_namein(selectbus_namefrombus_stationwherestation_id=@id2))d
wherec.station_id=d.station_id
(selectbus_namefrombus_stationwherestation_id=@id1)a,
(selectbus_namefrombus_stationwherebus_station.station_id=@stationID1)b
select@output2=a.bus_name
(selectbus_namefrombus_stationwherestation_id=@id2)a,(selectbus_namefrombus_stationwherebus_station.station_id=@stationID1)b
end
--若不存在直达和一次换乘线路,则搜寻二次换乘路线
ifnotexists(select*frombuswherename=@output1)andnotexists(select*frombuswherename=@output2)
--查找中间线路
(selectdistinctbus_name
frombus_station
wherestation_idin
(selectstation_idfrombus_station
wherebus_namein
(selectbus_namefrombus_stationwherestation_id=@id1)))a,
(selectdistinctbus_namefrombus_station
wherestation_idin
(selectstation_idfrombus_stationwherebus_namein(selectbus_namefrombus_stationwherestation_id=@id2)))b
--查找起点到中间线路的公交车
select@stationID1=a.station_id
(selectdistinctstation_idfrombus_stationwherebus_namein(selectbus_namefrombus_stationwherestation_id=@id1))a,
(selectstation_idfrombus_stationwherebus_name=@output2)b
wherea.station_id=b.station_id
select@output1=c.bus_name
(selectbus_namefrombus_stationwherestation_id=@id1)c,
(selectbus_namefrombus_stationwherestation_id=@stationID1)d
wherec.bus_name=d.bus_name
--查找中间线路到终点的公交车
select@stationID2=a.station_id
(selectdistinctstation_idfrombus_stationwherebus_namein(selectbus_namefrombus_stationwherestation_id=@id2))a,
select@output3=c.bus_name
(selectbus_namefrombus_stationwherestation_id=@id2)c,
(selectbus_namefrombus_stationwherestation_id=@stationID2)d
end
select@output4=namefromstationwhereid=@stationID1
select@output5=namefromstationwhereid=@stationID2
五、软件功能设计
软件共实现了3个大功能,即站点查询、线路查询、站站查询,其完成情况如下:
(一):
检查用户是否输入了站点或线路信息,如果没有录入,则提示:
请输入站点!
或请输入线路名!
(二):
检查用户是否输入的站点或线路是否存在,如果不存在,则提示:
此站点不存在!
或此线路不存在!
(三):
如果信息都填写正确,则根据选定的查询条件进行查找,查找的具体实现为:
(1)站点查询:
返回经过此站点的所有线路,并提供一条线路经过的所有站点。
如果没有结果,则提示:
找不到此站点!
(2)线路查询:
返回此线路的类型、最早和最晚时间、票价、经过站点等信息。
(3)站站查询:
返回从起点到终点的可行的一条线路,此线路可直达,如果没有直达,则最多换乘两次,并提示在哪里下车换乘,以及所有车辆的站点信息。
六、界面设计
七、应用程序
7.1站点查询
//查询经过给定站点的公交线路
protectedvoidstation_info(stringinput)
{
SqlConnectionmyConnection=newSqlConnection(connectionString);
myConnection.Open();
SqlCommandcmd=newSqlCommand("
selectbus_station.bus_nameas公?
交?
线?
路¡
¤
名?
busline.directionas方¤
?
向¨
°
lineas途ª
径?
站?
点Ì
frombus_station,station,buslinewherestation.name='
"
+input+"
'
anddbo.station.id=bus_station.station_idandbus_station.bus_name=busline.bus_name"
myConnection);
SqlDataAdapterda=newSqlDataAdapter();
da.SelectCommand=cmd;
System.Data.DataSetds=newSystem.Data.DataSet();
da.Fill(ds);
this.GridView1.DataSource=ds.Tables[0];
GridView1.DataBind();
cmd=null;
myConnection.Close();
}
7.2线路查询
//查询给定线路的公交车所经过站点
protectedstringbusline_info1(stringinput)
{stringconnectionString=@"
server=TXJM1FW3L1GYIC6;
database=bus;
IntegratedSecurity=true"
;
SqlCommandmyCommand=newSqlCommand("
busline_info"
myCommand.CommandType=System.Data.CommandType.StoredProcedure;
//创建参数
SqlParameterbus_name=newSqlParameter("
@input"
System.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 公交查询 系统 数据库 课程设计 报告