




已阅读5页,还剩12页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
公交查询系统数据库课程设计分析方案 导读:数据库课程设计报告班级:序号: 姓名:地球科学学院地信系 2018-06-28目录数据库课程设计 1 目录 2 一、概述 3 1.1 背景说明 3 1.2 开发环境 3 二、需求分析 3 2.1 用户需求 3 2.2 主要功能 3 2.3 清华大学数据库课程设计c# sql网上教学系统数据库课程设计报告班级:序号: 姓名:地球科学学院地信系 2018-06-28目录数据库课程设计 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 线路查询 77.3 站站查询 8 八、实验数据示例 10 九、心得 11一、概述 1.1 背景说明软件名称:公交线路查询系统 工程提出者: 工程开发者: 用户:广大需要乘坐公交车的人群 1.2 开发环境操作系统:Windows XP 软件配置:visual stutio2018,Microsoft SQLServer 2008 R2 数据库配置:Microsoft SQL Server 2008 R2 在 PC 机中新建 数据库,建立各个数据表、关系图。 二、需求分析 2.1 用户需求 城市的扩张使得公交线路越来越复杂,为了使得用户更加方便地 能够获得最新公交线路,“公交线路查询工具”帮助人们解决这个 问题。 本系统面向的对象是普通乘客,对于普通乘客来说,他们最关 心的就是查询。系统也只对用户提供信息查询功能,并不对用户开 放对数据的编辑权限。对于任何用户,只要浏览本系统的首页,就 可以根据自己的需求进行查询。数据的修改、删除、及时更新工作 只能由管理人员实现并对系统进行定期的维护,保证其运行的稳定 性。 2.2 主要功能 本系统从用户的需求出发,可实现以下功能: 1、线路具体情况查询:输入线路名称就可得到该线路的途经站点, 发车和末班车时间,票价等相关信息。 2、经过此站点的所有路线查询:输入站点名称即可得出经过该站点 的所有线路名称。3、站点间的点到点路线查询:输入出发站点和目的站点即可输出可选择的线路,包括中间站的转乘。2.3 数据流图公交车编号按线路查询站点信息数据选择查询类型2.4 数据字典判断类型起目 始的 点点站点名线路信息数据 按站点查询反馈给用户按起始、目的 站点查询乘车方案1、数据项名称name start_timeend_time buslength1 buslength2pt_price gd_price disprice_pt disprice_gd companyID company_name station_id station_nameorderid typeID type_name direction数据类型varchar timetime int int float float float float int varchar int varchar int int varchar charline varchar名称长度 5 8 8 2 2 3 3 3 3 1 30 3 30 2 2 5 4500字段描述公交车的名称 公交车每天的最早发车时间公交车每天的收班时间 公交线路去程的站点数 公交线路回程的站点数普通车的票价 高等级车的票价 普通车刷卡后的价格 高等级车刷卡后的价格公司编号 公司名称 站点的编号 站点的名称 站点在一条线路中的位置 线路类型编号,共 12 类 线路类型名 公交行驶方向,“去程”或 “回程” 公交行驶途径的站点2、数据流说明数据流来源 数据流去向用户查询公交线路记 记录公交车线路查 线路+站点 查询结果输录信息询信息出3、处理过程名称线路查 询站点查 询站站查 询简述根据公交线路查 询该线路上的所有站点 根据站点查询出 经过该站点的所有公交车编号 根据两个站点查询出所有线路输入的数据 流公交车编号站点名称两个不同的 站点处理 输出的数据流根据编号 查询根据站点 查询公交 车的编号 根据站点 查询出所有线路查询出该线路 上的所有公交车站点 路过该站点的 所有公交车编号 输出查询出的线路三、数据库概念结构设计根据需求分析,可知本系统有以下 E-R 图:1、公交站点 E-R 图站点3、公交公司 E-R 图 公交公司编号站点名称2、公交车 E-R 图编号票价公交线路首班时间 末班时间路线长度所属公 司id线路类 型id编号公司名称4、公交线路类型 E-R 图公交线路 类型编号类型名称5、合并 E-R 图公交公司1属于m公交线m路n属于1公交线路 类型线路_站点n站点 顺序站点四、数据库逻辑结构设计4.1 关系表设计根据 ER 模型,对本系统设计出 5 个关系表: 1、公交车表bus null公交车的名 称start_ti time me end_time timenot null not null最早发车时 间 收班时间buslengt int h1not null去程的站点 数buslengt int h2not null回程的站点 数pt_price float null disprice float null普通车的票 价 普通车刷卡_pt gd_price float null高等级车的 票价disprice float null _gd高等级车刷 卡companyI int Dnot foreignkeyreferencesc null ompany(id,typeID int not Foreignkeyreferencesbnull us_type(id2、公交站点 stationnot null站点的名称3 、 线 路 与 站 点 关 联 表 bus_station列名数据类型 NULL 约束说明bus_name varchar( not5nullstation_i intnotprimary key参照 bus(name 参照 station(iddnullorderid intnot站点在一条线路中null的位置4、公交公司表 company(id,name列名数据类型 NULL约束说明idintNot null primary公司编号keynameVarchar(5 Not null公司名称5、公交线路类型表 bus_type(id,name列名数据类型 NULL约束说明idintNot null primary线路类型编key号 , 共 12类nameVarchar(10 Not null线路类型名6、公交线路表 busline(bus_name,direction,line此表主要是为了方便依据线路来查询站点信息。列名 bus_namedirectionline数据类型 varchar(4varchar(4varchar(50 0NULL Not null Not null Not null4.2 数据表关系图约束 primary key说明 公司编号公交行驶方向,“去 程”或“回程” 公交行驶途径的站点五、创建数据库及其对象 5.1 建数据库和表 下面是创建数据库和表的过程,数据通过手动输入。 1、创建数据库 createdatabasebus on ( name=bus_data1, filename=C:Documents and SettingsAdministrator桌面 busbus_data1.mdflogon(name=bus_log,filename=C:Documents and SettingsAdministrator桌面busbus_log.ldf2、创建表公交公司表公交线路类型表createtablecompany ( idintprimarykeynotnull, namevarchar(30notnull createtablebus_type ( idintprimarykeynotnull, namevarchar(5notnull 公交站点公交线路表createtablestation ( idintprimarykeynotnull, namevarchar(15notnull 公交车表createtablebusline (bus_namevarchar(5, directionchar(2notnull, linevarchar(200notnull, primarykey(bus_name,direction , foreignkey(bus_namereference sbus(name 线路与站点关联表createtablebuscreatetablebus_station(namevarchar(5primarykeynotn (ull,bus_namevarchar(5,start_timedatetimenotnull, station_idint,end_timedatetimenotnull,orderidintnotnull,buslengthintnotnull,primarykey(bus_name,station_ipricefloatnotnull,d,companyIDintnotnull,foreignkey(bus_namereferencetypeIDintnotnull,sbus(name,foreignkey(companyIDreferenc foreignkey(station_idreferenescompany(id,cesstation(idforeignkey(typeIDreferencesb us_type(id5.2 查询实现这里只介绍线路查询和站站查询的存储过程实现,其它涉及到的功 能通过SQLCommand或SqlDataAdapter实现,在后面的应用程序设计 中实现。 1、线路具体情况查询: ifexists(selectnamefromsysobjectswherename=busline_info dropprocedurebusline_info go createprocedurebusline_infoinputvarchar(5,outputvarchar( 700output as begin selectoutput=line frombusline wherebusline.bus_name=input end go 2、站点间的点到点路线查询:ifexists(selectnamefromsysobjectswherename=station_station dropprocedurestation_station go createprocedurestation_stationinput1varchar(30,input2var char(30,output1varchar(5output,output2varchar(5output, output3varchar(5output,output4varchar(30output,output5 varchar(30output as begin declarestationID1int,stationID2int-换乘过程中的中间站点 declareid1int,id2int-记录起点和终点的IDselectid1=idfromstationwherename=input1 selectid2=idfromstationwherename=input2 -查找直达线路 selectoutput1=a.bus_name from (selectbus_namefrombus_stationwherestation_id=id1a, (selectbus_namefrombus_stationwherestation_id=id2b wherea.bus_name=b.bus_name -若不存在直达线路,则搜寻一次换乘路线 ifnotexists(select*frombuswherename=output1begin -查找中间站点 selectstationID1=c.station_idfrom -input1能直达的站点集合c (selectdistinctstation_id frombus_station wherebus_namein(selectbus_namefrombus_stationwherestation_id=id1c, -input2能直达的站点集合d (selectdistinctstation_id frombus_station wherebus_namein(selectbus_namefrombus_stationwherestation_id=id2d wherec.station_id=d.station_idselectoutput1=a.bus_name from (selectbus_namefrombus_stationwherestation_id=id1a, (selectbus_namefrombus_stationwherebus_station.station_id=stationID1b wherea.bus_name=b.bus_nameselectoutput2=a.bus_namefrom (selectbus_namefrombus_stationwherestation_id=id2a,(selec tbus_namefrombus_stationwherebus_station.station_id=statio nID1b wherea.bus_name=b.bus_name end -若不存在直达和一次换乘线路,则搜寻二次换乘路线 ifnotexists(select*frombuswherename=output1andnotexists(select*frombuswherename=output2 begin -查找中间线路 selectoutput2=a.bus_name from (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_n amefrombus_stationwherestation_id=id2bwherea.bus_name=b.bus_name -查找起点到中间线路的公交车 selectstationID1=a.station_id from (selectdistinctstation_idfrombus_stationwherebus_namein(selectbus_namefrombus_stationwherestation_id=id1a, (selectstation_idfrombus_stationwherebus_name=output2b wherea.station_id=b.station_id selectoutput1=c.bus_name from (selectbus_namefrombus_stationwherestation_id=id1c, (selectbus_namefrombus_stationwherestation_id=stationID1d wherec.bus_name=d.bus_name -查找中间线路到终点的公交车 selectstationID2=a.station_id from (selectdistinctstation_idfrombus_stationwherebus_namein(selectbus_namefrombus_stationwherestation_id=id2a, (selectstation_idfrombus_stationwherebus_name=output2b wherea.station_id=b.station_idselectoutput3=c.bus_name from (selectbus_namefrombus_stationwherestation_id=id2c, (selectbus_namefrombus_stationwherestation_id=stationID2d wherec.bus_name=d.bus_name end selectoutput4=namefromstationwhereid=stationID1 selectoutput5=namefromstationwhereid=stationID2 end 五、软件功能设计 软件共实现了 3 个大功能,即站点查询、线路查询、站站查询,其 完成情况如下: 如果没有结果,则提示:找不到此站点! 六、界面设计七、应用程序 7.1 站点查询 /查询经过给定站点的公交线路protectedvoid station_info(string input SqlConnection myConnection = newSqlConnection(connectionString。myConnection.Open(。SqlCommand cmd = newSqlCommand(“select bus_station.bus_name as 公?交?线?路名?,busline.direction as 方?向,line as 途?径?站?点? from bus_station,station,busline where = “ + input + “and dbo.station.id = bus_station.station_id and bus_station.bus_name = busline.bus_name”, myConnection。 SqlDataAdapter da = newSqlDataAdapter(。da.SelectCommand = cmd。 System.Data.DataSet ds = new System.Data.DataSet(。 da.Fill(ds。 this.GridView1.DataSource = ds.Tables0。 GridView1.DataBind(。 cmd = null。 myConnection.Close(。 7.2 线路查询 / 查询给定线路的公交车所经过站点protectedstring busline_info1(string input string connectionString = ”server=TXJM1FW3L1GYIC6。database = bus。Integrated Security = true”。 SqlConnection myConnection = newSqlConnection(connectionString。myConnection.Open(。 SqlCommand myCommand = newSqlCommand(“busline_info”, myConnection。myCommand.CommandType = System.Data.CommandType.StoredProcedure。 /创建参数 SqlParameter bus_name = newSqlParameter(“input”, System.Data.SqlDbType.VarChar, 5。bus_name.Direction = System.Data.ParameterDirection.Input。bus_name.Value = input。 myCommand.Parameters.Add(bus_name。 /添加输出参数 SqlParameter Result1 = newSqlParameter(“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 站站查询/查询给定起点和终点的公交车线路 protectedvoid station_station(string input1, string input2 string connectionString = ”server=TXJM1FW3L1GYIC6。 database = bus。Integrated Security = true”。 SqlConnection myConnection = newSqlConnection(connectionString。myConnection.Open(。 /利用SQL中已有的存储过程实现站站查询 SqlCommand myCommand = newSqlCommand(“station_station”, myConnection。myCommand.CommandType = System.Data.CommandType.StoredProcedure。/创建参数 SqlParameter station_name1 = newSqlParameter(“input1”, System.Data.SqlDbType.VarChar, 30。station_name1.Direction = System.Data.ParameterDirection.Input。station_name1.Value = input1。 myCommand.Parameters.Add(station_name1。SqlParameter station_name2 = newSqlParameter(“input2”, System.Data.SqlDbType.VarChar, 30。station_name2.Direction = System.Data.ParameterDirection.Input。station_name2.Value = input2。 myCommand.Parameters.Add(station_name2。 /添加输出参数 SqlParameter Result1 = newSqlParameter(“output1”, System.Data.SqlDbType.VarChar, 5。 Result1.Direction = System.Data.ParameterDirection.Output。 myCommand.Parameters.Add(Result1。SqlParameter Result2 = newSqlParameter(“output2”, System.Data.SqlDbType.VarChar, 5。Result2.Direction = System.Data.ParameterDirection.Output。myCommand.Parameters.Add(Result2。 SqlParameter Result3 = newSqlParameter(“output3”, System.Data.SqlDbType.VarChar, 5。Result3.Direction = System.Data.ParameterDirection.Output。myCommand.Parameters.Add(Result3。SqlParameter Result4 = newSqlParameter(“output4”, System.Data.SqlDbType.VarChar, 30。Result4.Direction = System.Data.ParameterDirection.Output。myCommand.Parameters.Add(Result4。SqlParameter Result5 = newSqlParameter(“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.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 = “您可以先乘坐 “ + str1 + “ 在 “ + str4+ “ 下车,” + “ 再乘坐 “ + str2。 lab5_nam
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 新能源商务车租赁创新创业项目商业计划书
- 建筑工程造价创新创业项目商业计划书
- 家政人员职业倦怠预防创新创业项目商业计划书
- 林业水资源合理利用创新创业项目商业计划书
- 2025年发酵酒精行业研究报告及未来行业发展趋势预测
- 2025年丙二醇甲醚乙酸酯行业研究报告及未来行业发展趋势预测
- 2025年地产绿化行业研究报告及未来行业发展趋势预测
- 2025年电动振筛机行业研究报告及未来行业发展趋势预测
- 2025年发泡餐具行业研究报告及未来行业发展趋势预测
- 2025年多格式转码器行业研究报告及未来行业发展趋势预测
- 外研版七年级上册初一英语全册课时练(一课一练)
- 蚯蚓养殖和治污改土技术规程 第1部分:蚯蚓养殖和粪污处理
- 成人鼻肠管的留置与维护(2021团体标准解读)-20221004172843
- 高考英语语法填空模拟题
- 借款利息确认书
- 熟识邮轮客舱房态讲解
- 汉字五行属性查询表
- 项目验收签收单
- 食品公司员工培训计划书
- 风湿性疾病的影像学表现
- 四川省建筑工程地下结构抗浮锚杆关键技术作业规程
评论
0/150
提交评论