一個(gè)基于ASP的標(biāo)題廣告管理系統(tǒng)(2)

2022-06-12發(fā)布者:ylm大?。?/span> 下載:0

文件大小:

軟件介紹

二、管理功能

   管理部分共有12個(gè)asp文件,這些腳本的主要功能分別如下:

BannerAdminLogin.asp:管理功能的登錄頁(yè)面。默認(rèn)的用戶(hù)名稱(chēng)是“ADMIN USER”,密碼是“PASSWord”。
CheckBannerAdministrationPassword.asp:檢查使用管理功能的用戶(hù)的密碼。
NotLoggedIn.asp:“沒(méi)有登錄”提示頁(yè)面,如果在登錄之前訪問(wèn)管理頁(yè)面,則顯示該頁(yè)面。
BannerAdministration.asp:這是管理功能的主界面,列出了所有的廣告,并提供兩個(gè)按鈕。這兩個(gè)按鈕分別用于新增廣告和新增廣告客戶(hù)。點(diǎn)擊廣告客戶(hù)名字可以編輯該廣告客戶(hù),點(diǎn)擊廣告文本可以編輯該廣告。
Advertisement.asp:輸入新廣告的信息,或編輯當(dāng)前廣告信息,或調(diào)用DeleteAdvertisement.asp刪除當(dāng)前廣告。
Advertiser.asp:輸入新廣告客戶(hù)的信息,或編輯當(dāng)前廣告客戶(hù)信息,或調(diào)用
DeleteAdvertiser.asp刪除當(dāng)前廣告客戶(hù)。
AddAdvertisement.asp:新增廣告記錄,從Advertisement.asp表單獲取信息,存儲(chǔ)到數(shù)據(jù)庫(kù)。
AddAdvertiser.asp:新增廣告客戶(hù)記錄,從Advertiser.asp表單獲取信息,存儲(chǔ)到數(shù)據(jù)庫(kù)。
UpdateAdvertisement.asp:從Advertisement.asp表單獲取信息,更新數(shù)據(jù)庫(kù)中與當(dāng)前廣告具有相同AdvertisementID的記錄。
UpdateAdvertiser.asp:獲取Advertiser.asp表單信息,更新數(shù)據(jù)庫(kù)中與當(dāng)前廣告客戶(hù)具有相同AdvertiserID的記錄。
DeleteAdvertisement.asp:根據(jù)當(dāng)前選中廣告的AdvertisementID,刪除數(shù)據(jù)庫(kù)中的相應(yīng)記錄。注意:刪除并返回管理主界面后有時(shí)需要重新刷新。
DeleteAdvertiser.asp:根據(jù)當(dāng)前選中廣告客戶(hù)的AdvertiserID,刪除相應(yīng)的數(shù)據(jù)庫(kù)記錄。


                  【圖1】

   完整代碼請(qǐng)從本文后面下載。假設(shè)所有文件均在inetpubScripts目錄下,則登錄管理功能的URL為:http://localhost/scripts/BannerAdminLogin.asp。所有其他功能均可從此開(kāi)始訪問(wèn)。

   接下來(lái)我們介紹管理功能腳本中的一些關(guān)鍵問(wèn)題。

   ㈠ 安全

   大多數(shù)執(zhí)行管理功能的頁(yè)面受密碼保護(hù),這些頁(yè)面在執(zhí)行其任務(wù)之前都會(huì)檢查一個(gè)session變量以確認(rèn)用戶(hù)已經(jīng)成功地登錄。檢查代碼如下所示:

  檢查用戶(hù)是否已經(jīng)登錄
 If SESSION( "LoggedIn" ) <> true Then
     Response.Redirect( "NotLoggedIn.asp" )
 End If
   這里所采用的安全機(jī)制較為簡(jiǎn)單,更多的說(shuō)明參見(jiàn)《在ASP應(yīng)用中驗(yàn)證用戶(hù)身份》。

   ㈡ 列出所有的廣告

   BannerAdministration.asp頁(yè)面啟動(dòng)時(shí)會(huì)列出數(shù)據(jù)庫(kù)中的所有廣告記錄。這部分功能通過(guò)一個(gè)簡(jiǎn)單的查詢(xún)和一個(gè)記錄集對(duì)象完成,如下所示:

     列出數(shù)據(jù)庫(kù)中的所有廣告
      Set cn = Server.CreateObject( "ADODB.Connection" )
     cn.Open "BannerBuddy"
     Set rs = Server.CreateObject( "ADODB.RECORDSET" )
     Set rs2 = Server.CreateObject( "ADODB.RECORDSET" )
     strSql = "SELECT * FROM Advertisement"
     rs.Open strSql, cn
     strCRLF = Chr( 13 ) + Chr( 10 )
     While not rs.EOF and not rs.BOF
        根據(jù)廣告客戶(hù)編號(hào)(AdvertiserID)查找客戶(hù)名稱(chēng)
        strSql = "SELECT Name From Advertiser where AdvertiserID = " + _
                  CStr( rs.Fields( "AdvertiserID" ) )
         rs2.Open strSql, cn
         strAdvertiser = ""
         If not rs2.EOF and not rs2.BOF Then
             strAdvertiser = rs2.Fields( "Name" )
         End If
         Response.Write( "</tr>" + strCRLF )
         rs2.Close
         rs.MoveNext
     Wend
   系統(tǒng)假定數(shù)據(jù)庫(kù)db.mdb的ODBC DSN為BannerBuddy,因此在運(yùn)行程序之前必需設(shè)置好這個(gè)DSN。有關(guān)數(shù)據(jù)庫(kù)連接和操作的更多說(shuō)明,參見(jiàn)《ASP應(yīng)用中數(shù)據(jù)庫(kù)記錄的選取與過(guò)濾》。

   在廣告清單中,單擊廣告客戶(hù)名字可以編輯該廣告客戶(hù)的信息,單擊“文本/圖形”欄中的文本可以編輯該廣告的信息,單擊圖片鏈接可以查看圖片。

   ㈢ 新增、修改廣告和廣告客戶(hù)

   AddAdvertisement.asp和AddAdvertiser.asp這兩個(gè)腳本的任務(wù)是獲取提交給它們的表單數(shù)據(jù),創(chuàng)建廣告客戶(hù)或廣告數(shù)據(jù)庫(kù)記錄。下面的代碼用于新增廣告記錄,新增廣告客戶(hù)(AddAdvertiser.asp)的代碼也類(lèi)似,此處略。

  連接到數(shù)據(jù)庫(kù),創(chuàng)建記錄集對(duì)象rs,略...
 strStartDate = Request.Form( "StartMonth" ) + "/" + _
   Request.Form( "StartDay" ) + "/" + _
   Request.Form( "Startyear" )
 strEndDate = Request.Form( "EndMonth" ) + "/" + _
     Request.Form( "EndDay" ) + "/" + _
   Request.Form( "Endyear" )
 
 nStatus = 1
 If UCase( Request.Form( "Status" ) ) = "INACTIVE" Then
   nStatus = 0
 End If
 
  根據(jù)所選擇的廣告客戶(hù)名字,獲取其編號(hào)
 nAdvertiserID = 1
 strSql = "select AdvertiserID from Advertiser where Name = " + _
   Request.Form( "Advertiser" ) + ""
 rs.Open strSql, cn
 If not rs.EOF and not rs.BOF Then
   nAdvertiserID = rs.Fields( "AdvertiserID" )
   If IsNull( nAdvertiserID ) Then
     nAdvertiserID = 1
   End If
 End If
 
  生成一個(gè)新的廣告編號(hào)
 nAdvertisementID = 1
 strSql = "select AdID=Max( AdID ) from Advertisement"
 rs.Close
 rs.Open strSql, cn
 If not rs.EOF and not rs.BOF Then
   nAdvertisementID = rs.Fields( "AdID" ) + 1
   If IsNull( nAdvertisementID ) Then
     nAdvertisementID = 1
   End If
 End If
 
  插入新廣告記錄的SQL命令
 strSql = "insert into Advertisement " + _
   "( AdvertiserID, Status, ImageURL, " + _
   "ImageWidth, ImageHeight, Link, " + _
   "AltText, Weight, StartDate, EndDate, " + _
   "ViewLimit, ClicksLimit, AdID ) Values ( "
 strSql = strSql + CStr( nAdvertiserID ) + ", "
  加上其他字段值,略...
 strSql = strSql + CStr( nAdvertisementID ) + " )"
 
 rs.Close
 rs.Open strSql, cn
   修改廣告、廣告客戶(hù)信息分別由UpdateAdvertiser.asp和UpdateAdvertiser.asp完成,這兩個(gè)腳本和AddAdvertisement.asp、AddAdvertiser.asp非常相似,只是把增加記錄操作改成了修改記錄。刪除廣告、廣告客戶(hù)的腳本很簡(jiǎn)單(分別為DeleteAdvertisement.asp和DeleteAdvertiser.asp),此處略。 

發(fā)表評(píng)論(共0條評(píng)論)
請(qǐng)自覺(jué)遵守互聯(lián)網(wǎng)相關(guān)政策法規(guī),評(píng)論內(nèi)容只代表網(wǎng)友觀點(diǎn),發(fā)表審核后顯示!

版權(quán)聲明:

1 本站所有資源(含游戲)均是軟件作者、開(kāi)發(fā)商投稿,任何涉及商業(yè)盈利目的均不得使用,否則產(chǎn)生的一切后果將由您自己承擔(dān)!

2 本站將不對(duì)任何資源負(fù)法律責(zé)任,所有資源請(qǐng)?jiān)谙螺d后24小時(shí)內(nèi)刪除。

3 若有關(guān)在線投稿、無(wú)法下載等問(wèn)題,請(qǐng)與本站客服人員聯(lián)系。

4 如侵犯了您的版權(quán)、商標(biāo)等,請(qǐng)立刻聯(lián)系我們并具體說(shuō)明情況后,本站將盡快處理刪除,聯(lián)系QQ:2499894784

返回頂部