<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../KS_Cls/Kesion.CommonCls.asp"-->
<!--#include file="../KS_Cls/Kesion.Label.CommonCls.asp"-->
<!--#include file="../KS_Cls/Template.asp"-->
<!--#include file="../KS_Cls/Kesion.IFCls.asp"-->
<%

Dim KSCls
Set KSCls = New GroupBuyIndex
KSCls.Kesion()
Set KSCls = Nothing

Class GroupBuyIndex
        Private KS, KSR,KSUser,Param
		Private GroupBuy,K,CurrentPage,totalPut,MaxPerPage
		Private Sub Class_Initialize()
		 If (Not Response.IsClientConnected)Then
			Response.Clear
			Response.End
		 End If
		  MaxPerPage=10         rem 定义每页显示条数
		  Set KS=New PublicCls
		  Set KSR = New Refresh
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		End Sub
		Public Sub Kesion()
		  Call showmain()
		End Sub
		%>
		<!--#include file="../KS_Cls/Kesion.IFCls.asp"-->
		<%
		Sub ShowMain()
			 Dim FileContent
			 FileContent = KSR.LoadTemplate(KS.Setting(137))    
			 FCls.RefreshType = "groupbyIndex" '设置刷新类型，以便取得当前位置导航等
			 FCls.RefreshFolderID = "0" '设置当前刷新目录ID 为"0" 以取得通用标签
			 GetQueryParam
			 LoadGroupBuyList
			 Immediate=false
			 Scan FileContent
			 Templates=KSR.KSLabelReplaceAll(Templates)
			 Response.write RexHtml_IF(Templates)
		End Sub
		
		
		Sub ParseArea(sTokenName, sTemplate)
			Select Case lcase(sTokenName)
			 case "groupbuylist"
			  If IsArray(GroupBuy) Then
			    For K=0 To Ubound(GroupBuy,2)
				  Scan sTemplate
				Next
			  End If
			End Select 
        End Sub 
		
		Sub ParseNode(sTokenType, sTokenName)
			Select Case lcase(sTokenType)
			   case"groupbuy"
					 Select  case lcase(sTokenName)
					  case "id" echo GroupBuy(0,k)
					  case "subject" echo GroupBuy(1,k)
					  case "date"  echo Year(GroupBuy(2,k)) & "年" & Month(GroupBuy(2,k)) & "月" & Day(GroupBuy(2,k)) & "日"
					  case "time" echo GroupBuy(3,k)
					  case "address" echo GroupBuy(4,k)
					  case "adddate" echo GroupBuy(5,k)
					  case "intro" echo KS.GotTopic(KS.LoseHtml(GroupBuy(6,k)),100)
					  case "photourl" if GroupBuy(7,k)="" or isnull(GroupBuy(7,k)) Then Echo "../images/nopic.gif" Else Echo GroupBuy(7,k)
					 end select
			  case "foot"
			         if sTokenName="showpage" then
				      Echo ShowPagePara(totalput, MaxPerPage, "", true, "条", CurrentPage,KS.QueryParam("page"))
					 end if
		    End Select 
        End Sub 
		
		
		Sub GetQueryParam()
		  If KS.S("page") <> "" Then
			  CurrentPage = CInt(Request("page"))
		  Else
			  CurrentPage = 1
		  End If
		End Sub

		
		Sub LoadGroupBuyList()
		 Param=" Where Endtf=0 and Locked=0"
		 If KS.S("T")<>"" Then Param=Param & " And TypeName='" & KS.S("T") & "'"
		 
		 If KS.S("KeyWord")<>"" Then Param=Param & " and (intro like '%" & Trim(KS.S("KeyWord")) & "%' or subject like '%" & Trim(KS.S("KeyWord")) & "%')"
		 Dim RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
		 RS.Open "Select ID,Subject,ActiveDate,ActiveTime,address,adddate,intro,photourl From KS_GroupBuy " & Param & " Order By Id Desc",Conn,1,1
		 If Not RS.Eof Then
			      TotalPut= rs.recordcount
				  If CurrentPage < 1 Then CurrentPage = 1
				  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 and (CurrentPage - 1) * MaxPerPage < totalPut Then
									RS.Move (CurrentPage - 1) * MaxPerPage
							Else
									CurrentPage = 1
							End If
							GroupBuy=RS.GetRows(MaxPerPage)
		 End If
		 RS.Close:Set RS=Nothing
		End Sub

         Public Function ShowPagePara(totalnumber, MaxPerPage, FileName, ShowAllPages, strUnit, CurrentPage, ParamterStr)
		  Dim N, I, PageStr
				Const Btn_First = "<span style='font-family:webdings;font-size:14px' title='第一页'>9</span>" '定义第一页按钮显示样式
				Const Btn_Prev = "<span style='font-family:webdings;font-size:14px' title='上一页'>3</span>" '定义前一页按钮显示样式
				Const Btn_Next = "<span style='font-family:webdings;font-size:14px' title='下一页'>4</span>" '定义下一页按钮显示样式
				Const Btn_Last = "<span style='font-family:webdings;font-size:14px' title='最后一页'>:</span>" '定义最后一页按钮显示样式
				  PageStr = ""
					If totalnumber Mod MaxPerPage = 0 Then
						N = totalnumber \ MaxPerPage
					Else
						N = totalnumber \ MaxPerPage + 1
					End If
					PageStr = PageStr & ("<div class='showpage' style='height:20px'><form action=""" & FileName & "?" & ParamterStr & """ name=""myform"" method=""post"">共 <font color=red>" & totalnumber & "</font> " & strUnit & "  分 <font color=red>" & N & "</font> 页 每页 <font color=red>" & MaxPerPage &"</font> " & strUnit &" | 当前第 <font color=red>" & CurrentPage & "</font> 页 &nbsp;&nbsp;&nbsp;")
					If CurrentPage < 2 Then
						PageStr = PageStr & Btn_First & " " & Btn_Prev & " "
					Else
						PageStr = PageStr & ("<a href=" & FileName & "?page=1" & "&" & ParamterStr & ">" & Btn_First & "</a> <a href=" & FileName & "?page=" & CurrentPage - 1 & "&" & ParamterStr & ">" & Btn_Prev & "</a> ")
					End If
					
					If N - CurrentPage < 1 Then
						PageStr = PageStr & " " & Btn_Next & " " & Btn_Last & " "
					Else
						PageStr = PageStr & (" <a href=" & FileName & "?page=" & (CurrentPage + 1) & "&" & ParamterStr & ">" & Btn_Next & "</a> <a href=" & FileName & "?page=" & N & "&" & ParamterStr & ">" & Btn_Last & "</a> ")
					End If
					If ShowAllPages = True Then
						PageStr = PageStr & ("转到:<input type='text' value='" & (CurrentPage + 1) &"' name='page' style='width:30px;height:18px;text-align:center;'>&nbsp;<input style='height:18px;border:1px #a7a7a7 solid;background:#fff;' type='submit' value='GO' name='sb'>")
				  End If
				  PageStr = PageStr & "</form></div>"
			 ShowPagePara = PageStr
	End Function

End Class
%>
