<%
'==========================
' file: ex_sm_ai_assets.asp
' writer: cnxk
' qq: 29510683
' web: http://www.czie.com
'==========================
dim exsm,stock_db,stock_conn,connstrex
dim issqlsmdatabase,sqlsmnowstring
dim exsmassetsai,exrndincident,exsmai
exsmassetsai=2		'等于2为打开随机事件及AI、等于1为打开随机事件关闭AI、等于0为关闭随机事件及AI。
exrndincident=60	'用户成功触发随机事件后60秒后才可以再次触发。
exsmai=60		'用户成功触发AI后60秒后才可以再次触发。
issqlsmdatabase=0	'数据库类别[1]为sql数据库[0]为access数据库
set exsm = new cls_stock
if issqlsmdatabase=1 then
	dim sqlsmdatabasename,sqlsmpassword,sqlsmusername,sqlsmlocalname
	sqlsmnowstring="getdate()"
	sqlsmdatabasename="数据库名"	'股市SQL数据库连接
	sqlsmpassword="用户密码"
	sqlsmusername="用户名称"
	sqlsmlocalname="(local)"
	connstrex="provider = sqloledb; user id="&sqlsmusername&"; password="&sqlsmpassword&"; initial catalog="&sqlsmdatabasename&"; data source="&sqlsmlocalname&";"
else
	sqlsmnowstring="now()"
	stock_db="inc/ex_stock/data/ExStock1.mdb"	'股市access数据库，sql数据库用户无需修改。
	connstrex="provider=microsoft.jet.oledb.4.0;data source="&server.mappath(stock_db)
end if
on error resume next	'此处代码有助于数据库安全建议使用。
set stock_conn = server.createobject("adodb.connection")
stock_conn.open connstrex
exsm.st_setting
class cls_stock
	public exrs,exsql,exsetting,trade_info,ai_setting
	public aiplacename,aiuserinfo
	private aitempsave
	public sub st_setting()
		aiplacename=replace(replace(replace(server.mappath("ex_sm_index.asp"),"ex_sm_index.asp",""),":",""),"\","")
		set exrs=stock_conn.execute("select sm_setting,trade_setting,ai_setting from ex_config")
		exsetting=split(exrs(0),",")
		trade_info=split(exrs(1),",")
		ai_setting=split(exrs(2),"|")
		set exrs=nothing
		if not isarray(session(aiplacename&"exsmid")) then
			aitempsave="exsm$$$"&now()&"$$$"&now()&""
			session(aiplacename&"exsmid")=split(aitempsave,"$$$")
		end if
		aiuserinfo=session(aiplacename&"exsmid")
		if dvbbs.userid>0 then
			if exsmassetsai>0 and datediff("s",aiuserinfo(1),now())>cint(exrndincident) then rndincident
			if exsmassetsai>1 and cint(ai_setting(0))=1 and datediff("s",aiuserinfo(2),now())>cint(exsmai) then exai
		end if
	end sub
	public function rndcolor()
		dim selcolor,colornum
		randomize
		colornum=cint(rnd*11)
		select case colornum
			case 0
				selcolor="blue"
			case 1
				selcolor="black"
			case 2
				selcolor="fuchsia"
			case 3
				selcolor="olive"
			case 4
				selcolor="red"
			case 5
				selcolor="maroon"
			case 6
				selcolor="navy"
			case 7
				selcolor="gray"
			case 8
				selcolor="green"
			case 9
				selcolor="teal"
			case 10
				selcolor="purple"
			case 11
				selcolor="lime"
			case else
				selcolor="black"
		end select
		rndcolor=selcolor
	end function
	private sub rndincident()
		dim rnum,rndid,rndn,mycontent,color,maxid
		randomize
		rnum=rnd
		if cdbl(rnum)<=cdbl(exsetting(17)/100) then
			maxid=stock_conn.execute("select top 1 cid from ex_stock order by cid desc")(0)
			randomize rnd
			rndid=int(maxid*rnd)+1
			exsql="select * from ex_stock where cid="&rndid
			set exrs=stock_conn.execute(exsql)
			if (exrs("tradeprice")-exrs("closingprice"))/exrs("closingprice")>=cdbl(trade_info(3)/100) then
				mycontent="上市公司["&exrs("company")&"]走势过红，打开涨停状态！"
				color="red"
				stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&color&"',"&sqlsmnowstring&")")
			elseif (exrs("tradeprice")-exrs("closingprice"))/exrs("closingprice")<=-cdbl(trade_info(4)/100) then
				mycontent="上市公司["&exrs("company")&"]走势低迷，打开跌停状态！"
				color="black"
				stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&color&"',"&sqlsmnowstring&")")
			elseif exrs("tradeprice")<cdbl(trade_info(5)) then
				mycontent="上市公司["&exrs("company")&"]正在重组，打开停牌状态！"
				color="black"
				stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&color&"',"&sqlsmnowstring&")")
			elseif exrs("lockstock")=1 then
				mycontent="上市公司["&exrs("company")&"]由于不明原因，打开封盘状态！"
				color="purple"
				stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&color&"',"&sqlsmnowstring&")")
			else
				randomize
				rndn=rnd
				if cdbl(rndn)<cdbl(exsetting(18)/100) then
					rnum=round(100*rnd+1)
					if rnum<10 then
						exfluctuate rnum*10,1,exrs("company"),"资产重组，现价微涨","maroon",rndid,1 
					elseif round(rnum)<20 then
						exfluctuate rnum*10,1,exrs("company"),"资产重组，现价上涨","purple",rndid,1
					elseif round(rnum)<30 then
						exfluctuate rnum*10,10,exrs("company"),"业绩提高，投资人信心加大，现价上涨","fuchsia",rndid,1
					elseif round(rnum)<40 then
						exfluctuate rnum*10,20,exrs("company"),"大规模资产重组，现价上涨","olive",rndid,1
					elseif round(rnum)<50 then
						exfluctuate rnum*10,300,exrs("company"),"业绩大幅提高，注入大量资金，现价上涨","purple",rndid,1
					elseif round(rnum)<60 then
						exfluctuate 1000-rnum*10,40,exrs("company"),"业绩大幅提高，注入大量资金，现价上涨","fuchsia",rndid,1 
					elseif round(rnum)<70 then
						exfluctuate 1000-rnum*10,30,exrs("company"),"大规模资产重组，现价上涨","red",rndid,1
					elseif round(rnum)<80 then
						exfluctuate 1000-rnum*10,20,exrs("company"),"业绩提高，投资人信心加大，现价上涨","maroon",rndid,1
					elseif round(rnum)<90 then
						exfluctuate 1000-rnum*10,10,exrs("company"),"资产重组，现价上涨","fuchsia",rndid,1
					else
						exfluctuate 1000-rnum*10,1,exrs("company"),"资产重组，现价微涨","olive",rndid,1
					end if
				else
					randomize
					rnum=round(100*rnd+1)
					if round(rnum)<10 then
						exfluctuate rnum*10,1,exrs("company"),"放出非利好消息，现价微跌","navy",rndid,-1 
					elseif round(rnum)<20 then
						exfluctuate rnum*10,1,exrs("company"),"放出非利好消息，现价下滑","teal",rndid,-1
					elseif round(rnum)<30 then
						exfluctuate rnum*10,10,exrs("company"),"业绩不佳，投资人信心不足，现价下滑","green",rndid,-1
					elseif round(rnum)<40 then
						exfluctuate rnum*10,20,exrs("company"),"业绩开始滑坡，现价下跌","blue",rndid,-1
					elseif round(rnum)<50 then
						exfluctuate rnum*10,300,exrs("company"),"业绩大幅滑坡，资金不足，现价下跌","green",rndid,-1
					elseif round(rnum)<60 then 
						exfluctuate 1000-rnum*10,40,exrs("company"),"业绩大幅滑坡，遭受大户抛售，现价下跌","navy",rndid,-1 
					elseif round(rnum)<70 then
						exfluctuate 1000-rnum*10,30,exrs("company"),"业绩开始滑坡，现价下跌","teal",rndid,-1
					elseif round(rnum)<80 then
						exfluctuate 1000-rnum*10,20,exrs("company"),"业绩不佳，投资人信心不足，现价下滑","gray",rndid,-1
					elseif round(rnum)<90 then
						exfluctuate 1000-rnum*10,10,exrs("company"),"放出非利好消息，现价下滑","purple",rndid,-1
					else
						exfluctuate 1000-rnum*10,1,exrs("company"),"放出非利好消息，现价微跌","blue",rndid,-1
					end if
				end if
			end if
			aiuserinfo(1)=now()
			session(aiplacename&"exsmid")=aiuserinfo
			if clng(exsetting(13))>0 then
				stock_conn.execute("delete from ex_news where id not in(select top "&clng(exsetting(13))&" id from ex_news order by id desc)")
			end if
		end if
	end sub
	private sub exfluctuate(rmax,rmin,obj,message,msgcolor,gpid,flag)
		dim amp,aistockname,newprice,tradeprice,closingprice,zangdierange,color,mycontent
		aistockname=obj
		randomize
		amp=round(((rmax-rmin+1)*rnd+rmin)/100,2)
		set exrs=stock_conn.execute("select sid,tradeprice,closingprice from ex_stock where cid="&gpid)
		newprice=round(amp*exrs(2)*flag/100,2)
		tradeprice=round(exrs(1),2)
		closingprice=round(exrs(2),2)
		amp=newprice/closingprice
		zangdierange=round(((tradeprice+newprice-closingprice)/closingprice)*100,2)
		if zangdierange>round(trade_info(3),2) then
			newprice=round(closingprice*(1+trade_info(3)/100)-tradeprice,2)
			amp=round(trade_info(3)/100,2)-(tradeprice-closingprice)/closingprice
		elseif zangdierange<round(-trade_info(4),2) then
			newprice=round(closingprice*(1+-trade_info(4)/100)-tradeprice,2)
			amp=round(-trade_info(4)/100,2)-(tradeprice-closingprice)/closingprice
		end if
		if round(amp,2)<>0 and round(tradeprice+newprice,2)>=1 then
			stock_conn.execute("update ex_stock set tradeprice=tradeprice+"&round(newprice,2)&",todaywave=todaywave+"&cdbl(amp)&",totalwave=totalwave+"&cdbl(amp)&" where cid="&gpid&"")
			mycontent="上市公司["&aistockname&"]"&message&"["&formatpercent(abs(amp),2,-1)&"]"
			color=""&msgcolor&""
			stock_conn.execute("insert into ex_news(content,color,addtime) values ('"&mycontent&"','"&color&"',"&sqlsmnowstring&")")
		end if
	end sub
	private function ai_rndname()
		dim ai_name,ai_num,rate,rndid
		ai_name=split(ai_setting(1),",")
		ai_num=ubound(ai_name)
		randomize
		rate=rnd
		rndid=cint(ai_num*rate)
		if cdbl(rndid)>=cdbl(ai_num) then rndid=cint(ai_num)
		ai_rndname=ai_name(rndid)
	end function
	private sub exai()
		dim rnum
		randomize
		rnum=rnd
		if cdbl(rnum)>=cdbl(1-ai_setting(2)/100) then
			dim rndid,stocksid,stockcode,stocknum,stockname,stockprice,closingprice,todaypermittradesum,lockstock
			dim buynum
			rndid=stock_conn.execute("select top 1 cid from ex_stock order by cid desc")(0)
			randomize rnd
			rndid=int(rndid*rnd)+1
			set exrs=stock_conn.execute("select sid,code,company,tradeprice,closingprice,stocksum,todaypermittradesum,lockstock from ex_stock where cid="&rndid)
			stocksid=exrs(0)	:	stockcode=exrs(1)	:	stockname=exrs(2)	:	stockprice=round(exrs(3),2)	:	closingprice=round(exrs(4),2)	:	stocknum=exrs(5)	:	todaypermittradesum=exrs(6)	:	lockstock=exrs(7)
			if round(todaypermittradesum)<=0 then exit sub
			if lockstock=1 then exit sub
			if round(stockprice,2)<=round(trade_info(5),2) then exit sub
			if round(stocknum)<5000000 or round(stocknum)>20000000 then stocknum=20000000
			stocknum=round(stocknum/30)
			randomize
			rnum=int(rnd*10+1)
			select case rnum
				case 1
					buynum=cint(rnd*1000+1)
					if cint(buynum)<100 then buynum=100
					if round(todaypermittradesum-buynum)<=0 then buynum=todaypermittradesum
					call exai_buy(buynum,-1,stocksid,stockcode,stockname,stockprice,closingprice,stocknum)
				case 2
					buynum=cint(rnd*10000+1)
					if cint(buynum)<100 then buynum=100
					if round(todaypermittradesum-buynum)<=0 then buynum=todaypermittradesum
					call exai_buy(buynum,-1,stocksid,stockcode,stockname,stockprice,closingprice,stocknum)			
				case 4
					buynum=cint(rnd*5000+1)
					if cint(buynum)<100 then buynum=100
					if round(todaypermittradesum-buynum)<=0 then buynum=todaypermittradesum
					call exai_buy(buynum,-1,stocksid,stockcode,stockname,stockprice,closingprice,stocknum)			
				case 7
					buynum=cint(rnd*7500+1)
					if cint(buynum)<100 then buynum=100
					if round(todaypermittradesum-buynum)<=0 then buynum=todaypermittradesum
					call exai_buy(buynum,-1,stocksid,stockcode,stockname,stockprice,closingprice,stocknum)			
				case 9
					buynum=cint(rnd*500+1)
					if cint(buynum)<100 then buynum=100
					if round(todaypermittradesum-buynum)<=0 then buynum=todaypermittradesum
					call exai_buy(buynum,-1,stocksid,stockcode,stockname,stockprice,closingprice,stocknum)			
				case else
					call exai_sale(-1)
			end select
		elseif cdbl(rnum)<cdbl(0.10) then
			stock_conn.execute("insert into ex_news (content,color,addtime) values('["&ai_rndname&"]在股票市场转了一圈，一笔交易都没有做成。','"&rndcolor&"',"&sqlsmnowstring&")") 
		end if
	end sub
	private sub exai_buy(buynum,uid,sid,stockcode,gupiaoname,nowprice,closingprice,stocknum)
		dim ai_name,rnum,rate,buynumhldcg,newprice,zd,zangdierange,mycontent
		ai_name=split(ai_setting(1),",")
		buynumhldcg=buynum
		if round(buynum)>10000 then buynumhldcg=10000
		randomize
		rnum=rnd
		rate=rnd
		if cdbl(rnum)<=0.4 then rnum=cdbl(rnum+0.5)
		if cint(ai_setting(3))=1 then
			if cdbl(rate)<round(trade_info(8)/100,2) then
				newprice=round(closingprice*buynumhldcg*rnum/stocknum,2)
				zd=newprice/closingprice
				zangdierange=round(((nowprice+newprice-closingprice)/closingprice),4)
				if zangdierange>round(trade_info(3)/100,2) then
					newprice=round(closingprice*(1+round(trade_info(3)/100,2))-nowprice,2)
					zd=round(trade_info(3)/100,2)-round((nowprice-closingprice)/closingprice,2)
				end if
				if round(nowprice+newprice,2)<round(trade_info(5),2) then newprice=0	:	zd=0
				if round(zd,4)=0 then
					mycontent="股民["&ai_rndname&"]买入["&gupiaoname&"]["&buynum&"]股，现价没有波动。"
				else
					mycontent="股民["&ai_rndname&"]买入["&gupiaoname&"]["&buynum&"]股，现价上涨["&formatpercent(zd,2,-1)&"]。"
				end if
			elseif cdbl(rate)<round(trade_info(8)/100,2)+round(trade_info(9)/100,2) then
				newprice=round(-closingprice*buynumhldcg*rnum/stocknum,2)
				zd=newprice/closingprice
				zangdierange=round(((nowprice+newprice-closingprice)/closingprice),4)
				if zangdierange<round(-trade_info(4)/100,2) then
					newprice=round(closingprice*(1+-round(trade_info(4)/100,2))-nowprice,2)
					zd=round(-trade_info(4)/100,2)-round((nowprice-closingprice)/closingprice,2)
				end if
				if round(nowprice+newprice,2)<round(trade_info(5),2) then newprice=0	:	zd=0
				if round(zd,4)=0 then
					mycontent="股民["&ai_rndname&"]买入["&gupiaoname&"]["&buynum&"]股，现价没有波动。"
				else
					mycontent="股民["&ai_rndname&"]买入["&gupiaoname&"]["&buynum&"]股，现价下滑["&formatpercent(abs(zd),2,-1)&"]。"
				end if
			else
				newprice=0
				zd=0
				mycontent="股民["&ai_rndname&"]买入["&gupiaoname&"]["&buynum&"]股，现价没有波动。"
			end if
		else
			newprice=0
			zd=0
			mycontent="股民["&ai_rndname&"]买入["&gupiaoname&"]["&buynum&"]股，现价没有波动。"
		end if
		set exrs=stock_conn.execute("select possessstocksum,buyprice from ex_customer where sid="&sid&" and userid="&uid&"")
		if exrs.eof and exrs.bof then
			stock_conn.execute("update ex_stock set tradeprice=tradeprice+"&round(newprice,2)&", todaypermittradesum=todaypermittradesum-"&round(buynum)&",surplusshare=surplusshare-"&round(buynum)&",todayadtradesum=todayadtradesum+"&round(buynum)&",todaybuynumber=todaybuynumber+1,todaywave=todaywave+"&cdbl(zd)&",totalwave=totalwave+"&cdbl(zd)&" where sid="&sid&"")
			stock_conn.execute("insert into ex_customer (username,userid,code,company,sid,buyprice,averageprice,possessstocksum,buytime) values ('"&ai_name(0)&"',"&uid&",'"&stockcode&"','"&gupiaoname&"',"&sid&","&round(nowprice,2)&","&round(nowprice,2)&","&buynum&","&sqlsmnowstring&")")
			stock_conn.execute("update ex_ai set userwealth=userwealth-"&round(buynum*nowprice,2)&",userassets=userassets-"&round(buynum*nowprice,2)&",possesssort=possesssort+1,totalbuy=totalbuy+1 where username='"&ai_name(0)&"'")
			stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&rndcolor&"',"&sqlsmnowstring&")")
		else
			dim mynum,agvprice
			mynum=exrs(0)
			agvprice=round((nowprice*buynum+exrs(1)*mynum)/(buynum+mynum),2)
			stock_conn.execute("update ex_stock set tradeprice=tradeprice+"&cdbl(newprice)&", todaypermittradesum=todaypermittradesum-"&round(buynum)&",surplusshare=surplusshare-"&round(buynum)&",todayadtradesum=todayadtradesum+"&round(buynum)&",todaybuynumber=todaybuynumber+1,todaywave=todaywave+"&cdbl(zd)&",totalwave=totalwave+"&cdbl(zd)&" where sid="&sid&"")
			stock_conn.execute("update ex_customer set buyprice="&round(nowprice,2)&",averageprice="&round(agvprice,2)&",possessstocksum=possessstocksum+"&round(buynum)&",buytime="&sqlsmnowstring&" where userid="&uid&" and sid="&sid&"")
			stock_conn.execute("update ex_ai set userwealth=userwealth-"&round(buynum*nowprice,2)&",userassets=userassets-"&round(buynum*nowprice,2)&",possesssort=possesssort+1,totalbuy=totalbuy+1 where username='"&ai_name(0)&"'")
			stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&rndcolor&"',"&sqlsmnowstring&")")
		end if
		stock_conn.execute("update ex_config set todaybuy=todaybuy+1,todaytotal=todaytotal+"&cdbl(buynum*nowprice)&"")
		exrs.close
		set exrs=nothing
		aiuserinfo(2)=now()
		session(aiplacename&"exsmid")=aiuserinfo
	end sub
	private sub exai_sale(uid)
		dim ai_name,rnum,rst,sid,buyprice,salenum,nowprice,gupiaoname,stocknum
		dim rate,salenumhldcg,newprice,zd,zangdierange,closingprice,mycontent
		ai_name=split(ai_setting(1),",")
		exsql="select d.sid,d.possessstocksum,g.company,g.tradeprice,g.closingprice,g.stocksum,g.lockstock from ex_customer d inner join ex_stock g on d.sid=g.sid where d.userid="&uid&""
		set rst=server.createobject("adodb.recordset")
		rst.open exsql,stock_conn,1,1
		if not rst.eof then
			randomize
			rst.absoluteposition=fix(rst.recordcount*rnd)+1
			if round(rst(3),2)<=round(trade_info(5),2) then exit sub
			if rst(6)=1 then exit sub
			sid=rst(0)
			salenum=rst(1)
			gupiaoname=rst(2)
			nowprice=round(rst(3),2)
			closingprice=round(rst(4),2)
			stocknum=rst(5)
			if stocknum<5000000 or stocknum>20000000 then stocknum=20000000
			stocknum=stocknum/30
			randomize
			if rnd<0.3 then
				salenum=rst(1)
			else
				rnum=rnd
				if cdbl(rnum)>0.5 then rnum=cdbl(1-rnum)
				salenum=cint(rst(1)*rnum+1)
				if round(salenum)<100 then salenum=100
				if round(salenum-rst(1))<=0 then salenum=rst(1)
			end if
			salenumhldcg=salenum
			if round(salenum)>10000 then salenumhldcg=10000
			randomize
			rate=rnd
			rnum=rnd
			if cdbl(rnum)<=0.4 then rnum=cdbl(rnum+0.5)
			if cint(ai_setting(3))=1 then
				if cdbl(rate)<cdbl(trade_info(10)/100) then
					newprice=round(-closingprice*salenumhldcg*rnum/stocknum,2)
					zd=newprice/closingprice
					zangdierange=round(((nowprice+newprice-closingprice)/closingprice),4)
					if zangdierange<round(-trade_info(4)/100,2) then
						newprice=round(closingprice*(1+-round(trade_info(4)/100,2))-nowprice,2)
						zd=round(-trade_info(4)/100,2)-round((nowprice-closingprice)/closingprice,2)
					end if
					if nowprice+newprice<round(trade_info(5),2) then newprice=0	:	zd=0
					if round(zd,4)=0 then
						mycontent="股民["&ai_rndname&"]卖出["&gupiaoname&"]["&salenum&"]股，现价没有波动。"
					else
						mycontent="股民["&ai_rndname&"]卖出["&gupiaoname&"]["&salenum&"]股，现价下滑["&formatpercent(abs(zd),2,-1)&"]。"
					end if
				elseif cdbl(rate)<round(trade_info(10)/100,2)+round(trade_info(11)/100,2) then
					newprice=round(closingprice*salenumhldcg*rnum/stocknum,2)
					zd=newprice/closingprice
					zangdierange=round(((nowprice+newprice-closingprice)/closingprice),4)
					if zangdierange>round(trade_info(3)/100,2) then
						newprice=round(closingprice*(1+round(trade_info(3)/100,2))-nowprice,2)
						zd=round(trade_info(3)/100,2)-round((nowprice-closingprice)/closingprice,2)
					end if
					if nowprice+newprice<round(trade_info(5),2) then newprice=0	:	zd=0
					if round(zd,4)=0 then
						mycontent="股民["&ai_rndname&"]卖出["&gupiaoname&"]["&salenum&"]股，现价没有波动。"
					else
						mycontent="股民["&ai_rndname&"]卖出["&gupiaoname&"]["&salenum&"]股，现价上涨["&formatpercent(zd,2,-1)&"]。"
					end if
				else
					newprice=0
					zd=0
					mycontent="股民["&ai_rndname&"]卖出["&gupiaoname&"]["&salenum&"]股，现价没有波动。"
				end if
			else
				newprice=0
				zd=0
				mycontent="股民["&ai_rndname&"]卖出["&gupiaoname&"]["&salenum&"]股，现价没有波动。"
			end if
			stock_conn.execute("update ex_stock set tradeprice=tradeprice+"&round(newprice,2)&", todaypermittradesum=todaypermittradesum+"&round(salenum)&",surplusshare=surplusshare+"&round(salenum)&",todayadtradesum=todayadtradesum+"&round(salenum)&",todaysellnumber=todaysellnumber+1,todaywave=todaywave+"&cdbl(zd)&",totalwave=totalwave+"&cdbl(zd)&" where sid="&sid&"")
			stock_conn.execute("update ex_customer set possessstocksum=possessstocksum-"&round(salenum)&",selltime="&sqlsmnowstring&" where userid="&uid&" and sid="&sid&"")
			stock_conn.execute("update ex_ai set userwealth=userwealth+"&round(salenum*nowprice,2)&",userassets=userassets+"&round(salenum*nowprice,2)&",possesssort=possesssort-1,totalsell=totalsell+1 where username='"&ai_name(0)&"'")
			stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&rndcolor&"',"&sqlsmnowstring&")")
			stock_conn.execute("update ex_config set todaysell=todaysell+1,todaytotal=todaytotal+"&cdbl(salenum*nowprice)&"")
			stock_conn.execute("delete from ex_customer where possessstocksum<=0")
        	end if
		rst.close
		set rst=nothing
		aiuserinfo(2)=now()
		session(aiplacename&"exsmid")=aiuserinfo
	end sub
	public function stockmoney(exuserid)
		set exrs=stock_conn.execute("select userassets from ex_user where userbbsid="&exuserid&"")
		if not exrs.eof then
			stockmoney=round(exrs(0),2)
		else
			stockmoney=0
		end if
		exrs.close
		set exrs=nothing
	end function
end class
%>