【文章內(nèi)容簡(jiǎn)介】
in,則把 j的值賦給 min} end。 search←min。 { 返回最小值 } end begin s← 除 E外所有站點(diǎn); dist[A,E]←search(A)。 end. 以下為該算法在本系統(tǒng)中的實(shí)現(xiàn): 第一步:定義 ppDistance(i,j)函數(shù),求出站點(diǎn) i 到站點(diǎn) j 的距離。通過(guò)對(duì)以下語(yǔ)句的調(diào)用,實(shí)現(xiàn)遞歸過(guò)程。主要代碼 如下: sql=select count(*) as count from PPright where BsStart=39。amp。iamp。39。 and BsEnd=39。amp。jamp。39。//創(chuàng)建統(tǒng)計(jì)出站點(diǎn) i 到站點(diǎn) j 的站數(shù)的 SQL 語(yǔ)句 Set rs=() //創(chuàng)建 Recordset對(duì)象 sql,Conn,0,3 if(rs(count)=0) then//如果站點(diǎn)數(shù)為 0則執(zhí)行下面 sql=select count(*) as count from PPright where BsStart=39。amp。jamp。39。 and BsEnd=39。amp。iamp。39。 //創(chuàng)建統(tǒng)計(jì)出站點(diǎn) j 到站點(diǎn) i 的站數(shù)的SQL 語(yǔ)句 39。 Set rs=() //創(chuàng)建Recordset 對(duì)象 sql,Conn,0,3 if(rs(count)=0) then//如 果站點(diǎn)數(shù)為 0則執(zhí)行下面 else//如果站點(diǎn)數(shù)不為 0則執(zhí)行下面 sql=select BsPPright from PPright where BsStart=39。amp。jamp。39。 and BsEnd=39。amp。iamp。39。 //創(chuàng)建查詢出站點(diǎn) j 到站點(diǎn) i 的站點(diǎn)間最短距離的 SQL 語(yǔ)句 39。 Set rs=() 39。創(chuàng)建Recordset 對(duì)象 sql,Conn,0,3 ppDistance=rs(BsPPright)//求出站點(diǎn) j到站點(diǎn) i的距離 第 10 頁(yè) 共 19 頁(yè) exit function end if else sql=select BsPPright from PPright where BsStart=39。amp。iamp。39。 and BsEnd=39。amp。jamp。39。 //創(chuàng)建查詢出站點(diǎn) i 到站點(diǎn) j 的站點(diǎn)間最 短距離的 SQL 語(yǔ)句 39。 Set rs=() 39。創(chuàng)建Recordset 對(duì)象 sql,Conn,0,3 ppDistance=rs(BsPPright)//求出站點(diǎn) i到站點(diǎn) j的距離 第二步:定義 getallsite()函數(shù),返回值為用來(lái)存放站點(diǎn)的數(shù)組。主要代碼如下: sql=select count(*) as count from BusSite //創(chuàng)建統(tǒng)計(jì)站點(diǎn)數(shù)的 SQL語(yǔ)句 Set rs=() //創(chuàng)建 Recordset對(duì)象 sql,Conn,0,3 dim count//定義一個(gè) count 變量 count=rs(count)//把站點(diǎn)數(shù)賦值給 count 變量 dim ret()//定義一個(gè)數(shù)組 ret() redim ret(count)//把 count 放到數(shù)組 ret()中 sql=select BsName from BusSite //創(chuàng)建查詢所有站點(diǎn)名的 SQL 語(yǔ)句 Set rs=() 39。創(chuàng)建 Recordset對(duì)象 sql,Conn,0,3 dim i//定義一個(gè)數(shù) i i=0 do while not ret(i)=rs(BsName)//把站點(diǎn)放到 ret()數(shù)組中 i=i+1//i 增加 1 第三步:定義 getothersite(ret,value)函數(shù),作用是剔除 ret 數(shù)組中value,返回值也是數(shù)組。主要代碼如下: dim retlength//定義一個(gè)變量 retlength retlength=UBound(ret)//把 ret 數(shù)組的最大下標(biāo)賦值給 retlength dim returnArray()//定義一個(gè)數(shù)組 returnArray() redim returnArray(retlength1)//把 retlength1放到數(shù)組returnArray()中 dim i,j j=0 for i=0 to retlength1//從 0 到 retlength1 第 11 頁(yè) 共 19 頁(yè) if(ret(i)=value) then//剔除 ret數(shù)組中 value else returnArray(j)=ret(i)//否則 returnArray(j)=ret(i) j=j+1 end if next getothersite=returnArray//返回?cái)?shù)組 returnArray 第四步:定義 pppath(startsite,endsite,num)函數(shù),求出站點(diǎn)間的最短路徑并顯示出距離。主要代碼如下: public function pppath(startsite,endsite) dim cityarray cityarray=getallsite() midarray=search(startsite,startsite,getothersite(cityarray,startsite),endsite) //此處省略部分代碼 function search(startsite,site,yarray,endsite) //求 site 到endsite 的最短距離 dim path //記錄路徑 if site=endsite then path= 39。CStr(site)+//賦值給路徑 search=Array(0,path) //此處省略部分代碼 dim j j=ppDistance(yarray(i),site) if CDbl(j)0 then//判斷兩個(gè)站點(diǎn)之間是否可以相鄰直達(dá) dim cityarray1 midarray=search(startsite,yarray(i),getothersite(yarray,yarray(i)),endsite) cityarray1=midarray(0) path=midarray(1) 39。if(site=startsite) then 39。 startsite++CStr(j)++yarray(i)+path+CStr(CDbl(j)+CDbl(cityarray1))+br / 39。end if 公交查詢的實(shí)現(xiàn)如圖 34所示。 第 12 頁(yè) 共 19 頁(yè) 圖 34 公交查詢窗口 2. 按車次查詢:可查詢各路公交車的車次及其所經(jīng)過(guò)的站點(diǎn), 首、末班車時(shí)間。首先通過(guò)函數(shù) checkbusexist( id)確認(rèn)該車次是否存在,再查詢通過(guò)對(duì)表 Bustail 的查詢來(lái)得到查詢結(jié)果,若車次不存在,則不能進(jìn)行查詢。此功能主要通過(guò)以下代碼實(shí)現(xiàn): if (checkbusexist((bus))) then rs1=GetBusdetail((bus)) 39。Set rs=GetBuspassingsite((bus)) sql=select * from Busdetail where BusNum=39。amp。(bus)amp。39。 order by Ordernum asc 本功能的實(shí)現(xiàn)如圖 35 所示。 圖 35 車次查詢窗口 3. 按站點(diǎn)查詢:查詢表 Bustail,可得到經(jīng)過(guò)該站點(diǎn)的所有公交車次。實(shí)現(xiàn)如下: if(checkexist((site))) then sql=select distinct (BusNum) from Busdetail where BsName=39。amp。(site)amp。39。 本功能實(shí)現(xiàn)如圖 36所示。 第 13 頁(yè) 共 19 頁(yè) 圖 36 站點(diǎn)查詢窗口 后臺(tái)管理功能模塊 管理員除了具有普通用戶的所有功能以外,還必須對(duì)系統(tǒng)信息實(shí)行更新,以保證用戶能在第一時(shí)間獲得的信息的準(zhǔn)確信及有效性。管理員進(jìn)入后臺(tái)管理頁(yè)面后,即可對(duì)系統(tǒng)信息進(jìn)行相應(yīng)的編輯和刪除。具體功能包括: 1. 站點(diǎn)名稱管理:對(duì)所有站點(diǎn)名稱可進(jìn)行編輯,添加,修改;可以隨時(shí) 按需要更改、增加和刪除站點(diǎn)信息。城市的面貌日新月異,公交站點(diǎn)也應(yīng)該隨著城市的變化而有所變動(dòng)。 添加 sql=insert into BusSite(BsName)values(39。+(BsName)+39。) 刪除 sql=delete from BusSite where BsId=amp。(id) 修改 sql=update BusSite set BsName=39。+(BsName)+39。 where BsId=amp。(id) 2. 站點(diǎn)基本信息管理:對(duì)公交線路內(nèi)容,包括車次名、工作時(shí)間等信息進(jìn)行更新。 添加 sql=insert into Bus(BusNum,BusStarttime,BusEndtime)values(39。+(BusNum)+39。,39。+(BusStarttime)+39。,39。+String(BusEndtime)+39。) 刪除 sql=delete from Bus where BusId=amp。(id) 修改 sql=update Bus set 第 14 頁(yè) 共 19 頁(yè) BusNum=39。+(BusNum)+39。,BusStarttime=39。+ueryString(BusStarttime)+39。,BusEndtime=39。+(BusEndtime)+ 39。 where BusId=amp。(id) 3. 站點(diǎn)順序管理:對(duì)每一線路所經(jīng)過(guò)之站點(diǎn)順序進(jìn)行更新。 添加 sql=insert into Busdetail(BsName,BusNum,Ordernum)values(39。+(BsName)+39。,39。+(BusNum)+39。,+(Ordernum)+) 刪除 sql=delete from Busdetail where BsdlId=amp。(id) 修改 sql=update Busdetail set BsName=39。+(BsName)+39。,BusNum=39。+ring(BusNum)+39。,Ordernum=+(Ordernum)+ where BsdlId=amp。(id) 4. 用戶管理 :對(duì)用戶數(shù)據(jù)可進(jìn)行更新。 添加 sql=insert into Users(UserSign,UserPwd,UserName,UserType)values(39。+ng(UserSign)+39。,39。+(UserPwd)+39。,39。+eryString( UserName)+39。,+(UserType)+) 刪除 sql=delete from Users where UserID=amp。(id) 修改 sql=update Users set UserSign=39。+(UserSign)+39。,UserPwd=39。+eryString(UserPwd)+39。,UserName=39。+(UserName)+39。,UserType=+(UserType)+ where UserID=amp。(id) 5. 站點(diǎn)間距離管理:對(duì)站點(diǎn)間距離信息可進(jìn)行更新。 添加 sql=insert into PPright(BsStart,BsEnd,BsPPright)values(39。+(BsStart)+39。,39。+(BsEnd)+39。,+(BsPPright)+) 刪除 sql=delete from PPright where Id=amp。(id) 修改 sql=update PPright set BsStart=