仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 380|回复: 8
打印 上一主题 下一主题

[学习教程] ASP网页设计dreamweaverMX通用分页代码研讨

[复制链接]
爱飞 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:30:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
无法实现跨操作系统的应用。当然这也是微软的理由之一,只有这样才能发挥ASP最佳的能力。可是我却认为正是Windows限制了ASP,ASP的概念本就是为一个能让系统运行于一个大的多样化环境而设计的;DreamweaverMX已正式公布了,Deamweaver4+DeamweaverULTRADEV4的组合使他成为固然的制做网页的首选工具,(好象做告白:) )
好了,进进正题,
我在之前做网页的分页时分都是用本人写的服务端剧本(我从不必ADO的分页),用了MX后发明在这内里用分页太便利了,不外代码也有点太长了,人人看上面的代码就能够晓得。用过以后我发明内里recordset的cursortype设为0分页居然能够一般事情!这令我受惊很多,剖析了代码以后才发明MX是用了一种挺笨的办法完成的,效力很低,以是人人仍是用1吧:)
剖析以下:


<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%>
<!--#includefile="Connections/ncarcnn.asp"-->
<%
DimRecordset1
DimRecordset1_numRows

SetRecordset1=Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection=MM_ncarcnn_STRING
Recordset1.Source="SELECT*FROMdbo.ncarinfo"

Recordset1.CursorType=0
这里用0也能够一般运转,可是经由剖析代码能够看出,用0的效力很低,倡议用1


Recordset1.CursorLocation=2
Recordset1.LockType=1
Recordset1.Open()

Recordset1_numRows=0
%>


<%

以下为分页代码
DimRepeat1__numRows
DimRepeat1__index

Repeat1__numRows=10
Repeat1__index=0
Recordset1_numRows=Recordset1_numRows+Repeat1__numRows
%>
<%
***Recordset形态,界说形态变量

DimRecordset1_total
DimRecordset1_first
DimRecordset1_last

settherecordcount
Recordset1_total=Recordset1.RecordCount

setthenumberofrowsdisplayedonthispage
If(Recordset1_numRows<0)Then
Recordset1_numRows=Recordset1_total
Elseif(Recordset1_numRows=0)Then
Recordset1_numRows=1
EndIf

setthefirstandlastdisplayedrecord
Recordset1_first=1
Recordset1_last=Recordset1_first+Recordset1_numRows-1

ifwehavethecorrectrecordcount,checktheotherstats处置准确的rs
If(Recordset1_total-1)Then
If(Recordset1_first>Recordset1_total)Then
Recordset1_first=Recordset1_total
EndIf
If(Recordset1_last>Recordset1_total)Then
Recordset1_last=Recordset1_total
EndIf
If(Recordset1_numRows>Recordset1_total)Then
Recordset1_numRows=Recordset1_total
EndIf
EndIf
%>
<%
***RecordsetStats:ifwedontknowtherecordcount,manuallycountthem处置毛病的RS

If(Recordset1_total=-1)Then

countthetotalrecordsbyiteratingthroughtherecordset
Recordset1_total=0
While(NotRecordset1.EOF)
Recordset1_total=Recordset1_total+1
Recordset1.MoveNext
Wend

resetthecursortothebeginning
If(Recordset1.CursorType>0)Then
Recordset1.MoveFirst
Else
Recordset1.Requery
EndIf

setthenumberofrowsdisplayedonthispage
If(Recordset1_numRows<0OrRecordset1_numRows>Recordset1_total)Then
Recordset1_numRows=Recordset1_total
EndIf

setthefirstandlastdisplayedrecord
Recordset1_first=1
Recordset1_last=Recordset1_first+Recordset1_numRows-1

If(Recordset1_first>Recordset1_total)Then
Recordset1_first=Recordset1_total
EndIf
If(Recordset1_last>Recordset1_total)Then
Recordset1_last=Recordset1_total
EndIf

EndIf
%>
<%
DimMM_paramName
%>
<%
***MoveToRecordandGoToRecord:declarevariables

DimMM_rs
DimMM_rsCount
DimMM_size
DimMM_uniqueCol
DimMM_offset
DimMM_atTotal
DimMM_paramIsDefined

DimMM_param
DimMM_index

SetMM_rs=Recordset1
MM_rsCount=Recordset1_total
MM_size=Recordset1_numRows
MM_uniqueCol=""
MM_paramName=""
MM_offset=0
MM_atTotal=false
MM_paramIsDefined=false
If(MM_paramName"")Then
MM_paramIsDefined=(Request.QueryString(MM_paramName)"")
EndIf
%>
<%
***MoveToRecord:handleindexoroffsetparameter

if(NotMM_paramIsDefinedAndMM_rsCount0)then

useindexparameterifdefined,otherwiseuseoffsetparameter
MM_param=Request.QueryString("index")
If(MM_param="")Then
MM_param=Request.QueryString("offset")
EndIf
If(MM_param"")Then
MM_offset=Int(MM_param)
EndIf

ifwehavearecordcount,checkifwearepasttheendoftherecordset
If(MM_rsCount-1)Then
If(MM_offset>=MM_rsCountOrMM_offset=-1)Thenpastendormovelast
If((MM_rsCountModMM_size)>0)Thenlastpagenotafullrepeatregion
MM_offset=MM_rsCount-(MM_rsCountModMM_size)
Else
MM_offset=MM_rsCount-MM_size
EndIf
EndIf
EndIf

movethecursortotheselectedrecord
MM_index=0
While((NotMM_rs.EOF)And(MM_index<MM_offsetOrMM_offset=-1))
MM_rs.MoveNext
MM_index=MM_index+1
Wend
If(MM_rs.EOF)Then
MM_offset=MM_indexsetMM_offsettothelastpossiblerecord
EndIf

EndIf
%>
<%
***MoveToRecord:ifwedontknowtherecordcount,checkthedisplayrange

If(MM_rsCount=-1)Then

walktotheendofthedisplayrangeforthispage
MM_index=MM_offset
While(NotMM_rs.EOFAnd(MM_size<0OrMM_index<MM_offset+MM_size))
MM_rs.MoveNext
MM_index=MM_index+1
Wend

ifwewalkedofftheendoftherecordset,setMM_rsCountandMM_size
If(MM_rs.EOF)Then
MM_rsCount=MM_index
If(MM_size<0OrMM_size>MM_rsCount)Then
MM_size=MM_rsCount
EndIf
EndIf

ifwewalkedofftheend,settheoffsetbasedonpagesize
If(MM_rs.EOFAndNotMM_paramIsDefined)Then
If(MM_offset>MM_rsCount-MM_sizeOrMM_offset=-1)Then
If((MM_rsCountModMM_size)>0)Then
MM_offset=MM_rsCount-(MM_rsCountModMM_size)
Else
MM_offset=MM_rsCount-MM_size
EndIf
EndIf
EndIf

resetthecursortothebeginning
If(MM_rs.CursorType>0)Then
MM_rs.MoveFirst
Else
MM_rs.Requery
EndIf

movethecursortotheselectedrecord
MM_index=0
While(NotMM_rs.EOFAndMM_index<MM_offset)
MM_rs.MoveNext
MM_index=MM_index+1
Wend
EndIf
%>
<%
***MoveToRecord:updaterecordsetstats

setthefirstandlastdisplayedrecord
Recordset1_first=MM_offset+1
Recordset1_last=MM_offset+MM_size

If(MM_rsCount-1)Then
If(Recordset1_first>MM_rsCount)Then
Recordset1_first=MM_rsCount
EndIf
If(Recordset1_last>MM_rsCount)Then
Recordset1_last=MM_rsCount
EndIf
EndIf

setthebooleanusedbyhideregiontocheckifweareonthelastrecord
MM_atTotal=(MM_rsCount-1AndMM_offset+MM_size>=MM_rsCount)
%>
<%
***GoToRecordandMoveToRecord:createstringsformaintainingURLandFormparameters

DimMM_keepNone
DimMM_keepURL
DimMM_keepForm
DimMM_keepBoth

DimMM_removeList
DimMM_item
DimMM_nextItem

createthelistofparameterswhichshouldnotbemaintained
MM_removeList="&index="
If(MM_paramName"")Then
MM_removeList=MM_removeList&"&"&MM_paramName&"="
EndIf

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

addtheURLparameterstotheMM_keepURLstring
ForEachMM_itemInRequest.QueryString
MM_nextItem="&"&MM_item&"="
If(InStr(1,MM_removeList,MM_nextItem,1)=0)Then
MM_keepURL=MM_keepURL&MM_nextItem&Server.URLencode(Request.QueryString(MM_item))
EndIf
Next

addtheFormvariablestotheMM_keepFormstring
ForEachMM_itemInRequest.Form
MM_nextItem="&"&MM_item&"="
If(InStr(1,MM_removeList,MM_nextItem,1)=0)Then
MM_keepForm=MM_keepForm&MM_nextItem&Server.URLencode(Request.Form(MM_item))
EndIf
Next

createtheForm+URLstringandremovetheintial&fromeachofthestrings
MM_keepBoth=MM_keepURL&MM_keepForm
If(MM_keepBoth"")Then
MM_keepBoth=Right(MM_keepBoth,Len(MM_keepBoth)-1)
EndIf
If(MM_keepURL"")Then
MM_keepURL=Right(MM_keepURL,Len(MM_keepURL)-1)
EndIf
If(MM_keepForm"")Then
MM_keepForm=Right(MM_keepForm,Len(MM_keepForm)-1)
EndIf

autilityfunctionusedforaddingadditionalparameterstothesestrings
FunctionMM_joinChar(firstItem)
If(firstItem"")Then
MM_joinChar="&"
Else
MM_joinChar=""
EndIf
EndFunction
%>
<%
***MoveToRecord:setthestringsforthefirst,last,next,andpreviouslinks

DimMM_keepMove
DimMM_moveParam
DimMM_moveFirst
DimMM_moveLast
DimMM_moveNext
DimMM_movePrev

DimMM_urlStr
DimMM_paramList
DimMM_paramIndex
DimMM_nextParam

MM_keepMove=MM_keepBoth
MM_moveParam="index"

ifthepagehasarepeatedregion,removeoffsetfromthemaintainedparameters
If(MM_size>1)Then
MM_moveParam="offset"
If(MM_keepMove"")Then
MM_paramList=Split(MM_keepMove,"&")
MM_keepMove=""
ForMM_paramIndex=0ToUBound(MM_paramList)
MM_nextParam=Left(MM_paramList(MM_paramIndex),InStr(MM_paramList(MM_paramIndex),"=")-1)
If(StrComp(MM_nextParam,MM_moveParam,1)0)Then
MM_keepMove=MM_keepMove&"&"&MM_paramList(MM_paramIndex)
EndIf
Next
If(MM_keepMove"")Then
MM_keepMove=Right(MM_keepMove,Len(MM_keepMove)-1)
EndIf
EndIf
EndIf

setthestringsforthemovetolinks
If(MM_keepMove"")Then
MM_keepMove=MM_keepMove&"&"
EndIf

MM_urlStr=Request.ServerVariables("URL")&"?"&MM_keepMove&MM_moveParam&"="

MM_moveFirst=MM_urlStr&"0"
MM_moveLast=MM_urlStr&"-1"
MM_moveNext=MM_urlStr&CStr(MM_offset+MM_size)
If(MM_offset-MM_size<0)Then
MM_movePrev=MM_urlStr&"0"
Else
MM_movePrev=MM_urlStr&CStr(MM_offset-MM_size)
EndIf
%>
<html>
<head>
<title>UntitledDocument</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>

<body>
<p></p>

<tableborder="1">
<tr>
<td>cpno</td>
<td>cbno</td>
<td>cdpt</td>
<td>cid</td>
<td>cbnm</td>
<td>ddate</td>
<td>cstate</td>
<td>guid</td>
</tr>
<%While((Repeat1__numRows0)AND(NOTRecordset1.EOF))%>
<tr>
<td><%=(Recordset1.Fields.Item("cpno").Value)%></td>
<td><%=(Recordset1.Fields.Item("cbno").Value)%></td>
<td><%=(Recordset1.Fields.Item("cdpt").Value)%></td>
<td><%=(Recordset1.Fields.Item("cid").Value)%></td>
<td><%=(Recordset1.Fields.Item("cbnm").Value)%></td>
<td><%=(Recordset1.Fields.Item("ddate").Value)%></td>
<td><%=(Recordset1.Fields.Item("cstate").Value)%></td>
<td><%=(Recordset1.Fields.Item("guid").Value)%></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>

</table>
<p></p>
<tableborder="0"width="50%"align="center">
<tr>
<tdwidth="23%"align="center"><%IfMM_offset0Then%>
<ahref="<%=MM_moveFirst%>"><%IfNotMM_atTotalThen%>
<ahref="<%=MM_moveNext%>"></a>
<%EndIfendNotMM_atTotal%></td>
</tr>
</table>

Records<%=(Recordset1_first)%>to<%=(Recordset1_last)%>of<%=(Recordset1_total)%>
</body>
</html>
<%
Recordset1.Close()
SetRecordset1=Nothing
%>



编译成dll用也能够:)
ASP由于使用了COM组件所以它会变的十分强大,但是这样的强大由于WindowsNT系统最初的设计问题而会引发大量的安全问题。只要在这样的组件或是操作中一不注意,哪么外部攻击就可以取得相当高的权限而导致网站瘫痪或者数据丢失;
愤怒的大鸟 该用户已被删除
沙发
发表于 2015-1-19 15:50:13 | 只看该作者
代码逻辑混乱,难于管理:由于ASP是脚本语言混合html编程,所以你很难看清代码的逻辑关系,并且随着程序的复杂性增加,使得代码的管理十分困难,甚至超出一个程序员所能达到的管理能力,从而造成出错或这样那样的问题。
蒙在股里 该用户已被删除
板凳
发表于 2015-1-26 21:41:52 | 只看该作者
ASP(ActiveServerPages)是Microsfot公司1996年11月推出的WEB应用程序开发技术,它既不是一种程序语言,也不是一种开发工具,而是一种技术框架,不须使用微软的产品就能编写它的代码,能产生和执行动态、交互式、高效率的站占服务器的应用程序。
admin 该用户已被删除
地板
发表于 2015-2-4 21:03:23 | 只看该作者
学习ASP其实应该上升到如何学习程序设计这种境界,其实学习程序设计又是接受一种编程思想。比如ASP如何学习,你也许在以前的学习中碰到过。以下我仔细给你说几点:
莫相离 该用户已被删除
5#
发表于 2015-2-10 10:36:57 | 只看该作者
我就感觉到ASP和一些常用的数据库编程以及软件工程方面的思想是非常重要的。我现在也在尝试自己做网页,这其中就用到了ASP,我想它的作用是可想而知的。
乐观 该用户已被删除
6#
发表于 2015-3-1 09:36:56 | 只看该作者
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
因胸联盟 该用户已被删除
7#
发表于 2015-3-10 13:09:57 | 只看该作者
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
飘灵儿 该用户已被删除
8#
发表于 2015-3-17 08:09:24 | 只看该作者
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
灵魂腐蚀 该用户已被删除
9#
发表于 2015-3-24 03:41:23 | 只看该作者
代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-11-14 14:02

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表