ASP 投票系统所用技术小结

本文解析了一个ASP投票系统的实现代码,包括页面连接数据库记录、显示错误提示、分页调用等功能,介绍了如何处理投票数据及页面操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ContractedBlock.gifExpandedBlockStart.gifCode


Code
5:函数部分应用

<%
titleid
=request.QueryString("titleid")
call isid(titleid)
set temp=conn.execute("select count(id) from [VoteTitle] where id="&titleid)
if temp(0)=0 then
    
Call ShowError("错误!")
end if
Call RsName(rs,"select a.id,a.selectitem,a.votecount,b.votetitle,b.webname from [VoteSelect] a inner join [VoteTitle] b on a.titleid=b.id where a.titleid="&titleid,1,1)
dim total
total
=0
do while not rs.eof
total
=total+rs(2)
rs.movenext
loop
rs.movefirst
if total=0 then
Call ShowErrorClose("尚无人投票!")
end if
%>

<href="javascript:window.close()">关闭窗口</a>


<%
id
=Cint(request.QueryString("id"))
if request.QueryString("action")="title" then
conn.execute(
"delete from [VoteSelect] where titleid="&id)
conn.execute(
"delete from [VoteTitle] where id="&id)
end if
if request.QueryString("action")="select" then
conn.execute(
"delete from [VoteSelect] where id="&id)
end if
Call ShowErrorTo("操作成功!","MyVote.asp")
Call CloseConn()
%>


Code
1:函数页面:
 
<%
'L.C.H-001建立连接数据库记录
Function RsName(Rs_Name,Sql,A,B)
Set Rs_Name=Server.CreateObject("Adodb.RecordSet")
Rs_Name.open Sql,conn,A,B
End Function
'************************************************************************
'
L.C.H-002释放记录集
Sub CloseRs()
rs.close
set rs=nothing
End Sub
'************************************************************************
'
L.C.H-003释放conn
Sub CloseConn()
conn.close
set conn=nothing
End Sub
'************************************************************************
'
L.C.H-004显示错误提示且返回上一页
Function ShowError(a)
response.write(
"<script language=javascript>alert('"&a&"');javascript:history.go(-1)")
response.write(
"</script>")
response.end()
End Function
'************************************************************************
'
L.C.H-005显示错误提示且重新载入另一页
Function ShowErrorTo(a,b)
response.write(
"<script language=javascript>alert('"&a&"');")
response.write(
"this.location.href='"&b&"';</script>")
response.end()
End Function
'************************************************************************
'
L.C.H-006显示错误提示且关闭该窗口
Function ShowErrorClose(a)
response.write(
"<script language=javascript>alert('"&a&"');")
response.write(
"javascript:window.close();</script>")
response.end()
End Function
'************************************************************************
'
L.C.H-007分页调用
Function PageGo(sql)
response.write 
"<table width='99%' border='1' align='center' cellPadding='0' cellSpacing='0' bordercolor='#71CC71' bgcolor='#E9F8E9' class='12'>"
response.write 
"<form method=Post action='"&Myself&"?"&sql&"'>"
response.write 
"<tr><td height='24' bordercolor='#E9F8E9'><div align='center'>"
   
If currentpage > 1 Then
      response.write 
"<a href='"&Myself&"?"&sql&"page="+cstr(1)+"'><font color='#ff0000'>首页</font></a><font color='#333333'><b>-</b></font>"  
      Response.write 
"<a href='"&Myself&"?"&sql&"page="+Cstr(currentpage-1)+"'><font color='#ff0000'>前页</font></a><font color='#333333'><b>-</b></font>"
   
Else
      Response.write 
"<font color='#333333'>首页-</font>"
      Response.write 
"<font color='#333333'>前页-</font>"      
   
End if
   
If currentpage < rs.PageCount Then
      Response.write 
"<a href='"&Myself&"?"&sql&"page="+Cstr(currentPage+1)+"'><font color='#ff0000'>后页</font></a><font color='#333333'><b>-</b></font>"
      Response.write 
"<a href='"&Myself&"?"&sql&"page="+Cstr(rs.PageCount)+"'><font color='#ff0000'>尾页</font></a>&nbsp;&nbsp;"
   
Else
      Response.write 
"<font color='#333333'>后页-</font>"
      Response.write 
"<font color='#333333'>尾页</font>&nbsp;&nbsp;"       
   
End if
Response.write 
"<font color='#333333'>页次:</font>" & "<font color=#ff0000 face='Geneva, Arial, Helvetica, sans-serif'>" & Cstr(CurrentPage) &  "</font>" & "<font color='#333333' face='Geneva, Arial, Helvetica, sans-serif'>/" & Cstr(rs.pagecount) & "</font>&nbsp;"
Response.write 
"<font color=#ff0000 face='Geneva, Arial, Helvetica, sans-serif'>" & Cstr(MaxPerPage) & "</font>" & "<font color='#333333' face='Geneva, Arial, Helvetica, sans-serif'>条/页&nbsp" & "共</font>" & "<font color=#ff0000 face='Geneva, Arial, Helvetica, sans-serif'>" & Cstr(rs.RecordCount) & "</font>" & "<font color='#333333'>条信息</font>&nbsp;&nbsp;"
response.write 
"<font color='#333333'>转到:</font><input type='text' name='page' size=4 maxlength=4 class='Input' value="&Currentpage&">&nbsp;"
response.write 
"<input type='submit'  value='转到'  name='cndok' class='button'></span>&nbsp;&nbsp;"   
response.write 
"</div></td></tr></form></table>"
End Function
'************************************************************************
'
L.C.H-008禁止外部提交
Sub Remote()
if not (instr(1,Request.ServerVariables("http_Referer"),Request.ServerVariables ("SERVER_NAME"),1)=8then
    
Call ShowError("参数错误!")
end if 
end Sub
'************************************************************************
'
L.C.H-010是否为数字
Function IsDigit(a)
    
if isnumeric(a)=false then
        
Call ShowError("参数错误!")
    
end if
end Function
'************************************************************************
'
L.C.H-011传递ID的有效性
Function Isid(a)
    
if a="" or isnumeric(a)=false then
        
Call ShowError("参数错误!")
    
end if
end Function
'************************************************************************
'
L.C.H-012关闭当前弹出窗口,并且刷新父窗口
Sub Refresh()
    response.write(
"<script language='javascript'>")
    response.write(
"alert('操作成功!');")
    response.write(
"opener.location.reload();")
    response.write(
"top.close();")
    response.write(
"</script>")
    response.end()
end sub 
'************************************************************************
'
L.C.H-013打开弹出窗口,并且刷新父窗口
Sub Refresh2()
    response.write(
"<script language='javascript'>")
    response.write(
"opener.location.reload();")
    response.write(
"</script>")
end sub 
'************************************************************************
%>

2:asp中Response.Expires = -1
一般情况下,当用户请求WEB服务器时,服务器把请求回复给客户端。在客户端,浏览器把缓存作为一种加快速度的策略,就是当请求时先检查缓存的情况,如果有就直接调缓存了,而不请求服务器了。 
在WEB程序设计中,有时为了防止重复的提交或者严格的次序等,必须让用户的数据立即在使用后就过期,当用户后退时就显示过期而不能继续使用。也算是为安全考虑的吧。 
一般,response.expires写在页面的最上端,后面跟的是一个时间,就是过期的时间,0表示立即过期。
response.expires=1表示在1分钟后过期。


3:ASP的Round函数是4舍6入,5奇进偶不进
[
round(56.5)=56 
但 
round(57.5)=58 
]
ASP的Round函数是4舍6入,5奇进偶不进,这样在一大堆需要四舍五入的数字相加时,可以减少误差增加精度,很多语言的round函数都是这样定义的。 
56.5,小数5前是6,偶数,因此不进,舍为56。如果一定需要四舍五入的话,用类似int(n+0.5)的方法。
4:进度条,并显示百分比
 
<td bgcolor="#FFFFFF"><div align="left">&nbsp;<img src= image/vote.gif width=<%=int((rs(2)/total)*100)%> height=9><font face="Geneva, Arial, Helvetica, sans-serif">&nbsp;<%=round(rs(2)/total*100,2)%>%</font></div></td>
5:复制代码的JS
<SCRIPT language=JavaScript>
<!--

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function JM_cc(ob){
var obj=MM_findObj(ob); if (obj) { 
obj.select();js
=obj.createTextRange();js.execCommand("Copy");}
alert(
"复制成功!")
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d
=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  
if(!&& document.getElementById) x=document.getElementById(n); return x;
}
//-->
</SCRIPT>

调用时:
<input name="Button" type="button" class="button" value="点击复制代码" onClick="JM_cc('js_1')">
js_1为一个
<textarea 
<textarea cols="80" rows="8" class="input1" name="js_1" wrap=VIRTUAL><iframe border="0" marginwidth="0" scrolling="No" marginheight="0" src="您网站的绝对地址/Vote/?id=<%=request("id")%>" width="200" height="200" frameborder="no"></iframe></textarea>

转载于:https://www.cnblogs.com/xocom/articles/asp.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值