<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>查詢</title>
</head>
<body bgcolor="#00CCFF">
<form method="POST" action="Query.asp?ToPage=1">
  <p>你可以用以下的方式找到你想要的水果，按[開始查詢]按鈕查詢：</p>
  <p>水果編號 ：                                     
  <input type="text" name="Prod_num" size="8"> <select size="1" name="D2">                                        
  <option>且</option>                                  
  <option>或</option>                                  
  </select>&nbsp;&nbsp; 農會名稱：<input type="text" name="Supp_name" size="13"><select size="1" name="D3">                                        
  <option>且</option>                                        
  <option>或</option>                                        
  </select>                                     
  &nbsp;                                       
</p>                                                                 
  <p>                                     
  水果名稱：<input type="text" name="Prod_name" size="15">&nbsp;&nbsp;                              
  排序方法：<select size="1" name="Order">                              
    <option value="編號">編號</option>                              
    <option>農會</option>                              
    <option>水果</option>                              
  </select>&nbsp; <input type="submit" value="開始查詢" name="B1"><input type="reset" value="重新設定" name="B2"></p>                                                                   
</form>                                                                   
<hr>                                                        
<!-- #include file="db.txt" -->                                                        
<%                                                                  
If Request("B1")="開始查詢" then                                                                  
SQL_Statement="Select prod_num 水果編號,S.supp_name 供應農會,description 水果名稱, unit_price 單價,image 產品介紹連結"                                            
SQL_Statement=SQL_Statement & ",P.supp_code from  Products P,Suppliers S where P.supp_code=S.supp_code "                                            
  if Request("Prod_num")<> Empty then                                                                
     SQL_Statement=SQL_Statement & "and (P.Prod_num=" & Request("Prod_num")                                                                
  end if                                                                  
  if Request("Supp_name")<> Empty then                                           
     if (Request("D2")="或" and Request("Prod_num")<> Empty) then                                      
       conj=" or "                                      
      elseif  Request("Prod_num")= Empty then     
       conj=" and ("                                       
      else      
      conj=" and "                                       
    end if                                                          
     SQL_Statement=SQL_Statement & conj & "S.Supp_name like '%" & Request("Supp_name")&"%'"                                                         
  end if                                                                  
  if Request("Prod_name")<> Empty then                                                                
     if (Request("D2")="或" and Request("Prod_num")<> Empty) or (Request("D3")="或" and Request("Supp_name")<> Empty) then                                     
       conj=" or "                                      
      elseif  Request("Supp_name")= Empty and Request("Prod_num")= Empty then     
       conj=" and ("                                       
      else      
      conj=" and "                                       
     end if                                                          
                                     
     SQL_Statement=SQL_Statement & conj & "P.description like '%" & Request("Prod_name")&"%'"                                                         
  end if                                      
  SQL_Statement=SQL_Statement & ")"       
  Select case Request("Order")                      
   Case "編號"                        
     SQL_Statement=SQL_Statement & " Order By Prod_num"                          
   Case "供應商"                      
     SQL_Statement=SQL_Statement & " Order By Supp_Name"                          
  	 Case "產品"                    
     SQL_Statement=SQL_Statement & " Order By Description"                          
  end Select                          
 RS.Open SQL_Statement,DBC,3                                                                
 RS.PageSize = 8                                                             
 set Session("RS")=RS                                                        
 DBError                                                        
End if                                                        
if Session("RS").RecordCount<1 or  CInt(Request("ToPage"))=0 then                                                        
  Response.Write "請輸入正確查詢條件!"                                                    
else                                                    
Act_file="Query.asp"                                                                
if Not IsEmpty(Request("ToPage")) then                                                             
	ToPage = CInt(Request("ToPage"))                                                              
	if ToPage > Session("RS").PageCount then                                                              
		Session("RS").AbsolutePage = Session("RS").PageCount                                                              
	elseif ToPage <= 0 then                                                              
		Session("RS").AbsolutePage = 1                                                              
	else                                                             
		Session("RS").AbsolutePage = ToPage                                                              
	end if                                                             
End if                                                             
Current_Page = Session("RS").AbsolutePage                                                              
%>                                                             
<H3>目前的分頁狀況為<FONT SIZE = 4 COLOR = red>                                                             
<% = Current_Page %>/<% = Session("RS").PageCount %>
</FONT>頁，請按[訂購編號]即可將水果放入購物車，等待結帳。                                                             
</H3>                                                             
<%                                                             
 Display_Page Session("RS"),Current_page,2                                         
%>                                                             
<TABLE>                                                             
<TR valign=baseline align=center>                                                             
<%                                                             
if Current_Page <> 1 then                                                             
	%>                                                             
	<TD Width=150>                                                             
	<A Href=<%=Act_file%>?ToPage=<% = 1%>>第一頁</A>                                                             
	</TD>                                                             
	<TD	Width=150>                                                             
	<A Href=<%=Act_file%>?ToPage=<% = Current_Page - 1%>>上一頁</A>                                                             
	</TD>                                                             
	<%                                                             
end if                                                             
if Current_Page <> Session("RS").PageCount then                                                             
	%>	                                                             
	<TD Width=150>                                                             
	<A Href=<%=Act_file%>?ToPage=<% = Current_Page + 1%>>下一頁</A>                                                             
	</TD>                                                               
	<TD	Width=150>                                                             
	<A Href=<%=Act_file%>?ToPage=<% = Session("RS").PageCount%>>最後一頁</A>                                                             
	</TD>                                                             
	<%                                                             
end if                                  
%>                                                             
<% if Session("RS").PageCount >1 then %>          
<TD	Width=150>                                                             
<FORM action="<%=Act_file%>" method=POST>                                                             
到                                                                
<INPUT type="text" name=ToPage style="HEIGHT: 25px; WIDTH: 40px"                                                               
 value=<% = Current_Page%>> 頁                                                               
</FORM></TD>          
<% end if%>          
</TR>                 
</TABLE>                                                               
<% End if%>                                                        
</body>                                                                   
</html>                                                                   
