<%dim action,searchkey,categoryid,jiage,dijiage
if Not isNumeric(request.form("dijiage")) then
dijiage = 0
end if
if Not isNumeric(request.form("jiage")) then
jiage = 0
end if
jiage = 0
dijiage = 0

categoryid=Cint(request.form("categoryid"))
jiage= FormatSQL(SafeRequest("jiage",1))
dijiage= FormatSQL(SafeRequest("dijiage",1))
action= FormatSQL(SafeRequest("action",1))
searchkey=FormatSQL(SafeRequest("searchkey",0))
If dijiage > jiage Then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('搜索价格下限大于价格上限，请正确输入！');history.go(-1);</script>"
response.End
end if
if categoryid="" then categoryid= FormatSQL(SafeRequest("categoryid",1))
if action="" then action=Cint(request.form("action"))
if searchkey="" then searchkey=trim(request.form("searchkey"))%>
<%call sss()%>
<link href="b2b_includefile/css.css" rel="stylesheet" type="text/css">


<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" align="center" bgcolor="#FFFFFF">
<TR><TD HEIGHT="30">
    <%if (searchkey="") and (dijiage="") and (jiage="") then
		response.write "对不起，请您输入查询关键字"
		response.End
	else
		response.write "您查询的关健字是：<font color=red>"&searchkey&"</font>"
	end if%> </TD>
</tr> </table>
<%'开始分页
				Const MaxPerPage=20
   				dim totalPut   
   				dim CurrentPage
   				dim TotalPages
   				dim j
   				dim sql
    				if Not isempty(request("page")) then
      				currentPage=Cint(request("page"))
   				else
      				currentPage=1
   				end if 
				
set rs=server.CreateObject("adodb.recordset")
if jiage=0 then  '//普通查询
select case action
case "1"
	select case trim(request("radiobuttonPrice"))
	case "1"
		jiage=20
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and name like '%"&searchkey&"%' and price2 < "&jiage,conn,1,1	
	case "2"
		dijiage=20
		jiage=40	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and name like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1	
	case "3"
		dijiage=40
		jiage=70
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and name like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "4"
		dijiage=70
		jiage=120	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and name like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "5"	
		dijiage=120
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and name like '%"&searchkey&"%' and price2> "&dijiage,conn,1,1
	case else
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and name like '%"&searchkey&"%' ",conn,1,1
	end select
case "2"
	select case trim(request("radiobuttonPrice"))
	case "1"
		jiage=20
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and mark like '%"&searchkey&"%' and price2 < "&jiage,conn,1,1	
	case "2"
		dijiage=20
		jiage=40	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and mark like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1	
	case "3"
		dijiage=40
		jiage=70
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and mark like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "4"
		dijiage=70
		jiage=120	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and mark like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "5"	
		dijiage=120
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and mark like '%"&searchkey&"%' and price2> "&dijiage,conn,1,1
	case else
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and mark like '%"&searchkey&"%' ",conn,1,1
	end select
case "3"
	select case trim(request("radiobuttonPrice"))
	case "1"
		jiage=20
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and introduce like '%"&searchkey&"%' and price2 < "&jiage,conn,1,1	
	case "2"
		dijiage=20
		jiage=40	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and introduce like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1	
	case "3"
		dijiage=40
		jiage=70
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and introduce like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "4"
		dijiage=70
		jiage=120	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and introduce like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "5"	
		dijiage=120
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and introduce like '%"&searchkey&"%' and price2> "&dijiage,conn,1,1
	case else
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and introduce like '%"&searchkey&"%' ",conn,1,1
	end select
case "4"
	select case trim(request("radiobuttonPrice"))
	case "1"
		jiage=20
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' and price2 < "&jiage,conn,1,1	
	case "2"
		dijiage=20
		jiage=40	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1	
	case "3"
		dijiage=40
		jiage=70
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "4"
		dijiage=70
		jiage=120	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "5"	
		dijiage=120
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' and price2> "&dijiage,conn,1,1
	case else
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' ",conn,1,1
	end select
	'rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' ",conn,1,1
case "5" 
	select case trim(request("radiobuttonPrice"))
	case "1"
		jiage=20
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' and price2 < "&jiage,conn,1,1	
	case "2"
		dijiage=20
		jiage=40	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1	
	case "3"
		dijiage=40
		jiage=70
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "4"
		dijiage=70
		jiage=120	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' and price2> "&dijiage&" and price2 < "&jiage,conn,1,1
	case "5"	
		dijiage=120
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' and price2> "&dijiage,conn,1,1
	case else
		rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' ",conn,1,1
	end select
	'rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' ",conn,1,1
case else
	select case trim(request("radiobuttonPrice"))
	case "1"
		jiage=20
		rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and price2> "&dijiage&"and price2< "&jiage,conn,1,1 	
	case "2"
		dijiage=20
		jiage=40	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and price2> "&dijiage&"and price2< "&jiage,conn,1,1 	
	case "3"
		dijiage=40
		jiage=70
		rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and price2> "&dijiage&"and price2< "&jiage,conn,1,1 
	case "4"
		dijiage=70
		jiage=120	
		rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and price2> "&dijiage&"and price2< "&jiage,conn,1,1 
	case "5"	
		dijiage=120
		rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and price2> "&dijiage,conn,1,1 
	case else
		rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3",conn,1,1 
	end select
	'rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and price2> "&dijiage&"and price2< "&jiage,conn,1,1 
end select
else
'//高级查询
if categoryid<>0 then  '//判断查询分类,分类不为空。  
select case action
case "1"
rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and name like '%"&searchkey&"%' and price2> "&dijiage&" price2 < "&jiage&" and categoryid="&categoryid,conn,1,1
case "2"
rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and mark like '%"&searchkey&"%' and price2> "&dijiage&" and price2< "&jiage&" and categoryid="&categoryid,conn,1,1
case "3"
rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and introduce like '%"&searchkey&"%'  and price2> "&dijiage&"and price2< "&jiage&" and categoryid="&categoryid,conn,1,1
case "4"
rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' and price2> "&dijiage&" and price2=< "&jiage&" and categoryid="&categoryid,conn,1,1
case "5"
rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' and price2> "&dijiage&" and price2=< "&jiage&" and categoryid="&categoryid,conn,1,1
case else
rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and price2> "&dijiage&"and price2< "&jiage,conn,1,1
end select
else
'//分类为空。
select case action
case "1"
rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and name like '%"&searchkey&"%' and price2> "&dijiage&" and price2< "&jiage,conn,1,1
case "2"
rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and mark like '%"&searchkey&"%' and price2> "&dijiage&" and price2< "&jiage,conn,1,1
case "3"
rs.open "select id,name,mark,introduce,price1,price2,productdate,adddate,pic,code,spic from product where recommend<>3 and introduce like '%"&searchkey&"%' and price2> "&dijiage&" and price2< "&jiage,conn,1,1
case "4"
rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and detail like '%"&searchkey&"%' and price2> "&dijiage&"and price2< "&jiage,conn,1,1
case "5"
rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and code like '%"&searchkey&"%' and price2> "&dijiage&"and price2< "&jiage,conn,1,1
case else
rs.open "select id,name,mark,introduce,price1,price2,productdate,detail,adddate,pic,code,spic from product where recommend<>3 and price2> "&dijiage&"and price2< "&jiage,conn,1,1
end select
end if
end if
				
  				if rs.eof And rs.bof then
       				Response.Write "<p align='center' > 对不起，没有查询到您需要的商品！</p>"
   				else
	  				totalPut=rs.recordcount

      				if currentpage<1 then
          				currentpage=1
      				end if

      				if (currentpage-1)*MaxPerPage>totalput then
	   					if (totalPut mod MaxPerPage)=0 then
	     					currentpage= totalPut \ MaxPerPage
	   					else
	      					currentpage= totalPut \ MaxPerPage + 1
	   					end if
      				end if

       				if currentPage=1 then
            			showContent
            			showpage totalput,MaxPerPage,"research.asp"
       				else
          				if (currentPage-1)*MaxPerPage<totalPut then
            				rs.move  (currentPage-1)*MaxPerPage
            				dim bookmark
            				bookmark=rs.bookmark
            				showContent
             				showpage totalput,MaxPerPage,"research.asp"
        				else
	        				currentPage=1
           					showContent
           					showpage totalput,MaxPerPage,"research.asp"
	      				end if
	   				end if
   				   				end if

   				sub showContent
       			dim i
	   			i=0

			%> 
<table width=100% border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#f2f2f2"> 
<tr align="center" height=30> 
<td width="16%" bgcolor="#f7f7f7"><FONT COLOR="#000000">商品名称</FONT></td>
<td width="8%" bgcolor="#f7f7f7"><FONT COLOR="#000000">商品品牌</FONT></td>
<td width="17%" bgcolor="#f7f7f7"><font color="#000000">商品编号</font></td>
<td width="7%" bgcolor="#f7f7f7"><FONT COLOR="#000000">市场价</FONT></td>
<td width="7%" bgcolor="#f7f7f7"><FONT COLOR="#000000">会员价</FONT></td>
</tr> 
<%do while not rs.eof%> 
<tr align="center" bgcolor="#FFFFFF" height=30> 
<%Dim num1 '//判断数字奇偶
num1 = Num1+1
If num1 Mod 2 = 0 Then%> 
<td align="center"><table width="100%"  border="0" cellspacing="2" cellpadding="3">
  <tr>
    <td align="center" bgcolor="#F7F7F7"><%response.write "<a href=b2b_cpinfo.asp?id="&trim(rs("id"))&" target=_blank>"&trim(rs("name"))&"</a>"%></td>
  </tr>
  <tr>
    <td align="center"><A  HREF=b2b_cpinfo.asp?id=<%=rs("id")%> TARGET=_blank>
<IMG SRC="<%if trim(rs("spic"))="" then %>images/emptybook.gif<%else%>image\<% = trim(rs("spic")) %>"<% end if%> BORDER=0 width="<% = webimg9 %>" height="<% = webimg10 %>"></a></td>
  </tr>
</table></td>
<td><%=trim(rs("mark"))%></td>
<td v> <%=trim(rs("code"))%></td>
<td><%=rs("price1")%>元</td>
<td><font color=#FF6600><%=rs("price2") %>元</font></div></td>
<%else%> 
<td width="3%" align="left"><table width="100%"  border="0" cellspacing="2" cellpadding="3">
  <tr>
    <td align="center" bgcolor="#F2F2F2"><%response.write "<a href=b2b_cpinfo.asp?id="&trim(rs("id"))&" target=_blank>"&trim(rs("name"))&"</a>"%></td>
  </tr>
  <tr>
    <td align="center"><A  HREF=b2b_cpinfo.asp?id=<%=rs("id")%> TARGET=_blank>
<IMG SRC="<%if trim(rs("spic"))="" then %>images/emptybook.gif<%else%>image\<% = trim(rs("spic")) %>"<% end if%> BORDER=0 width="<% = webimg9 %>" height="<% = webimg10 %>"></a></td>
  </tr>
</table>
</td>
<td><%=trim(rs("mark"))%></td>
<td><%=trim(rs("code"))%></td>
<td><%=rs("price1")%>元</td>
<td><font color=#FF6600><%=rs("price2")%>元</font></td>
<%end if%> </tr> 
<%i=i+1
		if i>=MaxPerPage then Exit Do
		rs.movenext
  loop
  rs.close
  set rs=nothing%> </table>
<%  
				End Sub   
  
				Function showpage(totalnumber,maxperpage,filename)  
  				Dim n
  				
				If totalnumber Mod maxperpage=0 Then  
					n= totalnumber \ maxperpage  
				Else
					n= totalnumber \ maxperpage+1  
				End If %>
				
				<form method=Post action=<% = filename %>?searchkey=<% = searchkey %>&action=<% = action %>&categoryid=<% = categoryid %>&jiage=<% = jiage %>>
	    		<%	If CurrentPage<2 Then  %>
				<div align="center">首 页 上一页
				<% Else  %>
				<div align="center"><a href=<% = filename %>?page=1&searchkey=<% = searchkey %>&action=<% = action %>&categoryid=<% = categoryid %>&jiage=<% = jiage %>&dijiage=<% = dijiage %>>首 页</a>
				<a href=<% = filename %>?page=<% = CurrentPage-1 %>&searchkey=<% = searchkey %>&action=<% = action %>&categoryid=<% = categoryid %>&jiage=<% = jiage %>&dijiage=<% = dijiage %>>上一页</a>
				<%	End If
				If n-currentpage<1 Then  %>
				下一页 末 页
				
				<%	Else  %>
				<a href=<% = filename %>?page=<% = (CurrentPage+1) %>&searchkey=<% = searchkey %>&action=<% = action %>&categoryid=<% = categoryid %>&jiage=<% = jiage %>&dijiage=<% = dijiage %>>下一页</a> 
				<a href=<% = filename %>?page=<% = n %>&searchkey=<% = searchkey %>&action=<% = action %>&categoryid=<% = categoryid %>&jiage=<% = jiage %>&dijiage=<% = dijiage %>>末 页</a>
				<%	End If  %>
				 第&nbsp;<b><% = CurrentPage %></b>&nbsp;页 共&nbsp;<b><% = n %></b>&nbsp;页
				 共查询到&nbsp;<b><% = totalnumber %></b>&nbsp;件商品
				转到第<input type="text" name="page" size=2 maxlength=10 value=<% = currentpage %>>
				页<input type='submit'  class='input_bot' value='跳转' name='cndok'>
				</div></form>
				<%
				End Function  
sub sss() 
if action="1" then
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from keyname where keyname='"&searchkey&"' ",conn,1,3
if rs.eof and rs.bof then
rs.close
rs.open "select * from keyname",conn,1,3
rs.addnew
rs("keyname")=searchkey
rs("keyorder")=1
rs.update
rs.close
set rs=nothing
else
rs("keyorder")=rs("keyorder")+1
rs.update
rs.close
set rs=nothing
end if
end if
end sub%>
