公交查询系统数据库课程设计报告

上传人:沈*** 文档编号:90653165 上传时间:2022-05-15 格式:DOC 页数:15 大小:1.86MB
收藏 版权申诉 举报 下载
公交查询系统数据库课程设计报告_第1页
第1页 / 共15页
公交查询系统数据库课程设计报告_第2页
第2页 / 共15页
公交查询系统数据库课程设计报告_第3页
第3页 / 共15页
资源描述:

《公交查询系统数据库课程设计报告》由会员分享,可在线阅读,更多相关《公交查询系统数据库课程设计报告(15页珍藏版)》请在装配图网上搜索。

1、数据库课程设计报告 班级:序号: 姓名: 地球科学学院地信系2013-06-28目录数据库课程设计1目录2一、概述31.1背景说明31.2开发环境3二、需求分析32.1用户需求32.2主要功能32.3数据流图32.4数据字典3三、数据库概念结构设计4四、数据库逻辑结构设计24.1 关系表设计24.2 数据表关系图2五、创建数据库及其对象25.1 建数据库和表25.2 查询实现3五、软件功能设计5六、界面设计6七、应用程序67.1 站点查询67.2 线路查询77.3 站站查询8八、实验数据示例10九、心得11一、概述1.1背景说明软件名称:公交线路查询系统 项目提出者: 项目开发者: 用户:广大

2、需要乘坐公交车的人群 1.2开发环境操作系统:Windows XP软件配置:visual stutio2010,Microsoft SQL Server 2008 R2数据库配置:Microsoft SQL Server 2008 R2在PC机中新建数据库,建立各个数据表、关系图。二、需求分析2.1用户需求城市的扩张使得公交线路越来越复杂,为了使得用户更加方便地能够获得最新公交线路,“公交线路查询工具”帮助人们解决这个问题。本系统面向的对象是普通乘客,对于普通乘客来说,他们最关心的就是查询。系统也只对用户提供信息查询功能,并不对用户开放对数据的编辑权限。对于任何用户,只要浏览本系统的首页,就可

3、以根据自己的需求进行查询。数据的修改、删除、及时更新工作只能由管理人员实现并对系统进行定期的维护,保证其运行的稳定性。2.2主要功能本系统从用户的需求出发,可实现以下功能: 1、线路具体情况查询:输入线路名称就可得到该线路的途经站点,发车和末班车时间,票价等相关信息。2、经过此站点的所有路线查询:输入站点名称即可得出经过该站点的所有线路名称。3、站点间的点到点路线查询:输入出发站点和目的站点即可输出可选择的线路,包括中间站的转乘。2.3数据流图2.4数据字典1、数据项名称数据类型长度字段描述namevarchar5公交车的名称start_timetime8公交车每天的最早发车时间end_tim

4、etime8公交车每天的收班时间buslength1int2公交线路去程的站点数buslength2int2公交线路回程的站点数pt_pricefloat3普通车的票价gd_pricefloat3高等级车的票价disprice_ptfloat3普通车刷卡后的价格disprice_gdfloat3高等级车刷卡后的价格companyIDint1公司编号company_namevarchar30公司名称station_idint3站点的编号station_namevarchar30站点的名称orderidint2站点在一条线路中的位置typeIDint2线路类型编号,共12类type_namevar

5、char5线路类型名directionchar4公交行驶方向,“去程”或“回程”linevarchar500公交行驶途径的站点2、数据流名称说明数据流来源数据流去向用户查询公交线路记录信息记录公交车线路查询信息线路+站点查询结果输出3、处理过程名称简述输入的数据流处理输出的数据流线路查询根据公交线路查询该线路上的所有站点公交车编号根据编号查询查询出该线路上的所有公交车站点站点查询根据站点查询出经过该站点的所有公交车编号站点名称根据站点查询公交车的编号路过该站点的所有公交车编号站站查询根据两个站点查询出所有线路两个不同的站点根据站点查询出所有线路输出查询出的线路三、数据库概念结构设计根据需求分析

6、,可知本系统有以下E-R图:10 / 15文档可自由编辑打印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约束说明namevarchar(5)not nullprimary key公交车的名称start_timetimenot nul

7、l最早发车时间end_timetimenot null收班时间buslength1intnot null去程的站点数buslength2intnot null回程的站点数pt_pricefloatnull普通车的票价disprice_ptfloatnull普通车刷卡gd_pricefloatnull高等级车的票价disprice_gdfloatnull高等级车刷卡companyIDintnot nullforeign key references company(id),typeIDintnot nullForeignkey references bus_type(id)2、公交站点stati

8、on(id,name)列名数据类型NULL约束说明idintnot nullprimary key站点的编号namevarchar(30)not null站点的名称3、线路与站点关联表bus_station(bus_name,station_id,orderid)记录公交线路经过站点的信息,并且按顺序记录各站点,以此记录线路与站点的关联信息。列名数据类型NULL约束说明bus_namevarchar(5)not nullprimary key参照bus(name)station_idintnot null参照station(id)orderidintnot null站点在一条线路中的位置4、公

9、交公司表company(id,name)列名数据类型NULL约束说明idintNot nullprimary key公司编号nameVarchar(5)Not null公司名称5、公交线路类型表bus_type(id,name)列名数据类型NULL约束说明idintNot nullprimary key线路类型编号,共12类nameVarchar(10)Not null线路类型名6、公交线路表busline(bus_name,direction,line) 此表主要是为了方便依据线路来查询站点信息。 列名数据类型NULL约束说明bus_namevarchar(4)Not nullprimary

10、 key公司编号directionvarchar(4)Not null公交行驶方向,“去程”或“回程”linevarchar(500)Not null公交行驶途径的站点4.2 数据表关系图五、创建数据库及其对象5.1 建数据库和表下面是创建数据库和表的过程,数据通过手动输入。1、创建数据库create database buson(name = bus_data1, = C:Documents and SettingsAdministrator桌面busbus_data1.mdf)log on(name = bus_log, = C:Documents and SettingsAdminist

11、rator桌面busbus_log.ldf)2、创建表公交公司表create table company(id int primary key not null,name varchar(30) not null)公交线路类型表create table bus_type(id int primary key not null,name varchar(5) not null)公交站点create table station(id int primary key not null,name varchar(15) not null)公交线路表create table busline(bus_na

12、me varchar(5),direction char(2) not null,line varchar(200) not null,primary key(bus_name,direction), foreign key(bus_name) references bus(name)公交车表create table bus(name varchar(5) primary key not null,start_time datetime not null,end_time datetime not null,buslength int not null,price float not null

13、,companyID int not null,typeID int not null,foreign key(companyID) references company(id),foreign key(typeID) references bus_type(id)线路与站点关联表create table bus_station(bus_name varchar(5),station_id int,orderid int not null,primary key(bus_name,station_id), foreign key(bus_name) references bus(name),f

14、oreign key(station_id)references station(id)5.2 查询实现这里只介绍线路查询和站站查询的存储过程实现,其它涉及到的功能通过SQLCommand或SqlDataAdapter实现,在后面的应用程序设计中实现。1、线路具体情况查询:if exists(select name from sysobjects where name = busline_info)drop procedure busline_infogocreate procedure busline_info input varchar(5),output varchar(700) out

15、putasbegin select output = line from busline where busline.bus_name = input end go2、站点间的点到点路线查询:if exists(select name from sysobjects where name = station_station)drop procedure station_stationgocreate procedure station_station input1 varchar(30),input2 varchar(30), output1 varchar(5) output,output2

16、 varchar(5) output,output3 varchar(5) output,output4 varchar(30) output,output5 varchar(30) outputasbegin declare stationID1 int,stationID2 int -换乘过程中的中间站点 declare id1 int,id2 int -记录起点和终点的ID select id1 = id from station where name = input1 select id2 = id from station where name = input2 -查找直达线路 se

17、lect output1 = a.bus_name from (select bus_name from bus_station where station_id = id1 ) a, (select bus_name from bus_station where station_id = id2 ) b where a.bus_name = b.bus_name -若不存在直达线路,则搜寻一次换乘路线 if not exists(select * from bus where name = output1)begin-查找中间站点 select stationID1 = c.station_

18、id from-input1能直达的站点集合c( select distinct station_id from bus_station where bus_name in(select bus_name from bus_station where station_id = id1 ) c,-input2能直达的站点集合d( select distinct station_id from bus_station where bus_name in(select bus_name from bus_station where station_id = id2) dwhere c.station

19、_id= d.station_idselect output1 = a.bus_name from(select bus_name from bus_station where station_id = id1 ) a,(select bus_name from bus_station where bus_station.station_id = stationID1 ) bwhere a.bus_name = b.bus_nameselect output2 = a.bus_name from(select bus_name from bus_station where station_id

20、 = id2) a,(select bus_name from bus_station where bus_station.station_id = stationID1 ) bwhere a.bus_name = b.bus_nameend -若不存在直达和一次换乘线路,则搜寻二次换乘路线 if not exists(select * from bus where name = output1) and not exists(select * from bus where name = output2)begin-查找中间线路select output2 = a.bus_name from(

21、select distinct bus_name from bus_station where station_id in(select station_id from bus_station where bus_name in(select bus_name from bus_station where station_id = id1)a,(select distinct bus_name from bus_station where station_id in (select station_id from bus_station where bus_name in(select bus

22、_name from bus_station where station_id = id2)bwhere a.bus_name = b.bus_name-查找起点到中间线路的公交车select stationID1 = a.station_id from(select distinct station_id from bus_station where bus_name in(select bus_name from bus_station where station_id = id1)a,(select station_id from bus_station where bus_name =

23、 output2) bwhere a.station_id = b.station_idselect output1 = c.bus_name from(select bus_name from bus_station where station_id = id1 ) c, (select bus_name from bus_station where station_id = stationID1) d where c.bus_name = d.bus_name-查找中间线路到终点的公交车select stationID2 = a.station_id from(select distinc

24、t station_id from bus_station where bus_name in(select bus_name from bus_station where station_id = id2)a,(select station_id from bus_station where bus_name = output2) bwhere a.station_id = b.station_idselect output3 = c.bus_name from(select bus_name from bus_station where station_id = id2 ) c, (sel

25、ect bus_name from bus_station where station_id = stationID2) d where c.bus_name = d.bus_nameendselect output4 = name from station where id = stationID1select output5 = name from station where id = stationID2end 五、软件功能设计软件共实现了3个大功能,即站点查询、线路查询、站站查询,其完成情况如下:(一):检查用户是否输入了站点或线路信息,如果没有录入,则提示:请输入站点!或请输入线路名

26、!(二):检查用户是否输入的站点或线路是否存在,如果不存在,则提示:此站点不存在!或此线路不存在!(三):如果信息都填写正确,则根据选定的查询条件进行查找,查找的具体实现为:(1)站点查询:返回经过此站点的所有线路,并提供一条线路经过的所有站点。如果没有结果,则提示:找不到此站点!(2)线路查询:返回此线路的类型、最早和最晚时间、票价、经过站点等信息。(3)站站查询:返回从起点到终点的可行的一条线路,此线路可直达,如果没有直达,则最多换乘两次,并提示在哪里下车换乘,以及所有车辆的站点信息。六、界面设计七、应用程序7.1 站点查询/查询经过给定站点的公交线路 protected void sta

27、tion_info(string input) SqlConnection myConnection = new SqlConnection(connectionString); myConnection.Open(); SqlCommand cmd = new SqlCommand(select bus_station.bus_name as 公?交?线?路名?,busline.direction as 方?向,line as 途?径?站?点? from bus_station,station,busline wher = + input + and dbo.station.id = bus

28、_station.station_id and bus_station.bus_name = busline.bus_name, myConnection); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; System.Data.DataSet ds = new System.Data.DataSet(); da.Fill(ds); this.GridView1.DataSource = ds.Tables0; GridView1.DataBind(); cmd = null; myConnection.Cl

29、ose(); 7.2 线路查询/ 查询给定线路的公交车所经过站点 protected string busline_info1(string input) string connectionString = server=TXJM1FW3L1GYIC6;database = bus;Integrated Security = true; SqlConnection myConnection = new SqlConnection(connectionString); myConnection.Open(); SqlCommand myCommand = new SqlCommand(busli

30、ne_info, myConnection); mandType = System.Data.CommandType.StoredProcedure; /创建参数 SqlParameter bus_name = new SqlParameter(input, System.Data.SqlDbType.VarChar, 5); bus_name.Direction = System.Data.ParameterDirection.Input; bus_name.Value = input; myCommand.Parameters.Add(bus_name); /添加输出参数 SqlParam

31、eter Result1 = new SqlParameter(output, System.Data.SqlDbType.VarChar, 700); Result1.Direction = System.Data.ParameterDirection.Output; myCommand.Parameters.Add(Result1); myCommand.ExecuteNonQuery(); string str = Result1.Value.ToString(); return str; 7.3 站站查询/查询给定起点和终点的公交车线路 protected void station_s

32、tation(string input1, string input2) string connectionString = server=TXJM1FW3L1GYIC6;database = bus;Integrated Security = true; SqlConnection myConnection = new SqlConnection(connectionString); myConnection.Open(); /利用SQL中已有的存储过程实现站站查询 SqlCommand myCommand = new SqlCommand(station_station, myConnec

33、tion); mandType = System.Data.CommandType.StoredProcedure;/创建参数 SqlParameter station_name1 = new SqlParameter(input1, System.Data.SqlDbType.VarChar, 30); station_name1.Direction = System.Data.ParameterDirection.Input; station_name1.Value = input1; myCommand.Parameters.Add(station_name1); SqlParamete

34、r station_name2 = new SqlParameter(input2, System.Data.SqlDbType.VarChar, 30); station_name2.Direction = System.Data.ParameterDirection.Input; station_name2.Value = input2; myCommand.Parameters.Add(station_name2); /添加输出参数 SqlParameter Result1 = new SqlParameter(output1, System.Data.SqlDbType.VarChar

35、, 5); Result1.Direction = System.Data.ParameterDirection.Output; myCommand.Parameters.Add(Result1); SqlParameter Result2 = new SqlParameter(output2, System.Data.SqlDbType.VarChar, 5); Result2.Direction = System.Data.ParameterDirection.Output; myCommand.Parameters.Add(Result2); SqlParameter Result3 =

36、 new SqlParameter(output3, System.Data.SqlDbType.VarChar, 5); Result3.Direction = System.Data.ParameterDirection.Output; myCommand.Parameters.Add(Result3); SqlParameter Result4 = new SqlParameter(output4, System.Data.SqlDbType.VarChar, 30); Result4.Direction = System.Data.ParameterDirection.Output;

37、myCommand.Parameters.Add(Result4); SqlParameter Result5 = new SqlParameter(output5, System.Data.SqlDbType.VarChar, 30); Result5.Direction = System.Data.ParameterDirection.Output; myCommand.Parameters.Add(Result5); myCommand.ExecuteNonQuery(); string str1, str2, str3, str4, str5; str1 = Result1.Value

38、.ToString(); str2 = Result2.Value.ToString(); str3 = Result3.Value.ToString(); str4 = Result4.Value.ToString(); str5 = Result5.Value.ToString(); myConnection.Close(); /界面提示信息 if (str1 = & str2 = & str3 = ) lab4_text.Text = 没有找到合适的路线; else if (str1 != & str2 != & str3 = ) lab4_text.Text = 您可以先乘坐 + st

39、r1 + 在 + str4 + 下车, + 再乘坐 + str2; lab5_name.Text = str1 + 公交线路:; lab5_line.Text = busline_info1(str1); lab6_name.Text = str2 + 公交线路:; lab6_line.Text = busline_info1(str2); else if (str1 != & str2 = & str3 = ) lab4_text.Text = 您可以直接乘坐 + str1; lab5_name.Text = str1 + 公交线路:; lab5_line.Text = busline_in

40、fo1(str1); else if (str1 != & str2 != & str3 != ) lab4_text.Text = 您可以先乘坐 + str1 + 在 + str4 + 下车, + 再乘坐 + str2 + 在 + str5 + 下车, + 最后再转乘 + str3 + 即可; lab5_name.Text = str1 + 公交线路:; lab5_line.Text = busline_info1(str1); lab6_name.Text = str2 + 公交线路:; lab6_line.Text = busline_info1(str2); lab7_name.Tex

41、t = str3 + 公交线路:; lab7_line.Text = busline_info1(str3); 八、实验数据示例1、bus表(存放公交车次有关信息数据) 2、bus_type表(存放公交车类型数据) 3、bus_type表(存放公交公司数据) 4、bus_station表(存放公交线路上的各个站点) 5、station表(存放公交站点数据) 6、bus_line表(存放公交线路,便于站点查询) 九、心得通过这次为期2个星期的数据库的课程设计实习,我从中学习到了一个数据库程序的设计的基本步骤,包括需求分析、概念结构设计、逻辑结构设计、物理结构设计等,同时加强了关系型数据库管理方面

42、的部分知识。我觉得需求分析是很重要的,只有需求分析做好了,后面的工作才会轻松。逻辑结构设计也很关键,需要考虑实体所应包含的所有属性,如果这个阶段不考虑清楚,等到后面才想起来的话,修改起来会比较麻烦。 在整个程序的设计时,我通过分析学习到了一个数据库程序应该考虑的方面,了解到关系型数据库关系处理方便的灵活性。同时在数据设计的过程中,让我知道了数据设计的重要性,在一定的选择判断中,设计出了数据库的整体结构。 通过在编程中嵌入SQL 语句访问数据库,处理返回数据,以及调用SQL中已经编写好的存储过程的过程中,巩固学习了SQL 语句的语法,也学会了在C#、ASP等编程语言中通过不同的方法使用数据库,自己收获还是很多的。不足之处就在于,可能由于编程能力的原因,在如何让程序数据变得动态、多样这个方面还有待提高,程序的编写也应该更简洁一些才好。 这次实习给了我宝贵的机会,以充足的时间去编写一个基于数据库的小程序,让我对数据库和编写程序方面都得到了提高。

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!