公交查詢系統(tǒng)-數(shù)據(jù)庫課程設(shè)計報告_第1頁
公交查詢系統(tǒng)-數(shù)據(jù)庫課程設(shè)計報告_第2頁
公交查詢系統(tǒng)-數(shù)據(jù)庫課程設(shè)計報告_第3頁
公交查詢系統(tǒng)-數(shù)據(jù)庫課程設(shè)計報告_第4頁
公交查詢系統(tǒng)-數(shù)據(jù)庫課程設(shè)計報告_第5頁
已閱讀5頁,還剩13頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、數(shù)據(jù)庫課程設(shè)計報告班級:序號:姓名:地球科學學院地信系2013-06-28 目錄 TOC o 1-5 h z HYPERLINK l bookmark0 o Current Document 數(shù)據(jù)庫課程設(shè)計 1目錄 2 HYPERLINK l bookmark4 o Current Document 一、概述 3 HYPERLINK l bookmark6 o Current Document 背景說明 3 HYPERLINK l bookmark8 o Current Document 開發(fā)環(huán)境 3 HYPERLINK l bookmark10 o Current Document 二、需求

2、分析 3 HYPERLINK l bookmark12 o Current Document 用戶需求 3 HYPERLINK l bookmark14 o Current Document 主要功能 3數(shù)據(jù)流圖 3數(shù)據(jù)字典 3 HYPERLINK l bookmark16 o Current Document 三、數(shù)據(jù)庫概念結(jié)構(gòu)設(shè)計 4 HYPERLINK l bookmark18 o Current Document 四、數(shù)據(jù)庫邏輯結(jié)構(gòu)設(shè)計 2 HYPERLINK l bookmark20 o Current Document 關(guān)系表設(shè)計 2數(shù)據(jù)表關(guān)系圖 2 HYPERLINK l boo

3、kmark22 o Current Document 五、創(chuàng)建數(shù)據(jù)庫及其對象 2 HYPERLINK l bookmark24 o Current Document 5.1 建數(shù)據(jù)庫和表 2 HYPERLINK l bookmark26 o Current Document 查詢實現(xiàn) 3 HYPERLINK l bookmark28 o Current Document 五、軟件功能設(shè)計 5 HYPERLINK l bookmark30 o Current Document 六、界面設(shè)計 6 HYPERLINK l bookmark32 o Current Document 七、應(yīng)用程序 6

4、HYPERLINK l bookmark34 o Current Document 7.1 站點查詢 6線路查詢 7 HYPERLINK l bookmark36 o Current Document 站站查詢 8 HYPERLINK l bookmark38 o Current Document 八、實驗數(shù)據(jù)示例 10 HYPERLINK l bookmark40 o Current Document 九、心得 11、概述1.1背景說明軟件名稱:公交線路查詢系統(tǒng)項目提岀者:項目開發(fā)者:用戶:廣大需要乘坐公交車的人群1.2開發(fā)環(huán)境操作系統(tǒng):Windows XP軟件配置:visual stuti

5、o2010 , Microsoft SQL Server 2008 R2數(shù)據(jù)庫配置:Microsoft SQL Server 2008 R2 在PC機中新建數(shù)據(jù)庫,建立各個數(shù)據(jù)表、關(guān)系圖二、需求分析2.1用戶需求城市的擴張使得公交線路越來越復(fù)雜,為了使得用戶更加方便地能夠獲得最新公交線路,“公交線路 查詢工具”幫助人們解決這個問題。本系統(tǒng)面向的對象是普通乘客,對于普通乘客來說,他們最關(guān)心的就是查詢。系統(tǒng)也只對用戶提供信 息查詢功能,并不對用戶開放對數(shù)據(jù)的編輯權(quán)限。對于任何用戶,只要瀏覽本系統(tǒng)的首頁,就可以根據(jù)自 己的需求進行查詢。數(shù)據(jù)的修改、刪除、及時更新工作只能由管理人員實現(xiàn)并對系統(tǒng)進行定期

6、的維護,保 證其運行的穩(wěn)定性。2.2主要功能本系統(tǒng)從用戶的需求岀發(fā),可實現(xiàn)以下功能:1、線路具體情況查詢:輸入線路名稱就可得到該線路的途經(jīng)站點,發(fā)車和末班車時間,票價等相關(guān)信息2、經(jīng)過此站點的所有路線查詢:輸入站點名稱即可得岀經(jīng)過該站點的所有線路名稱。3、站點間的點到點路線查詢:輸入岀發(fā)站點和目的站點即可輸岀可選擇的線路,包括中間站的轉(zhuǎn)乘。1、數(shù)據(jù)項名稱數(shù)據(jù)類型長度字段描述namevarchar5公交車的名稱start_timetime8公交車每天的最早發(fā)車時間end_timetime8公交車每天的收班時間buslengthlint2公交線路去程的站點數(shù)buslength2int2公交線路回程

7、的站點數(shù)pt_pricefloat3普通車的票價gd_pricefloat3高等級車的票價disprice_ptfloat3普通車刷卡后的價格disprice_gdfloat3高等級車刷卡后的價格companylDint1公司編號company_namevarchar30公司名稱station _idint3站點的編號station_namevarchar30站點的名稱orderidint2站點在一條線路中的位置typeIDint2線路類型編號,共12類type_namevarchar5線路類型名directionchar4公交行駛方向,“去程”或“回程”linevarchar500公交行駛途

8、徑的站點2、數(shù)據(jù)流名稱說明數(shù)據(jù)流來源數(shù)據(jù)流去向用戶查詢公交線路記錄信息記錄公交車線路查詢信息線路+站點查詢結(jié)果輸岀3、處理過程名稱簡述輸入的數(shù)據(jù)流處理輸岀的數(shù)據(jù)流線路查詢根據(jù)公交線路查詢該線路 上的所有站點公交車編號根據(jù)編號查詢查詢岀該線路上的所有公交車站點站點查詢根據(jù)站點查詢出經(jīng)過該站點的所有公交車編號站點名稱根據(jù)站點查詢公交車的編號路過該站點的所有公 交車編號站站查詢根據(jù)兩個站點查詢岀所有線路兩個不同的站點根據(jù)站點查詢岀 所有線路輸岀查詢岀的線路三、數(shù)據(jù)庫概念結(jié)構(gòu)設(shè)計根據(jù)需求分析,可知本系統(tǒng)有以下E-R圖:、公交公司E-R圖1、公交站點E-R圖3公交公司|編號站點站點名稱2、公交車E-R圖

9、4編號首班時間票價編號、公交線路類型編號E-R圖公交線路類型公司名稱U類型名稱25、合并E-R圖公交公司i站點公交線路類型四、數(shù)據(jù)庫邏輯結(jié)構(gòu)設(shè)計4.1關(guān)系表設(shè)計根據(jù)ER模型,對本系統(tǒng)設(shè)計岀5個關(guān)系表:1、公交車表bus (name, start_time , end_time , buslengthl , buslength2 , pt_price , dis_price , gd_price ,company_id,type_id )數(shù)據(jù)類型NULLnamevarchar(5)not nullprimary key公交車的名稱start_timetimenot null最早發(fā)車時間end_t

10、imetimenot null收班時間buslength1intnot null去程的站點數(shù)buslength2intnot null回程的站點數(shù)pt_pricefloatnull普通車的票價disprice_ptfloatnull普通車刷卡gd_pricefloatnull高等級車的票價disprice_gdfloatnull高等級車刷卡companyIDintnot nullforeign key references company id ),typeIDintnot nullForeignkey references bus_type (id )2、公交站點 station (id ,

11、 nam列名數(shù)據(jù)類型NULL約束說明idintnot nullprimary key站點的編號namevarchar(30)not null站點的名稱3、線路與站點關(guān)聯(lián)表記錄公交線路纟號 bus_station(bus_name, station_id , orderid )仝過站點的信息,并且按順序記錄各站點,以此記錄線路與站點的關(guān)聯(lián)信息。列名數(shù)據(jù)類型NULL約束說明bus_namevarchar(5)not nullprimary key參照 bus(name)station _idintnot null參照 station(id)orderidintnot null站點在一條線路中的位置

12、4、公交公司表 company(id,name)列名數(shù)據(jù)類型NULL約束說明idintNot nullprimary key公司編號nameVarchar(5)Not null公司名稱5、公交線路類型表 bus type(idpme)列名數(shù)據(jù)類型NULL約束說明primary keyidintNot null線路類型編號,共12類nameVarchar(10)Not null線路類型名6、公交線路表 busline(bus_name,direction,line)此表主要是為了方便依據(jù)線路來查詢站點信息列名數(shù)據(jù)類型NULL約束說明bus_namevarchar(4)Not nullprimar

13、y key公司編號directionvarchar(4)Not null公交行駛方向,“去程”或“回程”linevarchar(500)Not null公交行駛途徑的站點4.2數(shù)據(jù)表關(guān)系圖五、創(chuàng)建數(shù)據(jù)庫及其對象5.1建數(shù)據(jù)庫和表下面是創(chuàng)建數(shù)據(jù)庫和表的過程,數(shù)據(jù)通過手動輸入1、創(chuàng)建數(shù)據(jù)庫create database buson(name = bus_data1,filename =)log on(name = bus_log,filename =)2、創(chuàng)建表公交公司表create table company(id int primary key not null, name varchar (

14、30) not null桌面 busbus_data1.mdf桌面 busbus_log.ldf公交線路類型表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 bus(name varchar (5) primary key not null, start_time datetime not nul

15、l, end_time datetime not null, buslength int not null, price float not null, companyID int not null, typeID int not null, foreign key(companyID) references company(id), foreign key( typeID ) references bus_type (id )公交線路表create table busline (bus_name varchar (5), direction char (2) not null, line v

16、archar (200) not null,primarykey( bus_name direction ),foreignkey( bus_name)referen cesbus( name)線路與站點關(guān)聯(lián)表createtable bus_stationVbus_name varchar (5),station_id int ,orderidint not null,primarykey( bus_name station_id ),foreignkey( bus_name)referen cesbus( name.foreignkey (station_id)referencesstati

17、on (id )5.2查詢實現(xiàn)這里只介紹線路查詢和站站查詢的存儲過程實現(xiàn),其它涉及到的功能通過SQLComma或SqlDataAdapter實現(xiàn),在后面的應(yīng)用程序設(shè)計中實現(xiàn)。1、線路具體情況查詢:if exists( select name from sysobjects where name = busline_info )drop procedure busline_infogocreate procedure busline_info input varchar (5), output varchar (700) outputasbeginselect output = linefrom

18、 buslinewhere busline . bus_name = inputendgo2、站點間的點到點路線查詢: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 varchar (5) output , output3

19、 varchar (5) output , output4 varchar (30)output , output5 varchar (30) outputasbegindeclare stationID1 int , stationID2 int - 換乘過程中的中間站點declare id1 int , id2 int - 記錄起點和終點的 IDselect id1 = id from station where name = input1select id2 = id from station where name = input2- 查找直達線路select output1 = a.

20、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_id from-inp

21、ut1 能直達的站點集合 c( select distinct station_idfrom bus_stationwhere bus_name in( select bus_name from bus_station where station_id = id1 ) c, -input2 能直達的站點集合 d( select distinct station_idfrom bus_stationwhere bus_name in( select bus_name from bus_station where station_id = id2) d where c. station_id =

22、d. station_idselectoutput1 = a. bus_namefrom( selectbus_name from bus_stationwherestation_id= id1 ) a,( selectbus_name from bus_stationwherebus_station. station_id = stationID1 ) bwherea. bus_name = b. bus_nameselectoutput2 = a. bus_namefrom( selectbus_name from bus_stationwherestation_id= id2) a,(

23、select bus_name fromstationwhere 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_namefrom( select dist

24、inct bus_namefrom bus_stationwhere station_id in( select station_id from bus_stationwhere bus_name in( select bus_name from bus_station where station_id = id1) a,( select distinct bus_name from bus_stationwhere station_id in( select station_id from bus_station where bus_name in( select bus_name from

25、 bus_station where station_id = id2) bwhere a. bus_name = b. bus_name- 查找起點到中間線路的公交車select stationID1 = a. station_idfrom( select distinct station_id from bus_station where bus_name in( select bus_name from bus_station where station_id = id1) a,( selectstation_id from bus_stationwhere bus_name = out

26、put2) bwherea. station_id = b. station_idselectoutput1 = c. bus_namefrom( selectbus_name from bus_stationwherestation_id = id1 ) c,( selectbus_name from bus_stationwherestation_id = stationID1 ) dwhere c. bus_name = d. bus_name- 查找中間線路到終點的公交車select stationID2 = a. station_idfrom( select distinct sta

27、tion_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) b where a. station_id = b. station_idselect output3 = c. bus_namefrom( select bus_name from bus_station where station_id = id2 ) c,( s

28、elect 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 = stationID2 end五、軟件功能設(shè)計軟件共實現(xiàn)了 3 個大功能,即站點查詢、線路查詢、站站查詢,其完成情況如下:(一):檢查用戶是否輸入了站點或線路信息,如果沒有錄入,則提示:請輸入站點!

29、或請輸入線路名?。ǘ簷z查用戶是否輸入的站點或線路是否存在,如果不存在,則提示:此站點不存在!或此線路不存在!(三):如果信息都填寫正確,則根據(jù)選定的查詢條件進行查找,查找的具體實現(xiàn)為:(1)站點查詢:返回經(jīng)過此站點的所有線路,并提供一條線路經(jīng)過的所有站點。如果沒有結(jié)果,則提示:找不到此站點?。?)線路查詢:返回此線路的類型、最早和最晚時間、票價、經(jīng)過站點等信息。(3)站站查詢:返回從起點到終點的可行的一條線路,此線路可直達,如果沒有直達,則最多換乘兩次,并提示在哪里下車換乘,以及所有車輛的站點信息。六、界面設(shè)計七、應(yīng)用程序7.1站點查詢/查詢經(jīng)過給定站點的公交線路protected voi

30、d station_info( string input)SqlConnection myConnection = new SqlConnection (connectionstring);myConnection.Open();SqlCommanctmd = new SqlCommandselect bus_station.bus_name as公?交?線?路?O名?,busline.direction as方O ?向 ,line as途a?徑 ?站?點1 ? from bus_station,station,buslinewhere = + input + and dbo.station.

31、id = bus_station.stationd andbus_station.bus_name = busline.bus_name , myConnection);SqlDataAdapter da = new SqlDataAdapter ();da.SelectCommand = cmd;System.Data.DataSet ds = newSystem.Data. DataSet ();da.Fill(ds);this .GridViewl.DataSource = ds.TablesO;媳aftGridView1.DataBind(); cmd =null ;myConnect

32、ion.Close();kzm丸宣曲耐 粘 - 液陽丸 詛 十a(chǎn)l鈉 -尢jfir好呉?r ;淫贋13丸iirnr時越 :涅戸白丸lit水安堂 -;銀$日尢扯丟亦4一 5!FH-ig- :i:EBHI未l=JHPWt :說任曰怎誼也孔舌斗呆坯 一 殛貯日大道 快酒坤 一 富戸日天這3&11.工廠 一 451上日夭S.址備天-決陽大避酊4弓工廠-滾陽大遇JW制-滾PETKJa:襪洛- PHZiitWFff -識陽夫遒新衣-識陽亦道么笊 魅 - 汶陽土道宿felTilj - 汶|5日尢 道虹光 汶陽尢1K16MBDL堀 - 汶陽大MHm大曲口 - ?w大nt - 菸尢1斷- *RH客逞申*竹伍時毋

33、:毎丈th客謹中心 - 尊毎丈也 - 和麗丈:逍 - 漢陽丈址iff毎丈:i$Ef 汶陽天逍期板嚴埼 - 漢陽丈:進虹光 - 汶?yún)? 尢逖姚*山 - 注陽天itt么鈉 - 溟陽走遨鏑衣 - 液陽走HI憾陵 - 涼蹲大遺主黑鈉 - 液陽大jJE廉河汶岷尢謐:的嗎五昭需工廠一:盤頤K近剤f夭一57酣尢砸:J5:51:L工L 一宣頤尢誼“典宇舌片一:.立頤K*4長活嶺芙坯一汶PHK握竺HIH橋$V PH ra H.d捷*根旳-滾陽夫遛盂-僅陽夫垃水孜堂-段陽丸血帀陽粒-僅陽大蚯紆興專-漢陽大專原謚 江陽丸運十巫洛渝田尢運應(yīng)啲路 Z - 7EFK:3LF三JE -定函丸-左3玄涯丸戸“-癥苫嚴.理士亍

34、立岳-之飛 大SB増廠-走用坤三章吟-只詭三章務(wù)廉爭號-說陽大道亠星曲;瓦與戸霉粘誥-4X*大追七植侖-氐與犬道去*事-蛙陽太追乏鼻翳村-炳書 技爼二丘諷王W -法帀天:亙戶死 -硏耳天厘三聲弩-武獨怔卒氐話-看應(yīng)壬M空肖-百丘庚M巴:昶-斉手陀匸垢再-奇:壬亞- S?F=-5t 噸量辰舌-抵據(jù)巨SL興村一醫(yī)(35e5八、實驗數(shù)據(jù)示例1、bus表(存放公交車次有關(guān)信息數(shù)據(jù))、bus_type表(存放公交車類型數(shù)據(jù))3、bus_type表(存放公交公司數(shù)據(jù))namesartjmemjftebudenghJPtjttoMjitlfcpKJ|dphEtweE紳H40;W2MD;WX252応2-43A

35、4抽0 放:tXta-M9gL砧MUML斗A陽:興2HX-.K廿25L51,3/25I弟商KAO:2Md:t35弟L.5L3L62片596ftKcQO:W2Wfl:W3635MjU応21I的海KAO:H世 30:t22AWAWAUiALU2AWWljfULiWL6iW2iW132Z910idname1公交一公司2荃立二公司3換交二公司吟公交四公司5公交五公司6會交六公司7武農(nóng)江豆舍交B通恒公司7VLCZNULL5、station 表(存放公交站點數(shù)據(jù))4、bus_station 表(存放公交線路上的各個站點)idn-ame-bs 一nomc;gtZitiE mJOr-dricltiH-:舉亍可足篡估*1 LilZZZ3sM73夙iv舊甫茉旳aPS-曰7八一 Its乘湖杓za-.Jf甩羊宙河 京SSi按MJ大簡2歸昭271搭大耀衣運2Zj陽呂跑sa53il0羽Z工圮半甌32壓工丸護站華利2石曰闕mma-底江大學跖半44丹933坦江丸學站喪兆迪母口 K半8:客金*252SK

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論