本人整理好的一些ASP函数,提供给初学ASP的朋友们使用

ASP 专栏收录该内容
7 篇文章 0 订阅
<%
'============================textarea显示用===================================
function htmlencode1(fString) 
if fString<>"" and not isnull(fString) then
  fString = replace(fString, "&gt;", ">")
  fString = replace(fString, "&lt;", "<")
  fString = Replace(fString, "&nbsp;", chr(32))
  fString = Replace(fString, "</p><p>", CHR(10) & CHR(10))
  fString = Replace(fString, "<br>", CHR(10))
  htmlencode1=fString
else
  htmlencode1="" 
end if
end function
'===========================页面显示用===========================================
function htmlencode2(fString)  
if fString<>"" and not isnull(fString) then
  fString = replace(fString, ">", "&gt;")
  fString = replace(fString, "<", "&lt;")
  fString = Replace(fString, chr(32), "&nbsp;")
  fString = Replace(fString, CHR(10) & CHR(10), "</p><p>")
  fString = Replace(fString, CHR(10), "<br>")
  htmlencode2=fString
else
  htmlencode2=""
end if
end function
'====================================给指定的字符串添加字体颜色=====================================
function FontStyle(fString,strings)
 if fString<>"" and not isnull(fString) then   '
  fString = replace(fString,strings, "<SPAN style='COLOR: red; FONT-SIZE: 10pt; FONT-FAMILY: 黑体'>"&strings&"</SPAN>")
  FontStyle=fString
 else
    FontStyle=""
 end if
end function
'================================取出指定字符串前后的字符串方法=====================================
function GetStrs(str1,CharFlag,Dflag)
dim tmpstr
if Dflag=0 then'取左
  pos1=instr(str1,charFlag)
  if pos1<=20 then
      tmpstr=left(str1,pos1-1)
  else
     tmpstr=mid(str1,pos1-20,20)
  end if
else            '取右
   pos1=instr(str1,charFlag)+len(charFlag)
   if len(str1)-pos1<=20 then
      tmpstr=right(str1,len(str1)-pos1)
   else
      tmpstr=mid(str1,pos1+1,20)
   end if
end if
GetStrs=tmpstr
end function

function getfilename(str)
 pos=instr(str,".")
 if str<>"" then
  str=mid(str,pos,len(str))
 end if
 getfilename=str
end function
'======================================================删除文件=====================================
function delfile(filepath)
 imangepath=trim(filepath)
 path=server.MapPath(imangepath)
 SET fs=server.CreateObject("Scripting.FileSystemObject")
 if FS.FileExists(path) then
  FS.DeleteFile(path)      
 end if  
    set fs=nothing
end function
'===================================得到真实的客户端IP======================================
Public Function GetClientIP()
dim uIpAddr
' 本函数参考webcn.Net/AspHouse 文献<取真实的客户IP>
uIpAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If uIpAddr = "" Then uIpAddr = Request.ServerVariables("REMOTE_ADDR")
GetClientIP = uIpAddr
uIpAddr = ""
End function

'======================================用Jmail发送邮件===========================================
Function sendMail(names,message,email)
 set mymail=server.CreateObject("jmail.message")
 mymail.MailServerPassWord ="gwd3209" '发信授权邮件密码
 mymail.MailServerUserName ="gwd3209@163.com" '发信授权邮件名称
 mymail.ContentType = "text/html" '(是否支持html,如不要就去掉此行)
 mymail.Charset="gb2312" '使用字符集,不用改的  
 mymail.AddRecipient  "gwd3209@163.com"'收件人邮箱chg@haigaochem.com
 mymail.Body= message  '邮件正文
 'mymail.Body= "密码:"&pass&"/n"  '邮件正文
 mymail.From=""&email '发件人邮箱s
 mymail.Subject=""&names&"的意见和建议!!!"'邮件标题
 mymail.Send "smtp.163.com",false '邮件发送服务器
 set mymail = nothing
end Function
'========================================根据ID得到字符串========================================
function  getStr(getID)  
 dim  result 
 result=""     
   select  case  getID
    case  1 
          result="一天" 
      case  2  
         result="一星期"  
      case  3
   result="一个月"
       case  4
   result="三个月"
          case  5
   result="半年"
    case  6
   result="一年"
    end  select 
 getStr=result  
end  function
'========================================四舍五入函数==============================================
public function Round_(v,p)
     dim tempInt,tempdot,temp,Power
   temp=v
      Power=10^p
   tempInt=int(temp*power)
   tempDot=temp*Power-tempInt
   if tempdot>=0.499 then
   'tempdot一般不会恰好等于0.5,等于0.499999999999**,这个在数值计算中有详细介绍
   '我当时也没有写对,后来alert调试时候,忽然猛的想起来,当初程序员考试中说过这个问题,记忆力减退啊
    tempInt=tempInt+1
   end if
   Round_=CSng(tempInt/power)
   '因为有时候计算需要用到,如果不转换,会导致计算不出来,而且这种情况不是恒定的,我晕,所以干脆,强行转换
   end function
'==========================================SQL函数安全=================================================  
  function SqlShouldBeSafe()

    dim str_
    dim arra(1000)
    dim arrb(1000)
    dim strlen_
    dim k_
    dim i_
    dim tmpA_
    dim tmpB_
    dim tmp_
    str_ = request.QueryString
 if str_<>"" then
        strlen_ = len(str_)
        k_=1
        for i_=1 to strlen_
            if mid(str_,i_,1)="%" then
             tmpA_=mid(str_,i_+1,1)
          tmpB_=mid(str_,i_+2,1)     
       if ( (asc(tmpA_)>=48 and asc(tmpA_)<=57) or (asc(tmpA_)>=65 and asc(tmpA_)<=70) or (asc(tmpA_)>=97 and asc(tmpA_)<=102) ) and (  (asc(tmpB_)>=48 and asc(tmpB_)<=57) or (asc(tmpB_)>=65 and asc(tmpB_)<=70) or (asc(tmpB_)>=97 and asc(tmpB_)<=102)  ) then        
           tmp_ = chr(cint(tmpA_)*16+cint(tmpB_))
              arra(k_)="%" & tmpA_ & tmpB_
              arrb(k_)=LCase(tmp_)
              k_ = k_ + 1     
       end if
   end if
        next
        for i_=1 to k_
            str_ = replace(str_,arra(i_),arrb(i_))
        next 
        If Instr(str_,"select ") or Instr(str_,"insert ") or Instr(str_,"delete from") or Instr(str_,"count(") or Instr(str_,"drop table") or Instr(str_,"update ") or Instr(str_,"truncate ") or Instr(str_,"asc(") or Instr(str_,"mid(") or Instr(str_,"char(") or Instr(str_,"xp_cmdshell") or Instr(str_,"exec master") or Instr(str_,"net localgroup administrators") or Instr(str_,":") or Instr(str_,"net user") or Instr(str_,"'") or Instr(str_," or ")  then
            response.Write "<script language=""javascript"">alert('出错了');window.opener=null;window.close();</script>"
         response.End()
        end if
 end if 
end function 
'==================================取到浏览器版本转换字符串========================================
function browser()
 dim text 
 text = Request.ServerVariables("HTTP_USER_AGENT")
 if Instr(text,"MSIE 5.5")>0 then
  browser="IE 5.5"
 elseif Instr(text,"MSIE 6.0")>0 then
  browser="IE 6.0"
 elseif Instr(text,"MSIE 5.01")>0 then
  browser="IE 5.01"
 elseif Instr(text,"MSIE 5.0")>0 then
  browser="IE 5.00"
 elseif Instr(text,"MSIE 4.0")>0 then
  browser="IE 4.01"
  else
  browser="未知"
 end if
end function
'================================取到系统脚本转换字符串==================================
function system(text)
 if Instr(text,"NT 5.1")>0 then
  system=system+"Windows XP"
 elseif Instr(text,"NT 5")>0 then
  system=system+"Windows 2000"
 elseif Instr(text,"NT 4")>0 then
  system=system+"Windows NT4"
 elseif Instr(text,"4.9")>0 then
  system=system+"Windows ME"
 elseif Instr(text,"98")>0 then
  system=system+"Windows 98"
 elseif Instr(text,"95")>0 then
  system=system+"Windows 95"
  else
  system=system+"未知"
 end if
end function
'==================================AutoSelectsendEmail邮件功能=============================
Function AutoSelectsendEmail()
 emailname=l_title
 on error resume next
  if h_selectemail=0 then
 sendmsg="系统未开启邮件功能<br>"
 
elseif h_selectemail=1 then
 Set objcdonts = Server.CreateObject("CDONTS.NewMail")
 objcdonts.From =h_email
 objcdonts.To =emailto
 objcdonts.Subject =emailtopic
 objcdonts.BodyFormat = 0
 objcdonts.MailFormat = 0
 objcdonts.Body =emailbody
 objcdonts.Send
 Set objcdonts = Nothing 
 
elseif h_selectemail=2 then
 
 set Jmail=server.CreateObject ("Jmail.message")
 Jmail.Silent=true
 Jmail.fromname=emailname
 Jmail.from=h_email
 Jmail.AddRecipient (emailto)
 Jmail.Subject= emailtopic
 Jmail.body=emailbody
    JMail.MailServerUserName ="pwsite"  'SMTP服务器登录用户名
    JMail.MailServerPassWord ="xxxxxx"   'SMTP服务器登录密码
    JMail.send(h_emailserver)
   

elseif h_selectemail=3 then
 Set mailer=Server.CreateObject("ASPMAIL.ASPMailCtrl.1") 
 recipient=emailto
 sender=h_email
 subject=emailtopic
 message=emailbody
 mailserver=h_emailserver
 result=mailer.SendMail(mailserver, recipient, sender, subject, message)
 end if
 
 if err then
 SendMail=err.description
 err.clear
 else
 SendMail="OK"
 end if
end function

'===================================图表函数=====================================
function table3(total,table_x,table_y,all_width,all_height,table_type)
'参数含义(传递的数组,横坐标,纵坐标,图表的宽度,图表的高度,图表的类型)
'纯ASP代码生成图表函数3——饼图
tb_height=30
dim tb_color(7,2)
tb_color(1,1)="#d1ffd1"
tb_color(2,1)="#ffbbbb"
tb_color(3,1)="#ffe3bb"
tb_color(4,1)="#cff4f3"
tb_color(5,1)="#d9d9e5"
tb_color(6,1)="#ffc7ab"
tb_color(7,1)="#ecffb7"

tb_color(1,2)="#00ff00"
tb_color(2,2)="#ff0000"
tb_color(3,2)="#ff9900"
tb_color(4,2)="#33cccc"
tb_color(5,2)="#666699"
tb_color(6,2)="#993300"
tb_color(7,2)="#99cc00"

total_no=ubound(total,1)
totalpie=0
for i=1 to total_no
 totalpie=totalpie+total(i,1)
next

PreAngle=0
for i=1 to total_no
 response.write "<v:shape id='_x0000_s1025'  alt='' style='position:absolute;left:"&table_x&"px;top:"&table_y&"px;width:"&all_width&"px;height:"&all_height&"px;z-index:1' coordsize='1500,1400' o:spt='100' adj='0,,0' path='m750,700ae750,700,750,700,"&int(23592960*PreAngle)&","&int(23592960*total(i,1)/totalpie)&"xe' fillcolor='"&tb_color(i,1)&"' strokecolor='#FFFFFF'><v:fill color2='"&tb_color(i,2)&"' rotate='t' focus='100%' type='gradient'/><v:stroke joinstyle='round'/><v:formulas/><v:path o:connecttype='segments'/></v:shape>"&CHr(13)
 PreAngle=PreAngle+total(i,1)/totalpie
next

if table_type="A" then
 response.write "<v:rect id='_x0000_s1025' style='position:absolute;left:"&table_x+all_width+20&"px;top:"&table_y+20&"px;width:100px;height:"&total_no*tb_height+20&"px;z-index:1'/>"
for i=1 to total_no
 response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&table_x+all_width+25&"px;top:"&table_y+30+(i-1)*tb_height&"px;width:60px;height:"&tb_height&"px;z-index:1'>"
 response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>"&total(i,0)&"</td></tr></table></v:textbox></v:shape>"
 response.write "<v:rect id='_x0000_s1040' alt='' style='position:absolute;left:"&table_x+all_width+80&"px;top:"&table_y+30+(i-1)*tb_height+3&"px;width:30px;height:20px;z-index:1' fillcolor='"&tb_color(i,1)&"'><v:fill color2='"&tb_color(i,2)&"' rotate='t' focus='100%' type='gradient'/></v:rect>"
'显示比例数
' response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&table_x+all_width+110&"px;top:"&table_y+30+(i-1)*tb_height&"px;width:60px;height:"&tb_height&"px;z-index:1'>"
' response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>"&formatnumber(total(i,1)*100/totalpie,2,-1)&"%</td></tr></table></v:textbox></v:shape>"
next
end if

if table_type="B" then
pie=3.14159265358979
TempPie=0
for i=1 to total_no
 TempAngle=pie*2*(total(i,1)/(TotalPie*2)+TempPie)
 x1=table_x+all_width/2+cos(TempAngle)*all_width*3/8
 y1=table_y+all_height/2-sin(TempAngle)*all_height*3/8
 x2=table_x+all_width/2+cos(TempAngle)*all_width*3/4
 y2=table_y+all_height/2-sin(TempAngle)*all_height*3/4
 if x2>table_x+all_width/2 then
  x3=x2+20
  x4=x3
 else
  x3=x2-20
  x4=x3-100
 end if
 response.write "<v:oval id='_x0000_s1027' style='position:absolute;left:"&x1-2&"px;top:"&y1-2&"px;width:4px;height:4px; z-index:2' fillcolor='#111111' strokecolor='#111111'/>"&CHR(13)
 response.write "<v:line id='_x0000_s1025' alt='' style='position:absolute;left:0;text-align:left;top:0;z-index:1' from='"&x1&"px,"&y1&"px' to='"&x2&"px,"&y2&"px' coordsize='21600,21600' strokecolor='#111111' strokeweight='1px'></v:line>"
 response.write "<v:line id='_x0000_s1025' alt='' style='position:absolute;left:0;text-align:left;top:0;z-index:1' from='"&x2&"px,"&y2&"px' to='"&x3&"px,"&y2&"px' coordsize='21600,21600' strokecolor='#111111' strokeweight='1px'></v:line>"
 response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&x4&"px;top:"&y2-10&"px;width:100px;height:20px;z-index:1'>"
 response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>"&total(i,0)&" "&formatnumber(total(i,1)*100/totalpie,2,-1)&"%</td></tr></table></v:textbox></v:shape>"
 TempPie=TempPie+total(i,1)/TotalPie
next
end if
end function
%>

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

guoweidong

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值