【文章內(nèi)容簡介】
taGrid1 綁定,以顯示 searchSet 表中的內(nèi)容 : string CommStr0=select line_name as 線路 ,start_end as 起點終點 ,snum as 站點總數(shù) ,setime as 收發(fā)車時間 ,price as 票價 from line where line_id in (select line_id from linestops where stop_id in (select stop_id from stop where stop_name like39。%+stop+%39。)) order by line_id asc。//查詢經(jīng)過此站點的線路信息, 將查詢結果 按線路 id升序排列 ,并提供模糊查詢 。 string CommStr1=select line_id as 線路 ID,seq as 順序 from linestops where stop_id in (select stop_id from stop where stop_name like39。%+stop+%39。) order by line_id asc。//查詢站點在相應線路中的順序 ,并將查詢結果按線路 id升序排列 ,并提供模糊查詢 。 SqlDataAdapter myAdapter=new SqlDataAdapter(CommStr0,myConn)。//執(zhí)行 CommStr0字符串命令 ([searchSet])。 myAdapter=new SqlDataAdapter(CommStr1,myConn)。//執(zhí)行 CommStr1字符串命令 int n=([seq])。 for(int i=0。in。i++)//此 for循環(huán)用于將查出的結果依次填充到表 searchSet中的“順序”那一列 { [searchSet].Rows[i][此站點在線路中的順序]=([seq].Rows[i][順序 ])。 } =[searchSet]。 ()。//將表 searchSet和 DataGrid1綁定,以顯示 searchSet表中的內(nèi)容 string CommandText=select seq as 第幾站 ,stop_name as 站點名 from linestops inner join line on = and =(select line_id from line where line_name=39。+lname+39。)+ inner join stop on = and in(select from linestops where line_id=(select line_id from line where line_name=39。+lname+39。))order by seq asc。//查詢此線路上的所有站點和站點在線路中的相應位置(順序) ,并將查詢結果按站點的順序升序排列 第 10 頁 共 26 頁 站站查詢 站站查詢是三種查詢中最難的,因為它不僅要處理單條直達線路的情況和多條直達線路的情況,還要處理沒有直達線路的情況(即轉乘情況),并且提供模糊查詢的功能。根據(jù)用戶輸入的站點 ,查詢出最短直達線路,如果沒有直達線路則查詢出最短轉乘線路。關鍵代碼如下: 查詢直達線路 : 有直達線路的情況,如果只有一條直達線路,則直接顯示,如果有兩條或兩條以上的直達線路則找出距離最短的直達線路: SqlDataAdapter myAdapter=new SqlDataAdapter(CommandText,myConn)。執(zhí)行 CommandText字符串命令 ([searchSet])。//查詢出的結果存放入 searchSet表 =[searchSet]。 ()。//綁定;顯示 searchSet表中的內(nèi)容 if(i==1) //只有一條直達線路時將表 searchSet1和 DataGrid1綁定,直接顯示 else ////有兩條或 者兩條以上直達路線時找到最短線路; string CommStr4=select * from linestops where stop_id =(select stop_id from stop where stop_name=39。+startStop+39。)+ and line_id in (select line_id from linestops where stop_id =(select stop_id from stop where stop_name=39。+endStop+39。))。//在表 linestops中查詢經(jīng)過站點 startStop的線路中,又經(jīng)過了 endStop站點的的線路記錄 (line_id,stop_id,seq) for(i=0。in。i++)//此 for循環(huán)用于得到相應線路的總距離 for(int j=0。jb[i]。j++)//此 for循環(huán)用于將查詢出的站點到站點的距離存放到動態(tài)數(shù)組中 { string CommStr7=select startStop,endStop,distance from distance where startStop=(select stop_name from stop where stop_id=(select stop_id from linestops where line_id=+a[i]+ and seq=+(seq1[i]+j)+))+ and endStop=(select stop_name from stop where stop_id=(select stop_id from linestops where line_id=+a[i]+ and seq=+(seq1[i]+j+1)+))。//查詢起點站到目的站點之間每兩個站點間的距 sum=sum+(Sdistance[j])。//求距離之和 } string CommStr6=select line_name as 直達最短線路 ,snum as 站點總數(shù) ,start_end as 起點站終點站 ,setime as 收發(fā)車時間 ,price as 票價 from line where line_id=+a[i]+。//查詢各直達線路的信息 else 。。 //沒有直達線路 (轉乘 )的情況 string CommandText=select line_name as 直達線路 ,snum as 總站點數(shù) ,start_end as 起點終點 ,setime as 收發(fā)車時間 ,price as 票價 from line where line_id in (select line_id from linestops where stop_id in (select stop_id from stop where stop_name like39。%+startStop+%39。)+ and line_id in (select line_id from linestops where stop_id in (select stop_id from stop where stop_name like39。%+endStop+%39。)))。//查詢直達線路的命令字符串,模糊查詢 第 11 頁 共 26 頁 轉乘的 實現(xiàn) 的關鍵代碼 : 管理員登錄模塊分析 管理員要進入管理頁面,首先要從這里登錄。管理員必須在輸入用戶名、密碼和驗證碼完全正確的情況下才能進入管理頁面,否則系統(tǒng)會根據(jù)輸入的情況提示是驗證碼錯誤還是用戶名或密碼錯誤,不能進入管理頁面。管理員登 錄 成功后,進入后臺管理模塊,在此模塊中管理員可以添加、刪除和修改相關信息。 在此模塊中用到了存儲過程和驗證碼。 存儲過程 userlogin 用于驗證輸入的用戶名密碼是否正確、合法 : 通過比較 Session 中的字符串和輸入的字符串是否一致,來判斷輸入 驗證碼是否正確。實現(xiàn)驗證碼功能的關鍵代碼: string CommStr1=select stop_id from linestops where line_id in(select line_id from linestops where stop_id=(select stop_id from stop where stop_name=39。+startStop+39。))。 //查詢經(jīng)過站點 startStop的所有線路所經(jīng)過的 站點 (stop_id) string CommStr2=select stop_id from linestops where line_id in(select line_id from linestops where stop_id=(select stop_id from stop where stop_name=39。+endStop+39。))。 //查詢經(jīng)過站點endStop的所有線路所經(jīng)過的站點 (stop_id) int a=[A].。//計算經(jīng)過 站點 startStop的所有線路所要經(jīng)過的站點的總數(shù) int b=[B].。 //計算經(jīng)過站點 endStop的所有線路所要經(jīng)過的站點的總數(shù) ArrayList al=new ArrayList()。//此動態(tài)數(shù)組用于存放相交的站點 int c=。//得到轉乘站點的個數(shù) string CommStr3=select line_name as 乘此線路出發(fā) from line where line_id in (select line_id from linestops where stop_id =+al[m]++ and line_id in (select line_id from linestops where stop_id = (select stop_id from stop where stop_name=39。+startStop+39。)))。//查詢經(jīng)過起點站 startStop并同時經(jīng)過轉乘站點的線路 string CommStr4=select stop_name from stop where stop_id=+al[m]+。//查詢轉乘站點的站點名 string CommStr5=select line_name from line where line_id in(select line_id from linestops where stop_id=+al[m]+ and line_id in (select line_id from linestops where stop_id=(select stop_id from stop where stop_name=39。+endStop+39。)))。//查詢經(jīng)過轉乘站點又同時經(jīng)過目的站點endStop的線路 CREATE procedure userlogin ( @user_id varchar(20),//用于接收用戶名 @password char(15),//用于接收密碼 @success int output//用于判斷驗證用戶名和密碼是否成功 ) AS SELECT @success=count(*) from login WHERE user_id=@user_id and password=@password GO 第 12 頁 共 26 頁 判斷登錄是否成功,通過驗證輸入用戶名密碼驗證碼是否正確來確定登錄是否成功。登錄成功則轉到后臺管理頁面,如果不成功則給出錯誤提示。登錄過程關鍵代碼: 后臺功能模塊分析 后臺模塊主要是管理功能,可以分為三個小模塊:添加模塊、刪除模塊、修 random = new Random()。//生成隨機生成器 for(int i=0。 i5。 i++) { number = ()。 if(number % 2 == 0) code = (char)(39。039。 + (char)(number % 10))。 else code = (char)(39。A39。 + (char)(number % 26))。 checkCode += ()。 } Session[ValidateCode] = checkCode。//將字符串保存到 Session中,以便需要時進行驗證