<!--#include file="conn.asp" -->
<%
if Request.Cookies("username")=empty then 
response.Write("请先登陆。")
response.End()
end if

Set conn=Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.open ConnStr

menu=request("menu")
select case menu
case "buy"
	buyshow=session("buyshow")
	myshows=split(buyshow,"-")
	price=0
	for each myshow in myshows
		sql="select Price1 from [myshow] where id="&cint(myshow)&""
		rs.open sql,conn
		price=price+rs("Price1")
		rs.close
	next
	sql="select mybuyshow,money from [user] where username='"&Request.Cookies("username")&"'"
	rs.open sql,conn,1,3
	if rs("money")<price then 
		response.Write("很抱歉！您的现金不够，无法购买！")
		response.End()
	else
		rs("money")=rs("money")-price
	end if
	if len(rs("mybuyshow"))+len(buyshow)<250 or isnull(rs("mybuyshow")) then
		s=rs("mybuyshow")&"-"&buyshow
		a=split(s,"-")
		c=UBound(a)
		For I = 1 To c
			For j=i+1 To c
				if a(i)=a(j) then a(j)=""
			Next
		Next
		
		e=0
		redim sum(c)
		For i = 0 To c
			If a(i) <> "" Then
				sum(e) = right(a(i)+10000,4)
				e =e+1
			End If
		Next
		Redim Preserve sum(e-1)
		s=join(sum,"-")
		rs("mybuyshow")=s
	else 
		response.Write("超过衣柜容量，无法购买")
		response.End()
	end if
	rs.update
	rs.close
	session("buyshow")=""
	response.Write("<script>alert('购买成功,可以保存形象了。');close();</script>")
	
case "save"
	'session("buyshow")=""
	sessionbuyshow=""
	myshow=request("myshow")
	myshows=Split(myshow,">")
	sql="select mybuyshow from [user] where username='"&Request.Cookies("username")&"'"
	rs.open sql,conn
	mybuyshow=rs("mybuyshow")
	if isnull(mybuyshow) then mybuyshow="0000"
	rs.close
	'response.Write("mybuyshow="&mybuyshow)
	for each show in myshows
		show2=show+10000
		show2=right(show2,4)
		if show>15 then
		if instr(mybuyshow,show2)=0 then sessionbuyshow=sessionbuyshow&"-"&show
		end if
	next
	if sessionbuyshow<>"" then
	'session("buyshow")=session("buyshow")&"-"&sessionbuyshow
	session("buyshow")=sessionbuyshow
	response.Write("<script>alert('你穿戴的物品还有未购买的！请先购买！');top.location='myshow_buy.asp'</script>")
	else
	conn.execute("update [user] set myshow='"&myshow&"' where username='"&Request.Cookies("username")&"'")
	response.Write("<script>alert('保存成功');close();</script>")
	end if
	
case "camera"
	session("buyshow")=""
	myshow=request("myshow")
	myshows=Split(myshow,">")
	sql="select mybuyshow from [user] where username='"&Request.Cookies("username")&"'"
	rs.open sql,conn
	mybuyshow=rs("mybuyshow")
	if isnull(mybuyshow) then mybuyshow="0000"
	rs.close
	'response.Write(mybuyshow)
	for each show in myshows
		show2=show+10000
		show2=right(show2,4)
		if show>15 then
		if instr(mybuyshow,show2)=0 then session("buyshow")=session("buyshow")&"-"&show
		end if
	next
	if session("buyshow")<>"" then
	response.Write("<script>alert('你穿戴的物品还有未购买的！请先购买！');top.location='myshow_buy.asp'</script>")
	else
	sql="select * from [myshow_photo]"
	rs.open sql,conn,1,3
	rs.addnew
	rs("username")=Request.Cookies("username")
	rs("photo")=myshow
	rs("regtime")=now
	rs("explain")=Request("explain")
	rs.update
	rs.close
	response.Write("<script>alert('拍照成功');close();</script>")
	end if
	
case "clear"
	session("buyshow")=""
	response.Redirect("myshow_buy.asp")
	
case "match"
	photoid=request("photoid")
	conn.execute("update [myshow_photo] set photoshow=true where id="&photoid&" and username='"&Request.Cookies("username")&"'")
	response.Write("<script>alert('参赛成功！');window.opener.location.reload();window.close();</script>")

	
case "dropphoto"
	photoid=request("photoid")
	conn.execute("delete from [myshow_photo] where id="&photoid&" and username='"&Request.Cookies("username")&"'")
	response.Write("<script>alert('删除成功！');window.opener.location.reload();window.close();</script>")

case "dropclothes"
	clothesid=request("clothesid")
	clothesid=right(clothesid+10000,4)
	sql="select mybuyshow from [user] where username='"&Request.Cookies("username")&"'"
	rs.open sql,conn,1,3
	if not rs.eof then
		s=rs("mybuyshow")
		a=split(s,"-")
		c=UBound(a)
		For I = 1 To c
			if a(i)=clothesid then a(i)=""
		Next
		
		e=0
		redim sum(c)
		For i = 0 To c
			If a(i) <> "" Then
				sum(e) = a(i)
				e =e+1
			End If
		Next
		Redim Preserve sum(e-1)
		s=join(sum,"-")
		rs("mybuyshow")=s
	rs.update
	end if
	rs.close
	response.Write("<script>alert('删除成功！');window.opener.location.reload();window.close();</script>")
	
case "present"
	id=right((request("id")+10000),4)
	sql="select * from [user] where username='"&request("getid")&"'"
	Set rs=Conn.Execute(SQL)
	if rs.eof then 
		Response.Write("<li>您所赠送的对象不存在，请检查您输入的用户名。")
		Response.End()
	end if
	rs.close
		
	sql="select Price1 from [myshow] where id="&request("id")&""
	rs.open sql,conn
	price=rs("Price1")
	rs.close
	
	sql="select mybuyshow,money from [user] where username='"&Request.Cookies("username")&"'"
	rs.open sql,conn,1,3
	if rs("money")<price then 
		response.Write("<li>很抱歉！您的现金不够，无法购买！")
		response.End()
	else
		rs("money")=rs("money")-price
	end if
	rs.update
	rs.close
	
	sql="select * from [myshow_present]"
	rs.open sql,conn,1,3
	rs.addnew
	rs("myshowid")=request("id")
	rs("getid")=request("getid")
	rs("buytime")=now()
	rs("giveid")=Request.Cookies("username")
	rs("type")="0"
	rs.update
	rs.close
case else
	response.Redirect("myshow_buy.asp")
end select

set rs=nothing
set conn=nothing
Response.End
%>