<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/ex_stock/ex_sm_conn.asp"-->
<!--#include file="inc/ex_stock/ex_sm_const.asp"-->
<%
	select case request("action")
		case "analysediv"
			call analysediv()
		case "ai"
			call ai()
		case else
			call main()
	end select
	sub main()
		exsm.title 1,"在线情况"
		dim quotations
		session("ex_sm")=0
		exsm.name="exsm_imitate_quotations"
		quotations=exsm.value
%>
		<table class="tableborder1" cellspacing="1" cellpadding="3" align="center" border="0">
		<tr>
			<th height="25" id="tabletitlelink">-=> <%=exsm.setting_info(0)%> - 在 线 情 况<%if exsm.stockadmin then%>&nbsp;[<a href=?action=admin>管理</a>]<%end if%> <=-</th>
		</tr>
		<tr align="center">
			<td class="tablebody1">目前股市共有 <b><%=cint(quotations(4))+cint(quotations(5))%></b> 位在线股民，会员 <b><%=cint(quotations(4))%></b> 位，客人 <b><%=cint(quotations(5))%></b> 位。</td>
		</tr>
		</table>
		<br>
		<table class="tableborder1" cellspacing="1" cellpadding="3" align="center" border="0">
		<tr height="25"> 
		<th>id</th>
		<th>用户名</th>
		<th>目前位置</th>
		<th>开户</th>
		<th>来访时间</th>
		<th>活动时间</th>
		<th>用户IP</th>
		<th>autouserid</th>
		</tr>
<%
		dim currentpage,page_count,pcount
		dim totalrec,endpage,userip,address
		currentpage=request("page")
		if currentpage="" or not isnumeric(currentpage) then
			currentpage=1
		end if
		sql= "select * from ex_analyse"
		set rs= server.createobject("adodb.recordset")
		rs.open sql,stock_conn,1,1
		if rs.eof and rs.bof then
			response.write "<tr><td class=""tablebody1"" colspan=""8"">没有找到在线股民</td></tr></table>"
		else
			rs.pagesize=cint(exsm.setting_info(16))
			totalrec=rs.recordcount
			if cdbl(currentpage)>=totalrec\cdbl(rs.pagesize)+1 then
				currentpage=totalrec\cdbl(rs.pagesize)+1
			else
				currentpage=cdbl(currentpage)
			end if
			if clng(currentpage)<1 then currentpage=1
			rs.absolutepage=currentpage
			page_count=0
			do while (not rs.eof) and (not page_count = rs.pagesize)
				if exsm.stockadmin then
					userip=""&rs("userip")&""
					if rs("userid")=0 then
						address=""&rs("username")&""
					else
						address="<a href=""ex_sm_dispu.asp?uid="&rs("userid")&""">"&rs("username")&"</a>"
					end if
				else
					userip="*.*.*.*"
					if rs("hideuser")=1 then
						address="隐身股民"
					else
						if rs("userid")=0 then
							address=""&rs("username")&""
						else
							address="<a href=""ex_sm_dispu.asp?uid="&rs("userid")&""">"&rs("username")&"</a>"
						end if
					end if
				end if
%>
			<form action="ex_sm_admin_user.asp?action=deluserlist" method="post" name="form1">
			<tr align="center">
				<td class="tablebody1"><%if request("action")="admin" then%><input type="checkbox" name="id" value="<%=rs("id")%>"><%else%><%=rs("id")%><%end if%></td>
				<td class="tablebody1"><%=address%></td>
				<td class="tablebody2"><%=rs("nowseat")%></td>
				<td class="tablebody1"><%if rs("userid")=0 then%>否<%else%>是<%end if%></td>
				<td class="tablebody1"><%=rs("usertime")%></td>
				<td class="tablebody1"><%=rs("movetime")%></td>
				<td class="tablebody1"><%=userip%></td>
				<td class="tablebody1"><%=rs("statuserid")%></td>
			</tr>
<%
			page_count = page_count + 1
			rs.movenext
			loop
			pcount=rs.pagecount
			if request("action")="admin" then
%>
				<tr>
				<td class="tablebody2" colspan="8">&nbsp;
					<input type="checkbox" name="chkall" value="on" onclick="checkall(this.form)">&nbsp;全选/取消&nbsp;批量删除&nbsp;<input type="submit" name="submit" value="执行">
				</td>
				</tr>
<%
			end if
			response.write "</form>"
			response.write "</table>"
			call exsm.disppagenum(totalrec,page_count,currentpage,pcount,"?page=","?")
%>
		<script language="javascript">
			function checkall(form)	{
				for (var i=0;i<form.elements.length;i++){
					var e = form.elements[i];
					if (e.name != 'chkall'){
						e.checked = form.chkall.checked;
					}
				}
			}
			</script>
<%
		end if
		rs.close
		set rs=nothing
		exsm.rootshow
	end sub
	sub ai()
		response.write "ok"
	end sub
	sub analysediv()
		dim page,analysedata,identifyuserip,j
		dim autouserid
		response.write "<script language=""javascript"" src=""inc/ex_stock/ex_sm_online.js""></script>"
		if request("online")=1 then
			response.write "<script language=""javascript"">"
			response.write "showanalyse();"
			response.write "</script>"
		end if
		if request("on")=1 then exit sub
		response.write "<script language=""javascript"">"
		page=request("page")
		if page="" then page=1
		page=clng(page)
		if exsm.userid<>0 then
			response.write "username='"&exsm.stockholder&"';"
		else
			autouserid=clng(exsm.exsmuserinfo(3))
			response.write "statuserid='"&autouserid&"';"
		end if
		if exsm.stockadmin then
			identifyuserip=",userip"
			response.write "stockadmin=1;"
		end if
		j=0
		set rs=server.createobject("adodb.recordset")
		sql="select id,username,usertime,nowseat,userid,movetime,hideuser,statuserid"&identifyuserip&" from ex_analyse"
		rs.open sql,stock_conn,1,1
		rs.pagesize=cint(exsm.setting_info(12))
		rs.absolutepage=page
		response.write "pagecount="&rs.pagecount&";"
		response.write "count="&rs.recordcount&";"
		response.write "pagesize="&cint(exsm.setting_info(12))&";"
		response.write "page="&page&";"
		do while not rs.eof
			for i=0 to rs.fields.count-1
				analysedata=analysedata & rs(i)& "@$#^"
			next
			analysedata=analysedata&"!&%@"
		rs.movenext
		j=j+1
		if j=cint(exsm.setting_info(12)) then exit do
		loop
		rs.close
		analysedata=replace(replace(replace(replace(analysedata&"","\","\\"),"'","\'"),vbcrlf,"\n"),chr(13),"")
		response.write "showlist('"&analysedata&"');"
		response.write "</script>"
	end sub
	dim aitrade_info,ai_setting
	if request("aion")="on" then
		aitrade_info=split(exsm.stockdata(10,0),",")
		ai_setting=split(exsm.stockdata(14,0),"|")
		if exsm.userid>0 and datediff("s",session(exsm.placename&"exsmteuserid")(8),now())>60 then rndincident
		if exsm.userid>0 and cint(ai_setting(0))=1 and datediff("s",session(exsm.placename&"exsmteuserid")(10),now())>60 then exai
	end if
	sub rndincident()
		dim rnum,rndid,rndn,mycontent,color,maxid
		randomize
		rnum=rnd
		if cdbl(rnum)<=cdbl(exsm.setting_info(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
			sql="select * from ex_stock where cid="&rndid
			set rs=stock_conn.execute(sql)
			if (rs("tradeprice")-rs("closingprice"))/rs("closingprice")>=cdbl(aitrade_info(3)/100) then
				mycontent="上市公司["&rs("company")&"]走势过红，打开涨停状态！"
				color="red"
				stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&color&"',"&sqlsmnowstring&")")
			elseif (rs("tradeprice")-rs("closingprice"))/rs("closingprice")<=-cdbl(aitrade_info(4)/100) then
				mycontent="上市公司["&rs("company")&"]走势低迷，打开跌停状态！"
				color="black"
				stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&color&"',"&sqlsmnowstring&")")
			elseif rs("tradeprice")<cdbl(aitrade_info(5)) then
				mycontent="上市公司["&rs("company")&"]正在重组，打开停牌状态！"
				color="black"
				stock_conn.execute("insert into ex_news (content,color,addtime) values('"&mycontent&"','"&color&"',"&sqlsmnowstring&")")
			elseif rs("lockstock")=1 then
				mycontent="上市公司["&rs("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(exsm.setting_info(18)/100) then
					rnum=round(100*rnd+1)
					if rnum<10 then
						exfluctuate rnum*10,1,rs("company"),"资产重组，现价微涨","maroon",rndid,1 
					elseif round(rnum)<20 then
						exfluctuate rnum*10,1,rs("company"),"资产重组，现价上涨","purple",rndid,1
					elseif round(rnum)<30 then
						exfluctuate rnum*10,10,rs("company"),"业绩提高，投资人信心加大，现价上涨","fuchsia",rndid,1
					elseif round(rnum)<40 then
						exfluctuate rnum*10,20,rs("company"),"大规模资产重组，现价上涨","olive",rndid,1
					elseif round(rnum)<50 then
						exfluctuate rnum*10,300,rs("company"),"业绩大幅提高，注入大量资金，现价上涨","purple",rndid,1
					elseif round(rnum)<60 then
						exfluctuate 1000-rnum*10,40,rs("company"),"业绩大幅提高，注入大量资金，现价上涨","fuchsia",rndid,1 
					elseif round(rnum)<70 then
						exfluctuate 1000-rnum*10,30,rs("company"),"大规模资产重组，现价上涨","red",rndid,1
					elseif round(rnum)<80 then
						exfluctuate 1000-rnum*10,20,rs("company"),"业绩提高，投资人信心加大，现价上涨","maroon",rndid,1
					elseif round(rnum)<90 then
						exfluctuate 1000-rnum*10,10,rs("company"),"资产重组，现价上涨","fuchsia",rndid,1
					else
						exfluctuate 1000-rnum*10,1,rs("company"),"资产重组，现价微涨","olive",rndid,1
					end if
				else
					randomize
					rnum=round(100*rnd+1)
					if round(rnum)<10 then
						exfluctuate rnum*10,1,rs("company"),"放出非利好消息，现价微跌","navy",rndid,-1 
					elseif round(rnum)<20 then
						exfluctuate rnum*10,1,rs("company"),"放出非利好消息，现价下滑","teal",rndid,-1
					elseif round(rnum)<30 then
						exfluctuate rnum*10,10,rs("company"),"业绩不佳，投资人信心不足，现价下滑","green",rndid,-1
					elseif round(rnum)<40 then
						exfluctuate rnum*10,20,rs("company"),"业绩开始滑坡，现价下跌","blue",rndid,-1
					elseif round(rnum)<50 then
						exfluctuate rnum*10,300,rs("company"),"业绩大幅滑坡，资金不足，现价下跌","green",rndid,-1
					elseif round(rnum)<60 then 
						exfluctuate 1000-rnum*10,40,rs("company"),"业绩大幅滑坡，遭受大户抛售，现价下跌","navy",rndid,-1 
					elseif round(rnum)<70 then
						exfluctuate 1000-rnum*10,30,rs("company"),"业绩开始滑坡，现价下跌","teal",rndid,-1
					elseif round(rnum)<80 then
						exfluctuate 1000-rnum*10,20,rs("company"),"业绩不佳，投资人信心不足，现价下滑","gray",rndid,-1
					elseif round(rnum)<90 then
						exfluctuate 1000-rnum*10,10,rs("company"),"放出非利好消息，现价下滑","purple",rndid,-1
					else
						exfluctuate 1000-rnum*10,1,rs("company"),"放出非利好消息，现价微跌","blue",rndid,-1
					end if
				end if
			end if
			exsm.exsmuserinfo(8)=now()
			session(exsm.placename&"exsmteuserid")=exsm.exsmuserinfo
			if clng(exsm.setting_info(13))>0 then
				stock_conn.execute("delete from ex_news where id not in(select top "&clng(exsm.setting_info(13))&" id from ex_news order by id desc)")
			end if
		end if
	end sub
	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 rs=stock_conn.execute("select sid,tradeprice,closingprice from ex_stock where cid="&gpid)
		newprice=round(amp*rs(2)*flag/100,2)
		tradeprice=round(rs(1),2)
		closingprice=round(rs(2),2)
		amp=newprice/closingprice
		zangdierange=round(((tradeprice+newprice-closingprice)/closingprice)*100,2)
		if zangdierange>round(aitrade_info(3),2) then
			newprice=round(closingprice*(1+aitrade_info(3)/100)-tradeprice,2)
			amp=round(aitrade_info(3)/100,2)-(tradeprice-closingprice)/closingprice
		elseif zangdierange<round(-aitrade_info(4),2) then
			newprice=round(closingprice*(1+-aitrade_info(4)/100)-tradeprice,2)
			amp=round(-aitrade_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&")")
			call exsm.calculatefund("no",rs(0))
		end if
	end sub
	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
	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 rs=stock_conn.execute("select sid,code,company,tradeprice,closingprice,stocksum,todaypermittradesum,lockstock from ex_stock where cid="&rndid)
			stocksid=rs(0)	:	stockcode=rs(1)	:	stockname=rs(2)	:	stockprice=round(rs(3),2)	:	closingprice=round(rs(4),2)	:	stocknum=rs(5)	:	todaypermittradesum=rs(6)	:	lockstock=rs(7)
			if round(todaypermittradesum)<=0 then exit sub
			if lockstock=1 then exit sub
			if round(stockprice,2)<=round(aitrade_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&"]在股票市场转了一圈，一笔交易都没有做成。','"&exsm.rndcolor&"',"&sqlsmnowstring&")") 
		end if
	end sub
	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(aitrade_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(aitrade_info(3)/100,2) then
					newprice=round(closingprice*(1+round(aitrade_info(3)/100,2))-nowprice,2)
					zd=round(aitrade_info(3)/100,2)-round((nowprice-closingprice)/closingprice,2)
				end if
				if round(nowprice+newprice,2)<round(aitrade_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(aitrade_info(8)/100,2)+round(aitrade_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(-aitrade_info(4)/100,2) then
					newprice=round(closingprice*(1+-round(aitrade_info(4)/100,2))-nowprice,2)
					zd=round(-aitrade_info(4)/100,2)-round((nowprice-closingprice)/closingprice,2)
				end if
				if round(nowprice+newprice,2)<round(aitrade_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 rs=stock_conn.execute("select possessstocksum,buyprice from ex_customer where sid="&sid&" and userid="&uid&"")
		if rs.eof and rs.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&"','"&exsm.rndcolor&"',"&sqlsmnowstring&")")
		else
			dim mynum,agvprice
			mynum=rs(0)
			agvprice=round((nowprice*buynum+rs(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&"','"&exsm.rndcolor&"',"&sqlsmnowstring&")")
		end if
		stock_conn.execute("update ex_config set todaybuy=todaybuy+1,todaytotal=todaytotal+"&cdbl(buynum*nowprice)&"")
		call exsm.calculatefund("no",sid)
		rs.close
		set rs=nothing
		exsm.exsmuserinfo(10)=now()
		session(exsm.placename&"exsmteuserid")=exsm.exsmuserinfo
	end sub
	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),",")
		sql="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 sql,stock_conn,1,1
		if not rst.eof then
			randomize
			rst.absoluteposition=fix(rst.recordcount*rnd)+1
			if round(rst(3),2)<=round(aitrade_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(aitrade_info(10)/100) then
					newprice=round(-closingprice*salenumhldcg*rnum/stocknum,2)
					zd=newprice/closingprice
					zangdierange=round(((nowprice+newprice-closingprice)/closingprice),4)
					if zangdierange<round(-aitrade_info(4)/100,2) then
						newprice=round(closingprice*(1+-round(aitrade_info(4)/100,2))-nowprice,2)
						zd=round(-aitrade_info(4)/100,2)-round((nowprice-closingprice)/closingprice,2)
					end if
					if nowprice+newprice<round(aitrade_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(aitrade_info(10)/100,2)+round(aitrade_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(aitrade_info(3)/100,2) then
						newprice=round(closingprice*(1+round(aitrade_info(3)/100,2))-nowprice,2)
						zd=round(aitrade_info(3)/100,2)-round((nowprice-closingprice)/closingprice,2)
					end if
					if nowprice+newprice<round(aitrade_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&"','"&exsm.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")
			call exsm.calculatefund("no",sid)
        	end if
		rst.close
		set rst=nothing
		exsm.exsmuserinfo(10)=now()
		session(exsm.placename&"exsmteuserid")=exsm.exsmuserinfo
	end sub
%>