文章詳情頁
SQL Server靜態頁面導出技術3
瀏覽:117日期:2023-10-28 13:41:21
本段文章節選自鐵道出版社新出的《用BackOffice建立Intranet/Extranet應用》一書(現已在海淀圖書城有售)。本書詳盡地講述了如何使用微軟BackOffice系列產品來組建Intranet/Extranet應用。通過它您將掌握NT的安裝和設置、使用IIS建立Web站點、通過ILS建立網絡會議系統、用Exchange建立企業的郵件和協作系統、用SQL Server建立Web數據庫應用、用Proxy Server建立同Internet安全可靠的連接、用Media Server建立網絡電視臺/廣播站、用Chart server建立功能強大的聊天室、用Site Server建立個性化的郵件列表和分析網站的訪問情況、用Commerce Server建立B2B或B2C的電子商務網站。此外本書還對網絡的安全性進行了討論,從而指導您建立一個更為健壯和安全的網絡應用。閱讀本書之后,您將發現實現豐富多彩的網絡應用原來這樣簡單……絕對原創,歡迎轉載。但請務必保留以上文字。靜態頁面導出實例分析:;;;;下面討論如何使用靜態頁面導出技術來實現我們在前面要求的各種功能。;;;;首先,我們來看看要導出的頁面文件的結構:;;;;所有導出的頁面都將被放在一個目錄名為當日期的目錄下。其中有兩個非導出文件index.htm和show.htm文件。其作用同cbbinput目錄中的default.htm和show.htm文件相類似。都是為了滿足使頁面能夠正常顯示的需要。之所以使用index.htm而不用default.htm為文件名,是因為大多數ISP提供的主頁空間的目錄省缺文件的名字都是index.htm。;;;;當日的各個版面則導出為一個名為list.htm的文件。每個版面的文章題目列表則分別按順序導出為1~n(n為當日的版面總數)個頁面文件。其文件名也為1.htm~n.htm。當日所刊載的各個文章則以其id為文件名分別進行導出。在list.htm文件中,包含到各個版面頁面文件的超鏈接。在各個版面的頁面文件中,又包含到各個文章頁面文件的超連接。;;;;在出版報的主頁上,還應該有一個用來顯示日期的頁面文件。每個日期的超鏈接都將與其頁面文件所在的目錄中的index.htm文件相對應。點擊日期后,將彈出一個新的瀏覽器窗口。其中顯示的是相應日期的報紙內容。;;;;此外,還應當將此日各篇文章的配圖文件也拷貝到此目錄之下。;;;;我們為此建立一個任務,它會在每天下午的六點執行,將當天報紙的內容導出為靜態的HTML頁面文件。此任務的代碼如下(可以在本書配套光盤的SQLServer目錄的子目錄test下找到此段代碼的文件,其文件名為webout.sql。它使用的模板文件也可以在此目錄下找到):use testgodeclare ;;;;@riqi;;varchar(20),;;;;@filepath;;varchar(255),;;;;@listfile;;varchar(255),;;;;@command varchar(255)set @riqi=left(convert(varchar(40),getdate(),20),10) set @filepath='d:webout'+@riqi+''set @command='md '+@filepathexecute master.dbo.Xp_cmdshell @command set @command='md '+@filepath+'images'execute master.dbo.Xp_cmdshell @commandset @command ='copy d:testfiles*.* d:webout'+@riqi+''execute master.dbo.Xp_cmdshell @command set @command ='copy d:testfilesimages*.* d:webout'+@riqi+'images'execute master.dbo.Xp_cmdshell @command set @command ='copy d:test'+@riqi+'*.* d:webout'+@riqi+''execute master.dbo.Xp_cmdshell @commandset @listfile=@filepath+'list.htm'execute sp_makewebtask @outputfile=@listfile,@query='select distinct banmianfrom gaojianwhere kanwu=''出版報'' and datepart(yy,riqi)=datepart(yy,getdate()) and datepart(dy,riqi)=datepart(dy,getdate())',@templatefile='d:testlist.tml',@codepage=936declare @lists int,@banmian varchar(64),;;;;@filename varchar(64),;;;;@search varchar(2000)set @lists=0declare point cursor for select distinct banmianfrom gaojianwhere kanwu='出版報' and datepart(yy,riqi)=datepart(yy,getdate()) and datepart(dy,riqi)=datepart(dy,getdate())for read onlyopen pointfetch point into ;;@banmianwhile (@@fetch_status=0)beginset @lists=@lists+1set @filename=@filepath+convert(varchar(64),@lists)+'.htm'set @search='SELECT id,timu,laiyuan FROM gaojian WHERE datepart(yy,riqi)=datepart(yy,convert(datetime,'''+@riqi+''')) and datepart(dy,riqi)=datepart(dy,convert(datetime,'''+@riqi+'''))'+'and banmian ='''+@banmian+'''and kanwu=''出版報''order by timu'execute sp_makewebtask @outputfile=@filename,@query=@search,@templatefile='d:testlist2.tml',@codepage=936fetch point into @banmianendclose pointdeallocate pointdeclare @gaojianid intdeclare point2 cursor for select gaojian.idfrom gaojianwhere kanwu='出版報' and datepart(yy,riqi)=datepart(yy,getdate()) and datepart(dy,riqi)=datepart(dy,getdate())for read onlyopen point2fetch point2 into ;;@gaojianidwhile (@@fetch_status=0)beginset @filename=@filepath+convert(varchar(64),@gaojianid)+'.htm'set @search='SELECT timu,laiyuan,neirong,left(pics,10)+ STUFF(pics,1,21,''''),yuanwen FROM gaojian WHERE id='+convert(varchar(64),@gaojianid)execute sp_makewebtask @outputfile=@filename,@query=@search,@templatefile='d:testoutfile.tml',@codepage=936fetch point2 into @gaojianidendclose point2deallocate point2declare @dy int,;;;;@date varchar(20),;;;;@yue varchar(2),;;;;@yue2 varchar(2),;;;;@ri int,;;;;@xingqi int,;;;;@year int,;;;;@outchar varchar(1600),;;;;@tt intcreate table ##daylist ;;;;(out varchar(1600))set @yue2='00'set @tt=0declare point3 cursor for SELECT distinct dy=datepart(dy,riqi),date=left(convert(varchar(40),riqi,20),10),yue=convert(varchar(2),datepart(mm,riqi)),ri=datepart(dd,riqi),xingqi=datepart(dw,riqi),year=datepart(yy,riqi)FROM gaojianwhere kanwu = '出版報' order by year,dyfor read onlyopen point3fetch point3 into @dy,@date,@yue,@ri,@xingqi,@yearwhile (@@fetch_status=0)beginif @yue<>@yue2beginset @tt=0if @yue2=0;;;insert into ##daylist values('<TABLE BORDER="BORDER" ALIGN="CENTER"><th><tr><h2>'+convert(varchar(4),@year)+'年'+@yue+'月份</h2></tr></th><tr><td>星期日</td><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr>')else ;;;insert into ##daylist values('</tr></table><TABLE BORDER="BORDER" ALIGN="CENTER"><th><tr><h2>'+convert(varchar(4),@year)+'年'+@yue+'月份</h2></tr></th><tr><td>星期日</td><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr>')endif @tt<>0;;;if @xingqi < 7;;;;;;set @outchar=@outchar+'<td><a href="'+@date+'/index.htm" TARGET="new">'+convert(varchar(2), @ri)+'</a></td>';;;;else ;;;;;;set @outchar=@outchar+'<td><a href="'+@date+'/index.htm" TARGET="new">'+convert(varchar(2), @ri)+'</a></td></tr><tr>'else ;;;;;;begin;;;;;;set @tt=1;;;;;;set @outchar=;;;;;;case ;;;;;when @xingqi=1 then '';;;;when @xingqi=2 then '<td></td>';;;;when @xingqi=3 then '<td></td><td></td>';;;;when @xingqi=4 then '<td></td><td></td><td></td>';;;;when @xingqi=5 then '<td></td><td></td><td></td><td></td>';;;;when @xingqi=6 then '<td></td><td></td><td></td><td></td><td></td>';;;;when @xingqi=7 then '<td></td><td></td><td></td><td></td><td></td><td></td>';;;;;;end;;;;if @xingqi < 7;;;;;;set @outchar=@outchar+'<td><a href="'+@date+'/index.htm" TARGET="new">'+convert(varchar(2), @ri)+'</a></td>';;;;else ;;;;;;set @outchar=@outchar+'<td><a href="'+@date+'/index.htm" TARGET="new">'+convert(varchar(2), @ri)+'</a></td></tr><tr>';;;;;endinsert into ##daylist values(@outchar)set @yue2=@yueset @outchar=''fetch point3 into @dy,@date,@yue,@ri,@xingqi,@yearendclose point3deallocate point3execute sp_makewebtask @outputfile='d:testdaylist.htm',@query='select * from ##daylist',@templatefile='d:testrili.tml',@codepage=936drop table ##daylist;;;;首先請讀者通讀上面的代碼,以便對它有一個大概的了解。下面我們將對代碼進行逐段的分析和講解:
標簽:
Sql Server
數據庫
排行榜