<%
 '得到超值礼包
 '参数showdel  true---显示删除  false ---不显示
 Function GetPackage(showdel)
	    If KS.IsNul(GetUserID) Then Exit Function
		Dim RS,RSB,GXML,GNode,str,n,Price
		Set RS=Conn.Execute("select packid,username from KS_ShopPackageSelect Where UserName='" & GetUserID & "' group by packid,username")
		If Not RS.Eof Then
		 Set GXML=KS.RsToXml(Rs,"row","")
		End If
		RS.Close : Set RS=Nothing
		If IsOBJECT(GXml) Then
		   FOR 	Each GNode In GXML.DocumentElement.SelectNodes("row")
		     Set RSB=Conn.Execute("Select top 1 * From KS_ShopPackAge Where ID=" & GNode.SelectSingleNode("@packid").text)
			 If Not RSB.Eof Then
					  If Conn.Execute("Select Sum(Amount) From KS_ShopPackageSelect Where Packid=" & GNode.SelectSingleNode("@packid").text & " and username='" & GetUserID & "'")(0)=RSB("num")  Then   '商品件数是否一致
					  
						Dim RSS:Set RSS=Server.CreateObject("adodb.recordset")
						RSS.Open "Select a.title,a.GroupPrice,a.Price_Member,a.Price,b.* From Product A inner join KS_ShopPackageSelect b on a.id=b.proid Where b.packid=" & GNode.SelectSingleNode("@packid").text & " and  b.UserName='" & GetUserID & "'",Conn,1,1
						  str=str & "<tr class='tdbg' height=""25"" align=""center""><td colspan=2><strong><a href='pack.asp?id=" & RSB("ID") & "' target='_blank'>" & RSB("PackName") & "</a></strong>,您选择的套装详细如下:</td>"
						  n=1
						  Dim TotalPackPrice,tempstr,i
						  TotalPackPrice=0 : tempstr=""
						Do While Not RSS.Eof
						 
						  For I=1 To RSS("Amount") 
							  '得到单件品价格 
							  IF KS.C("UserName")<>"" Then
								  If RSS("GroupPrice")=0 Then
								   Price=RSS("Price_Member")
								  Else
								   Dim RSP:Set RSP=Conn.Execute("Select Price From KS_ProPrice Where GroupID=(select groupid from ks_user where username='" & KS.C("UserName") & "') And ProID=" & RSS("ID"))
								   If RSP.Eof Then
									 Price=RSS("Price_Member")
								   Else
									 Price=RSP(0)
								   End If
								   RSP.Close:Set RSP=Nothing
								  End If
							  Else
								  Price=RSS("Price")
							  End If
							
							   TotalPackPrice=TotalPackPrice+Price
							  tempstr=tempstr & n & "." & rss("title") & " " & rss("AttributeCart") & "<br/>"
							  n=n+1
						  Next
						  RSS.MoveNext
						Loop
						
						str=str &"<td></td><td>￥" & TotalPackPrice & "</td><td>" & rsb("discount") & "折</td><td>￥" & formatnumber((TotalPackPrice*rsb("discount")/10),2,-1) & "</td><td>￥" & formatnumber((TotalPackPrice*rsb("discount")/10),2,-1) & "</td>"
					    if showdel then
						str=str & "<td><a href='?action=delpack&id=" & rsb("id") & "' onclick=""return(confirm('确定删除该礼包吗?'))"">删除</a></td>"
						end if
						str=str & "</tr><tr><td align='left' colspan=8>" & tempstr & "</td></tr>" 
						
						TotalPrice=TotalPrice+round(formatnumber((TotalPackPrice*rsb("discount")/10),2,-1))   '将礼包金额加入总价
						
						RSS.Close
						Set RSS=Nothing
					
					End If
			End If
			RSB.Close
		   Next
			
	    End If
		
		
		
		GetPackage=str
		
End Function
	 
	  '用户名
Function GetUserID()
		  If KS.IsNul(KS.C("UserName")) Then
			GetUserID=KS.C("CartID")
		  Else
		    GetUserID=KS.C("UserName")
		  End If
End Function 

Function GetBundleSalePro(ProID,ShowAction)   '获得捆绑促销的商品
  Dim Str,RS,XML,Node
  Set RS=Server.CreateObject("adodb.recordset")
  RS.Open "Select I.ID,I.Title,b.Price,b.amount,b.id as selid From Product I inner Join KS_ShopBundleSelect b on i.id=b.pid Where B.ProID=" & ProID & " and b.username='" & GetUserID & "' order by I.id",conn,1,1
  If Not RS.Eof Then
    Set XML=KS.RsToXml(rs,"row","")
  End If
  RS.Close:Set RS=Nothing
  If IsObject(XML) Then
	  Str=Str&"<tr class='tdbg' height=""15"" align=""center""> " & vbcrlf
	  Str=Str&"<td></td><td colspan=10 style='color:green;'>选购捆绑促销商品:</td> " & vbcrlf
	  Str=Str&"</tr> " & vbcrlf
     For Each Node In Xml.DocumentElement.SelectNodes("row")
	  Str=Str&"<tr class='tdbg'  align=""center""> " & vbcrlf
	  Str=Str&"<td height=""10""></td>" &vbcrlf
	  str=str &"<td>" & Node.SelectSingleNode("@title").text &"</td> " & vbcrlf
	  str=str &"<td><input type='hidden' name='SelID' value='" & Node.SelectSingleNode("@selid").text & "'>"
	  If ShowAction=true Then
	  str=str & "<input type=""Text"" name=""Q_" & Node.SelectSingleNode("@selid").text & """ value=""" & Node.SelectSingleNode("@amount").text & """ size=""5"" style=""text-align:center"" class=""textbox"">"
	  else
	   str=str & Node.SelectSingleNode("@amount").text
	  end if
	  str=str & "</td> " & vbcrlf
	  str=str &"<td>---</td> " & vbcrlf
	  str=str &"<td>---</td> " & vbcrlf
	  str=str &"<td>￥" & formatnumber(Node.SelectSingleNode("@price").text,2,-1) &"</td> " & vbcrlf
	  str=str &"<td>￥" & formatnumber(Node.SelectSingleNode("@price").text*Node.SelectSingleNode("@amount").text,2,-1) &"</td> " & vbcrlf
	  If ShowAction=true Then
	  str=str &"<td><a href=""?Action=BundleSale&SelID=" & Node.SelectSingleNode("@selid").text & """>删除</a> <a href=""../User/index.asp?User_Favorite.asp?Action=Add&ChannelID=5&InfoID=" & Node.SelectSingleNode("@id").text & """ target=""_blank"">收藏</a></td> " & vbcrlf
	  End If
	  Str=Str&"</tr> " & vbcrlf
	  
	  TotalPrice=TotalPrice+round(Node.SelectSingleNode("@price").text*Node.SelectSingleNode("@amount").text)   '将礼包金额加入总价

	 Next
  End If
  
  GetBundleSalePro=Str
End Function

Sub SetBundleSaleAmount()
	   Dim SelID,IdArr,I,Num
	   SelID=KS.S("SelID")
	   If SelID<>"" Then
	     SelID=Replace(SelID," ","")
		 IdArr=Split(SelID,",")
		 For I=0 To Ubound(IDArr) 
		   Num=KS.ChkClng(Request("Q_"&idArr(i)))
		   If Num>0 Then
		     Conn.Execute("Update KS_ShopBundleSelect Set Amount=" & Num & " Where ID=" & IDArr(i))
		   End If
		 Next
	   End If
End Sub

%>