ASP数据岛操作类
ASP数据岛操作类
发布时间:2016-12-29 来源:查字典编辑
摘要:=1andCurPage4ThenIfCurPage+25ThenEndPage=5ElseEndPage=DataSource.PageC...

<%

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'ProgrammingBySmartpig'

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

ClassTBGrid

publicDataSource'数据源

publicstyle'表格总风格

publicHeadStyle'表头风格

publicHeadItemStyle'表头单独风格

publicitemStyle'单元格独立网络

publicHeadSort'表头是否显示排序功能

publicColumns'需要显示的列元素

publicAlternate'是否交替风格

publicAlternateStyle'偶数行风格

publicNormalStyle'正常风格

publicDefaultStyle'默认风格簇

publicPageSize'页大小

publicAllowPageing'是否分页

publicPageingStyle'页数风格

PrivateTemplates'自定义单元项

privateCurPage'当前页

privatePageStart'页面开始运行时间

'内容之间的关系

'Columns.add"Field","HeadText"

'AddTemplate("HeadText",Template)

'itemStyle.add"Field","style:adsasd"

'HeadSort.add"Field",True

'DataSource(Columns.Keys(i))

PrivateSubClass_Initialize'设置Initialize事件。

SetitemStyle=CreateObject("Scripting.Dictionary")

SetHeadSort=CreateObject("Scripting.Dictionary")

SetHeadItemStyle=CreateObject("Scripting.Dictionary")

SetColumns=CreateObject("Scripting.Dictionary")

SetTemplates=CreateObject("Scripting.Dictionary")

SetDataSource=CreateObject("ADODB.Recordset")

Alternate=0

PageStart=Timer

EndSub

PrivateSubClass_Terminate'设置Terminate事件。

SetitemStyle=Nothing

SetHeadSort=Nothing

SetHeadItemStyle=Nothing

SetColumns=Nothing

SetDataSource=Nothing

EndSub

PrivateSubInitTable()

'SetFieldsNum=DataSource.Fields.Count

'SetRowsNum=DataSource.RecordCount

ifColumns.Count=0then

Fori=0toDataSource.Fields.Count-1

Columns.addDataSource.Fields(i).Name,DataSource.Fields(i).Name

response.Write(DataSource.Fields(i).Name)

Next

endif

ifIsEmpty(Style)andIsEmpty(NormalStyle)then

DefaultStyle=1

Else

DefaultStyle=Style

endif

CurPage=CInt(Request.QueryString("page"))

ifCurPage=""then

CurPage=1

EndIf

ifPageSize=Emptythen

PageSize=10

endif

selectCaseDefaultStyle

Case1

Style="align=centerborder=0cellpadding=4cellspacing=1bgcolor='#cccccc'"

Alternate=1

HeadStyle="Height=25style=""background-color:#006699;color:#ffffff"""

AlternateStyle="bgColor=#ffffffheight=25"

NormalStyle="height=25bgcolor=#f5f5f5"

AllowPageing=true

tbGrid1.PageingStyle="bgcolor='#f5f5f5'align='right'"

Case2

Style="align=centerborder=0cellpadding=4cellspacing=1bgcolor='#cccccc'"

Alternate=0

HeadStyle="Height=25style=""background-color:#ffffff"""

AlternateStyle="bgColor=#ffffffheight=25"

NormalStyle="height=25bgcolor=#ffffff"

CaseElse

EndSelect

Endsub

publicSubAddTemplate(ByValColumnName,ByValTemplate)

Columns.addColumnName,ColumnName

Templates.addColumnName,Template

EndSub

publicSubShow()

InitTable()

DimtableStr

DimtdStart,tdEnd,tbStyle,tbContent

DimcurRow

Dimclm

DimregEx,Match,Matches

tableStr="<table"&style&">"&vbCrLF

'DrawTableHead

Response.Write(tableStr)

Response.Write("<tr>")

forEachclminColumns.Keys()

tbStyle=HeadStyle&""&HeadItemStyle(clm)

tdStart="<th"&tbStyle&">"

tdEnd="</th>"&vbCrLf

Response.Write(tdStart)

'加入表头排序功能

'CodebyRedsun

'Date:2005-1-17

IfHeadSort(clm)Then

Response.WriteSort(clm,Columns(clm))

Else

Response.Write(Columns(clm))

EndIf

Response.Write(tdEnd)

Next

Response.Write("</tr>"&vbCrLF)

'DrawTableitems

curRow=1

ifAllowPageing<>Emptythen

DataSource.PageSize=PageSize

else

DataSource.PageSize=DataSource.RecordCount

endif

ifCurPage<1then

DataSource.AbsolutePage=1

endif

ifCurPage>=DataSource.PageCountthen

DataSource.AbsolutePage=DataSource.PageCount

endif

ifCurPage>=1andCurPage<=DataSource.PageCountthen

DataSource.AbsolutePage=CurPage

endif

forcurRow=1toDataSource.PageSize

ifDataSource.EOFthen

ExitFor

endif

Response.Write("<tr>")

forEachclminColumns.Keys()

ifAlternate=0then

tbStyle=NormalStyle&""&ItemStyle(clm)

else

ifcurRowmod2=0then

tbStyle=AlternateStyle&""&ItemStyle(clm)

else

tbStyle=NormalStyle&""&ItemStyle(clm)

endif

endif

tdStart="<td"&tbStyle&">"

tdEnd="</td>"&vbCrLf

ifTemplates(clm)=Emptythen

tbContent=DataSource(clm)

else

tbContent=Templates(clm)

SetregEx=NewRegExp

regEx.Pattern="{[A-Za-z0-9_-]+}"

regEx.IgnoreCase=True

regEx.Global=True

SetMatches=regEx.Execute(Templates(clm))

Foreachmatchinmatches

OnErrorResumeNext

tbContent=Replace(tbContent,Match.Value,DataSource(Mid(Match.Value,2,Len(Match.Value)-2)),1)

Next

endif

Response.Write(tdStart)

Response.Write(tbContent)

Response.Write(tdEnd)

Next

Response.Write("</tr>"&vbCrLF)

DataSource.MoveNext

Next

'DrawPageingRow

ifDataSource.PageCount>1andLCase(pageingStyle)<>"none"then

Dimi,EndPage,StartPage

response.write("<tr>")

response.write("<tdcolspan="&Columns.Count&""&PageingStyle&">")

'改进分页功能

'CodebyRedsun

'Date:2005-1-17

IfCurPage>4Then

IfCurPage+2<DataSource.PageCountThen

StartPage=CurPage-2

EndPage=CurPage+2

Else

StartPage=DataSource.PageCount-4

EndPage=DataSource.PageCount

EndIf

Else

StartPage=1

IfDataSource.PageCount>5Then

EndPage=5

Else

EndPage=DataSource.PageCount

EndIf

EndIf

IfCurPage>1Then

Response.Write"<atitle='首页'href='"&GetUrl("page")&"page=1'><fontface=webdings>9</font></a>"

Response.Write"<atitle='上页'href='"&GetUrl("page")&"page="&CurPage-1&"'><fontface=webdings>3</font></a>"

Else

Response.Write"<fontface=webdings>9</font>"

Response.Write"<fontface=webdings>3</font>"

EndIf

Fori=StartPagetoEndPage

ifi<>CurPagethen

response.write("<atitle='第"&i&"页'href='"&GetUrl("page")&"page="&i&"'>"&i&"</a>")

Else

response.write("<b>"&i&"</b>")

Endif

next

IfCurPage<DataSource.PageCountThen

Response.Write"<atitle='下页'href='"&GetUrl("&page&")&"page="&CurPage+1&"'><fontface=webdings>4</font></a>"

Response.Write"<atitle='尾页'href='"&GetUrl("&page&")&"page="&DataSource.PageCount&"'><fontface=webdings>:</font></a>"

Else

Response.Write"<fontface=webdings>4</font>"

Response.Write"<fontface=webdings>:</font>"

EndIf

Response.Write"[共"&DataSource.RecordCount&"条]["&PageSize&"条/页][共"&DataSource.PageCount&"页]"

Response.Write"PageExecute:"&Round((Timer-PageStart)*1000,2)&"MS"

response.write("</td></tr>"&vbCrLf)

Endif

'DrawTableend

Response.Write("</table>")

Endsub

'====================================================================

'获取当前Url参数的函数

'CodeingbyRedsun

'====================================================================

PrivateFunctionGetUrl(RemoveList)

DimScriptAddress,M_ItemUrl,M_item

ScriptAddress=CStr(Request.ServerVariables("SCRIPT_NAME"))&"?"'取得当前地址

M_ItemUrl=""

ForEachM_itemInRequest.QueryString

IfInStr(RemoveList,M_Item)=0Then

M_ItemUrl=M_ItemUrl&M_Item&"="&Server.URLEncode(Request.QueryString(""&M_Item&""))&"&"

EndIf

Next

GetUrl=ScriptAddress&M_ItemUrl

EndFunction

'=============================

'实现列表排序

'返回Url参数并动态改变排序方式

'参数:需要进行排序的字段名,显示的名称

'=============================

PrivateFunctionSort(SortStr,DispName)

IfSortStr=""OrDispName=""ThenExitFunction

Sort=GetUrl("SOrder,SSort")

SSort=UCase(Request.QueryString("SSort"))

IfSSort="DESC"Then

SSort="ASC"

Else

SSort="DESC"

EndIf

Sort="<aclass='headhref'href='"&Sort&"SOrder="&SortStr&"&SSort="&SSort&"'>"&DispName&SortType(SortStr)&"</a>"

EndFunction

'-----------------------------------------------

'标识排序列为升序还是降序方式

'参数:排序列字段名称

'-----------------------------------------------

PrivateFunctionSortType(FieldName)

DimSOrderName

SOrderName=Request.QueryString("SOrder")

IfSOrderName<>FieldNameThenExitFunction

DimSSortImg

SSortImg=Request.QueryString("SSort")

SortType="<imgsrc='/OrderFormSystem/images/"&SSortImg&".gif'border='0'>"

EndFunction

EndClass

'usersLike{UserID,LoginName,Password,RealName,Age,Gender,}

'initDB

Rs.Open"Select*fromusers",Cn

DimtbGrid1

SettbGrid1=NewTBGrid

SettbGrid1.DataSource=Rs

tbGrid1.Columns.add"LoginName","用户名"

tbGrid1.HeadSort.add"LoginName",True

tbGrid1.Columns.add"Password","密码"

tbGrid1.AddTemplate"修改","<ahref='aaa.asp?id={UserID}'><fontcolor=red>{RealName}</font></a>"

tbGrid1.ItemStyle.add"Password","align=right"

tbGrid1.ItemStyle.add"修改","width=100"

tbGrid1.PageSize=5

tbGrid1.AllowPageing=true

tbGrid1.PageingStyle="align=right"

tbGrid1.Show()

'CloseDB

%>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ASP教程学习
热门ASP教程学习
编程开发子分类