公交查询系统—数据库课程设计分析方案.pdf
《公交查询系统—数据库课程设计分析方案.pdf》由会员分享,可在线阅读,更多相关《公交查询系统—数据库课程设计分析方案.pdf(15页珍藏版)》请在三一文库上搜索。
1、数据库课程设计 报告 班级: 序号: 姓名: 地球科学学院地信系 2018-06-28 1 / 15 目录 数据库课程设计1 目录 2 一、概述3 1.1 背景说明 3 1.2 开发环境 3 二、需求分析3 2.1 用户需求 3 2.2 主要功能 3 2.3 数据流图 3 2.4 数据字典 3 三、数据库概念结构设计4 四、数据库逻辑结构设计2 4.1 关系表设计2 4.2 数据表关系图2 五、创建数据库及其对象2 5.1 建数据库和表2 5.2 查询实现3 五、软件功能设计5 六、界面设计6 七、应用程序6 7.1 站点查询6 7.2 线路查询7 7.3 站站查询8 八、实验数据示例10 九
2、、心得11 2 / 15 选择查询类型判断类型 按起始、目的 站点查询 按站点查询 按线路查询 反馈给用户 站点信息数据 乘车方案 线路信息数据 站点名 公交车编号 起 始 点 目 的 点 一、概述 1.1 背景说明 软件名称:公交线路查询系统 工程提出者: 工程开发者: 用户:广大需要乘坐公交车的人群 1.2 开发环境 操作系统: Windows XP 软件配置: visual stutio2018,Microsoft SQLServer 2008 R2 数据库配置: Microsoft SQL Server 2008 R2在 PC机中新建数据库,建立各个数据表、关系图。 二、需求分析 2.
3、1 用户需求 城市的扩张使得公交线路越来越复杂,为了使得用户更加方便地能够获得最新公交线路,“公交线 路查询工具”帮助人们解决这个问题。 本系统面向的对象是普通乘客,对于普通乘客来说,他们最关心的就是查询。系统也只对用户提供信 息查询功能,并不对用户开放对数据的编辑权限。对于任何用户,只要浏览本系统的首页,就可以根据自 己的需求进行查询。数据的修改、删除、及时更新工作只能由管理人员实现并对系统进行定期的维护,保 证其运行的稳定性。 2.2 主要功能 本系统从用户的需求出发,可实现以下功能: 1、线路具体情况查询:输入线路名称就可得到该线路的途经站点,发车和末班车时间,票价等相关信 息。 2、经
4、过此站点的所有路线查询:输入站点名称即可得出经过该站点的所有线路名称。 3、站点间的点到点路线查询:输入出发站点和目的站点即可输出可选择的线路,包括中间站的转乘。 2.3数据流图 2.4 数据字典 1、数据项 名称数据类型长度字段描述 3 / 15 namevarchar5 公交车的名称 start_timetime8 公交车每天的最早发车时间 end_timetime8 公交车每天的收班时间 buslength1int2 公交线路去程的站点数 buslength2int2 公交线路回程的站点数 pt_pricefloat3 普通车的票价 gd_pricefloat3 高等级车的票价 disp
5、rice_ptfloat3 普通车刷卡后的价格 disprice_gdfloat3 高等级车刷卡后的价格 companyIDint1 公司编号 company_namevarchar30 公司名称 station_idint3 站点的编号 station_namevarchar30 站点的名称 orderidint2 站点在一条线路中的位置 typeIDint2 线路类型编号,共12 类 type_namevarchar5 线路类型名 directionchar4 公交行驶方向,“去程”或“回程” linevarchar500 公交行驶途径的站点 2、数据流 名称说明数据流来源数据流去向 用户
6、查询公交线路记录信息记录公交车线路查询信息线路 +站点查询结果输出 3、处理过程 名称简述输入的数据流处理输出的数据流 线路查询根据公交线路查询该线路 上的所有站点 公交车编号根据编号查询查询出该线路上的所 有公交车站点 站点查询根据站点查询出经过该站 点的所有公交车编号 站点名称根据站点查询公 交车的编号 路过该站点的所有公 交车编号 站站查询根据两个站点查询出所有 线路 两个不同的站点根据站点查询出 所有线路 输出查询出的线路 三、数据库概念结构设计 根据需求分析,可知本系统有以下E-R 图: 1、公交站点E-R 图 3、公交公司E-R 图 2、公交车 E-R 图 4、公交线路类型E-R
7、图 5、合并 E-R 图 站点 编号站点名称 公交线路 编号 首班时间末班时间路线长度 所属公 司 id 票价 线路类 型 id 公交公司 编号公司名称 公交线路 类型 编号类型名称 公交线 路 站点 站点 顺序 公交公司 公交线路 类型 属于 1 m 属于 n 1 线路_ 站点 m n 四、数据库逻辑结构设计 4.1 关系表设计 根据 ER模型,对本系统设计出5 个关系表: 1、公交车表 bus not null primary key 公交车的名称 start_time time not null 最早发车时间 end_time time not null 收班时间 buslength1
8、int not null 去程的站点数 buslength2 int not null 回程的站点数 pt_price float null 普通车的票价 disprice_pt float null 普通车刷卡 gd_price float null 高等级车的票价 disprice_gd float null 高等级车刷卡 companyID int not null foreignkeyreferencescompany(id , typeIDint not null Foreignkeyreferencesbus_type ( id 2、公交站点station not null 站点的
9、名称 3、线路与站点关联表bus_station not null primary key 参照 bus(name station_id int not null 参照 station(id orderid int not null 站点在一条线路中的位置 4、公交公司表company(id,name 列名数据类型NULL 约束说明 id int Not null primary key 公司编号 name Varchar(5 Not null 公司名称 5、公交线路类型表bus_type(id,name 列名数据类型NULL 约束说明 id int Not null primary key
10、线路类型编号,共 12 类 1 / 15 name Varchar(10 Not null 线路类型名 6、公交线路表busline(bus_name,direction,line 此表主要是为了方便依据线路来查询站点信息。 列名数据类型NULL 约束说明 bus_name varchar(4 Not null primary key 公司编号 direction varchar(4 Not null 公 交 行 驶 方 向 , “ 去 程 ” 或 “ 回 程” line varchar(500 Not null 公交行驶途径的站点 4.2 数据表关系图 五、创建数据库及其对象 5.1 建数据
11、库和表 下面是创建数据库和表的过程,数据通过手动输入。 1、创建数据库 createdatabasebus on ( name =bus_data1, filename =桌面 busbus_data1.mdf log on ( name =bus_log, filename =桌面 busbus_log.ldf 2、创建表 公交公司表 createtablecompany ( id intprimarykeynotnull, name varchar ( 30notnull 公交线路类型表 createtablebus_type ( id intprimarykeynotnull, name
12、 varchar ( 5notnull 2 / 15 公交站点 createtablestation ( id intprimarykeynotnull, name varchar ( 15notnull 公交线路表 createtablebusline ( bus_name varchar ( 5, directionchar ( 2notnull, line varchar ( 200notnull, primarykey (bus_name , direction, foreignkey(bus_name referencesbus( name 公交车表 createtablebus (
13、 name varchar ( 5primarykey notnull, start_timedatetime notnull, end_time datetime notnull, buslength int notnull, price floatnotnull, companyIDint notnull, typeID int notnull, foreignkey( companyIDreferencescompany ( id , foreignkey( typeID referencesbus_type ( id 线路与站点关联表 createtablebus_station (
14、bus_name varchar ( 5, station_idint , orderid int notnull, primarykey (bus_name , station_id, foreignkey(bus_name referencesbus( name , foreignkey(station_idreferencesstation(id 5.2 查询实现 这里只介绍线路查询和站站查询的存储过程实现,其它涉及到的功能通过SQLCommand或SqlDataAdapter 实 现,在后面的应用程序设计中实现。 1、线路具体情况查询: if exists(select name fr
15、om sysobjectswherename =busline_info dropprocedure busline_info go createprocedurebusline_infoinputvarchar ( 5, outputvarchar ( 700output as begin select output=line from busline wherebusline . bus_name =input end go 2、站点间的点到点路线查询: if exists(select name from sysobjectswherename =station_station drop
16、procedure station_station go createprocedurestation_stationinput1varchar ( 30, input2varchar ( 30, output1varchar ( 5output , output2varchar ( 5output , output3varchar ( 5output , output4varchar ( 30output , output5varchar ( 30output as begin declare stationID1 int , stationID2 int - 换乘过程中的中间站点 decl
17、are id1int , id2int - 记录起点和终点的ID select id1=id from stationwherename =input1 select id2=id from stationwherename =input2 3 / 15 - 查找直达线路 select output1=a. bus_name from ( select bus_name from bus_stationwherestation_id=id1a, ( select bus_name from bus_stationwherestation_id=id2b wherea. bus_name =b.
18、 bus_name - 若不存在直达线路, 则搜寻一次换乘路线 if notexists(select * from buswherename =output1 begin - 查找中间站点 select stationID1 =c. station_idfrom -input1 能直达的站点集合c ( selectdistinctstation_id from bus_station wherebus_name in( select bus_name from bus_stationwherestation_id=id1c, -input2 能直达的站点集合d ( selectdistinc
19、tstation_id from bus_station wherebus_name in( select bus_name from bus_stationwherestation_id=id2d wherec. station_id=d. station_id select output1=a. bus_name from ( select bus_name from bus_stationwherestation_id=id1a, ( select bus_name from bus_stationwherebus_station. station_id=stationID1 b whe
20、rea. bus_name =b. bus_name select output2=a. bus_name from ( select bus_name from bus_stationwherestation_id=id2a,( select bus_name from bus_stationwherebus_ station. station_id=stationID1 b wherea. bus_name =b. bus_name end - 若不存在直达和一次换乘线路, 则搜寻二次换乘路线 if notexists(select * from buswherename =output1
21、andnotexists(select *from buswherename =output2 begin - 查找中间线路 select output2=a. bus_name from ( selectdistinctbus_name from bus_station wherestation_idin ( select station_idfrom bus_station wherebus_name in 4 / 15 ( select bus_name from bus_stationwherestation_id=id1a, ( selectdistinctbus_name from
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 公交查询 系统 数据库 课程设计 分析 方案
链接地址:https://www.31doc.com/p-4664870.html