<!--#include file="setup.asp"-->
<!--#include file="plus/Ex_Stock/Exsm_Plus_Conn.asp"-->
<!--#include file="plus/Ex_Stock/Exsm_Plus_Const.asp"-->
<%
	Dim ClosingPrice,NowPrice,NowNum,StockNum,TradeStockName,OpenPrice,TradeStockCode,newnum
	Dim sid,Trade_Info,BuyTime,SaleTime
	sid=request("sid")
	If Not Exsm.Members Then
		Exsm.Errmess="<li>您还没有股票帐户，不能炒股，请先开户。"
		Call Exsm.Endinfo(1)
	Else
		If sid="" or (not isnumeric(sid)) then
			Exsm.Errmess="<li>错误的参数，请指定正确的股票。"
			Call Exsm.Endinfo(1)
		Else
			Trade_Info=Split(Exsm.Stock_Setting(2),",")
			Sql="select Code,Company,TradePrice,ClosingPrice,TodayPermitTradeSum,LockStock from EX_Stock Where Sid="&sid
			Set Rs=stock_conn.execute(sql)
			If Rs.eof and Rs.bof Then
				Exsm.Errmess="<li>没有找到该股票。"
				Call Exsm.Endinfo(1)
			Elseif Rs(5)=1 Then
				Exsm.Errmess="<li>该股票已经封盘，不能进行交易。"
				Call Exsm.Endinfo(1)
			Elseif Rs(2)<Cdbl(Trade_Info(5)) Then
				Exsm.Errmess="<li>停牌的股票不能进行买卖操作请等待复盘。"
				Call Exsm.Endinfo(1)
			Else
				StockNum=Rs(4)
				NowNum=Rs(4)		'交易量
				NowPrice=Round(Rs(2),2)		'当前价格
				ClosingPrice=Round(Rs(3),2)
				TradeStockName=Rs(1)	'股票名称
				TradeStockCode=Rs(0)	'股票
				If Clng(Trade_Info(2))>0 And NowNum>Clng(Trade_Info(2)) Then NowNum=Clng(Trade_Info(2))
				select case request("action")
					case "trade"
						call Trade()
					case "UserFh"
						call UserFh()
					case "UserHl"
						call UserHl()
					case else
						call main()
				End select
			End if
		End if
	End if
	Sub Main()
		Exsm.Title 1,""&TradeStockName&"-交易"
		Dim Sushare,PermitTradeSum,RankSecret,TradeSecret,BuyMax
		Sql="select PossessStockSum from EX_Customer where UserId="&Exsm.UserID&" and sid="&sid
		Set Rs=stock_conn.execute(sql)
		If Rs.eof then 
			Sushare=0
			PermitTradeSum=0
		Else
			Sushare=Rs(0)
			PermitTradeSum=Rs(0)
			If Clng(Trade_Info(2))>0 And PermitTradeSum>Clng(Trade_Info(2)) Then PermitTradeSum=Clng(Trade_Info(2))
		End if

		Rs.close
		Set Rs=Nothing
		Set Rs=stock_conn.execute("select ID,RankSecret,TradeSecret from EX_User Where ID="&Exsm.UserID&"")
		RankSecret=Rs(1)
		TradeSecret=Rs(2)
		Rs.close
		Set Rs=Nothing
		If NowNum<Fix(Exsm.UserCash/(NowPrice*(1+Trade_Info(6)/100))) Then
			BuyMax=NowNum
		Else
			BuyMax=Replace(Formatnumber(Fix(Exsm.UserCash/(NowPrice*(1+Trade_Info(6)/100))),0,-1),",","")
		End if
		If BuyMax+0>NowNum+0 Then BuyMax=NowNum
		Response.Write "<script language=""JavaScript"" src =""plus/Ex_Stock/Exsm_Plus_MyDispose.js""></script>"
		Response.Write "<script language=""JavaScript"">"
		Response.Write "var assignwidth='"&Exsm.AssignWidth&"';"
		Response.Write "TradeAsk="&Clng(Trade_Info(2))&";"
		Response.Write "StockSum="&NowNum&";"
		Response.Write "StockPrice="&NowPrice&";"
		Response.Write "Poundage="&Trade_Info(6)/100&";"
		Response.Write "</Script>"
		Response.Write "<script language=""JavaScript"" src =""plus/Ex_Stock/Exsm_Plus_Exchange.js""></script>"
		Response.Write "<Script Language=JavaScript>"
		Response.Write "var assignwidth='"&Exsm.AssignWidth&"';"
		Response.Write "var stockcode='"&TradeStockCode&"';"
		Response.Write "var stockname='"&Exsm.htmlencode(TradeStockName)&"';"
		Response.Write "var stocksid="&sid&";"
		Response.Write "var stocknum='"&StockNum&"';"
		Response.Write "var nowprice='"&NowPrice&"';"
		Response.Write "var usercash='"&Exsm.UserCash&"';"
		Response.Write "var buymax='"&BuyMax&"';"
		Response.Write "var tradelimit="&Clng(Trade_Info(2))&";"
		Response.Write "var poundage="&Round(Trade_Info(6),2)&";"
		Response.Write "var permittradesum='"&PermitTradeSum&"';"
		Response.Write "var sushare='"&sushare&"';"
		Response.Write "var ranksecret="&RankSecret&";"
		Response.Write "var tradesecret="&TradeSecret&";"
		Response.Write "show_trade_info();"
		Response.Write "</Script>"
		Exsm.RootShow
	End Sub
	Sub Trade()
		Dim Privacy,ManageMent,UserName
		Dim BuyNum,DelMoney,Poundage,Rnum,Rate,NewPrice,Zd,TotalStockNum,BuyNumhldcg,ZangDieRange,Mycontent,Color,MyNum,AgvPrice
		Dim SaleNum,AddMoney,Rname,RemainNum,SaleNumhldcg
		Privacy=Request.Form("Privacy")
		ManageMent=Request.Form("ManageMent")
		If Privacy=1 Then
			UserName=Exsm.StockHolder
		Else
			UserName="[ExU]"&Exsm.StockHolder&"[/ExU]"
		End if
		If Request("Put")="购买" Then
			BuyNum=Request.Form("BuyNum")
			If Trade_Info(0)=0 Then
				Exsm.Errmess="<li>股市交易已经暂停，不能进行股票买卖操作。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If BuyNum="" Or (Not isnumeric(BuyNum)) Then
				Exsm.Errmess="<li>请正确输入购买数量。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If not datediff("s",Session(Exsm.PlaceName&"ExsmTeUserID")(7),Now())>10 Then
				Exsm.Errmess="<li>您可能刚刚登录或再次买入股票最少间隔[10]秒钟。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			BuyNum=Round(BuyNum,2)
			If BuyNum<1 Then
				Exsm.Errmess="<li>请正确输入购买数量。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If NowNum>100 And BuyNum<100 Then
				Exsm.Errmess="<li>本股市限制每次最少交易量为[100]股！"
				Call Exsm.Endinfo(1)
				Exit Sub
			Elseif Clng(Trade_Info(2))>0 And BuyNum>Clng(Trade_Info(2)) Then
				Exsm.Errmess="<li>本股市限制每次最大交易量为["&Trade_Info(2)&"]股！"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			DelMoney=BuyNum*NowPrice
			Poundage=DelMoney*(Trade_Info(6)/100)
			If Exsm.UserCash<Round(DelMoney+Poundage,2) Then
				Exsm.Errmess="<li>您的资金不足以购买指定的股票，您可以减少购买数量或者购买其它股票。"
				Call Exsm.Endinfo(1)
			Elseif NowNum<BuyNum Then
				Exsm.Errmess="<li>没有足够的股票数量，您可以减少购买数量或者购买其它股票。"
				Call Exsm.Endinfo(1)
			End if
			If NowNum<100 And NowNum-BuyNum>0 Then
				Exsm.Errmess="<li>您购买的股票数量已经不足最少交易量[100]股，您必须全部买入。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			BuyNumhldcg=BuyNum
			If BuyNum>10000 Then BuyNumhldcg=10000
			Set Rs=stock_conn.execute("select TradePrice,StockSum,TodayPermitTradeSum from EX_Stock Where sid="&sid)
			If Rs.eof And Rs.bof Then
				Exsm.Errmess="<li>错误的股票参数！请确定该股票存在。"
				Call Exsm.Endinfo(1)
				Exit Sub
			Elseif NowPrice<>Round(Rs(0),2) Or StockNum<>Rs(2) Then
				Exsm.Errmess="<li>可能您很长时间没有活动造成数据停滞！请返回后刷新页面再进行交易。"
				Call Exsm.Endinfo(1)
				Exit Sub
			Else
				TotalStockNum=Rs(1)
				If TotalStockNum<5000000 Or TotalStockNum>20000000 Then TotalStockNum=20000000
				TotalStockNum=TotalStockNum/30
			End if
			Rs.close
			Set Rs=Nothing
			Randomize
			Rate=Rnd
			Rnum=Rnd
			If Rnum<=0.4 Then Rnum=Rnum+0.5
			If Rate<Round(Trade_Info(8)/100,2) Then
				NewPrice=Round(ClosingPrice*BuyNumhldcg*Rnum/TotalStockNum,2)
				ZD=NewPrice/ClosingPrice
				ZangDieRange=Round(((NowPrice+NewPrice-ClosingPrice)/ClosingPrice)*100,2)
				If ZangDieRange>Round(Trade_Info(3),2) Then
					NewPrice=Round(ClosingPrice*(1+Round(Trade_Info(3)/100,2))-NowPrice,2)
					ZD=Round(Trade_Info(3)/100,2)-((NowPrice-ClosingPrice)/ClosingPrice)
				End if
				If NowPrice+NewPrice<Round(Trade_Info(5),2) Then NewPrice=0	:	ZD=0
				If Round(ZD,4)=0 Then
					Mycontent="股民["&UserName&"]买入["&TradeStockName&"]["&BuyNum&"]股，现价没有波动"
				Else
					Mycontent="股民["&UserName&"]买入["&TradeStockName&"]["&BuyNum&"]股，现价上涨["&FormatPercent(ZD,2,-1)&"]"
				End if
				Color=Exsm.RndColor
			Elseif Rate<Round(Trade_Info(8)/100,2)+Round(Trade_Info(9)/100,2) Then
				NewPrice=Round(-ClosingPrice*BuyNumhldcg*Rnum/TotalStockNum,2)
				ZD=NewPrice/ClosingPrice
				ZangDieRange=Round(((NowPrice+NewPrice-ClosingPrice)/ClosingPrice)*100,2)
				If ZangDieRange<-Trade_Info(4)+0 Then
					NewPrice=Round(ClosingPrice*(1+Round(-Trade_Info(4)/100,2))-NowPrice,2)
					ZD=Round(-Trade_Info(4)/100,2)-((NowPrice-ClosingPrice)/ClosingPrice)
				End if
				If NowPrice+NewPrice<Round(Trade_Info(5),2) Then NewPrice=0	:	ZD=0
				If Round(ZD,4)=0 Then
					Mycontent="股民["&UserName&"]买入["&TradeStockName&"]["&BuyNum&"]股，现价没有波动"
				Else
					Mycontent="股民["&UserName&"]买入["&TradeStockName&"]["&BuyNum&"]股，现价下滑["&Replace(FormatPercent(ZD,2,-1),"-","")&"]"
				End if
				Color=Exsm.RndColor
			Else
				NewPrice=0
				ZD=0
				Mycontent="股民["&UserName&"]买入["&TradeStockName&"]["&BuyNum&"]股，现价没有波动"
				Color=Exsm.RndColor
			End if
			set Rs=stock_conn.execute("select PossessStockSum,AveragePrice,BuyTime from EX_Customer Where Sid="&Sid&" And UserId="&Exsm.UserID&"")
			If Rs.eof And Rs.bof Then
				If ChangeOptB(Sid,Exsm.UserID,Exsm.StockHolder,BuyNum,ManageMent)=True Then Mycontent=Mycontent+"，并取得经营权。"
				stock_conn.execute("update EX_Stock set TradePrice=TradePrice+"&Cdbl(NewPrice)&",SurplusShare=SurplusShare-"&Round(BuyNum)&",TodayPermitTradeSum=TodayPermitTradeSum-"&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,Sid,BuyPrice,AveragePrice,PossessStockSum,Company,Code) values ('"&Exsm.StockHolder&"',"&Exsm.UserID&","&Sid&",'"&NowPrice&"','"&NowPrice&"','"&BuyNum&"','"&TradeStockName&"','"&TradeStockCode&"')")
				stock_conn.execute("update Ex_User set UserWealth=UserWealth-"&Round(DelMoney+Poundage,2)&",PossessSort=PossessSort+1,TodayBuy=TodayBuy+1,TotalBuy=TotalBuy+1,LastTradeDate="&SqlSmNowString&" Where ID="&Exsm.UserID)
				stock_conn.execute("insert into EX_News (content,Color,addtime) values('"&Mycontent&"','"&Color&"',"&SqlSmNowString&")")
			Else
				MyNum=rs(0)
				AgvPrice=rs(1)
				If ChangeOptB(Sid,Exsm.UserID,Exsm.StockHolder,BuyNum+MyNum,ManageMent)=True Then Mycontent=Mycontent+"，并取得经营权。"
				AgvPrice=(NowPrice*BuyNum+AgvPrice*MyNum)/(BuyNum+MyNum)
				stock_conn.execute("update EX_Stock set TradePrice=TradePrice+"&Cdbl(NewPrice)&",SurplusShare=SurplusShare-"&Round(BuyNum)&",TodayPermitTradeSum=TodayPermitTradeSum-"&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 PossessStockSum=PossessStockSum+"&Round(BuyNum)&",BuyPrice="&Round(NowPrice,2)&",AveragePrice="&Round(AgvPrice,2)&",BuyTime="&SqlSmNowString&" Where UserId="&Exsm.UserID&" And Sid="&Sid)
				stock_conn.execute("update Ex_User set UserWealth=UserWealth-"&Round(DelMoney+Poundage,2)&",TodayBuy=TodayBuy+1,TotalBuy=TotalBuy+1 Where ID="&Exsm.UserID)
				stock_conn.execute("insert into EX_News (content,Color,addtime) values('"&Mycontent&"','"&Color&"',"&SqlSmNowString&")")
			End if
			stock_conn.execute("update EX_Config set TodayBuy=TodayBuy+1,TodayTotal=TodayTotal+"&Cdbl(DelMoney)&",ExColExp=ExColExp+"&Cdbl(ZD*100)&"")
			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
			Call GivePoundage(Sid,Poundage)
			Call Exsm.CalculateFund(Exsm.UserID,Sid)
			Exsm.ExsmUserInfo(7)=Now()
			Session(Exsm.PlaceName&"ExsmTeUserID")=Exsm.ExsmUserInfo
			Exsm.Sucmess="<li>股票购买成功！"
			Call Exsm.Endinfo(1)
		End if
		If Request("Put")="出售" Then
			SaleNum=Request.Form("SaleNum")
			If Trade_Info(0)=0 Then
				Exsm.Errmess="<li>股市交易已经暂停，不能进行股票买卖操作。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If SaleNum="" Or (Not isnumeric(SaleNum)) Then
				Exsm.Errmess="<li>请正确输入卖出数量。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If not datediff("s",Session(Exsm.PlaceName&"ExsmTeUserID")(7),Now())>10 Then
				Exsm.Errmess="<li>您可能刚刚登录或再次卖出股票最少间隔[10]秒钟。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			SaleNum=Round(SaleNum,2)
			If SaleNum<1 Then
				Exsm.Errmess="<li>请正确输入卖出数量。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			RemainNum=StockNum+SaleNum
			AddMoney=SaleNum*NowPrice
			Poundage=AddMoney*(Trade_Info(6)/100)
			set Rs=stock_conn.execute ("select PossessStockSum,BuyTime,SellTime from EX_Customer Where UserId="&Exsm.UserID&" And Sid="&sid&"")
			If Rs.eof And Rs.bof Then
				Exsm.Errmess="<li>您没有这只股票，无法进行卖出操作。"
				Call Exsm.Endinfo(1)
				Exit Sub
			Elseif Datediff("h",Rs(1),Now())<Cint(Trade_Info(7)) Then
				Exsm.Errmess="<li>股市实行T+0操作，离可以抛出该股票还差["&(Trade_Info(7)*60-Datediff("n",Rs(1),Now()))&"]分钟！"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If Rs(0)>100 And SaleNum<100 Then
				Exsm.Errmess="<li>本股市限制每次最少交易量为[100]股！"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If Clng(Trade_Info(2))>0 And SaleNum>Clng(Trade_Info(2)) Then
				Exsm.Errmess="<li>本股市限制每次最大交易量为["&Trade_Info(2)&"]股！"
				Call Exsm.Endinfo(1)
				Exit Sub
			Else
				MyNum=Rs(0)-SaleNum
			End if
			If MyNum<0 Then
				Exsm.Errmess="<li>您没有足够的股票卖出！请减少卖出数量。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If Rs(0)<100 And MyNum>0 Then
				Exsm.Errmess="<li>您的股票数不足最少交易量[100]股，您必须全部卖出。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			Rs.close
			Set Rs=Nothing
			SaleNumhldcg=SaleNum
			If SaleNum>10000 Then SaleNumhldcg=10000
			Set Rs=stock_conn.execute("select TradePrice,StockSum,TodayPermitTradeSum from EX_Stock Where sid="&sid)
			If Rs.eof And Rs.bof Then
				Exsm.Errmess="<li>错误的股票参数！请确定该股票存在。"
				Call Exsm.Endinfo(1)
				Exit Sub
			Elseif NowPrice<>Round(Rs(0),2) Or StockNum<>Rs(2) Then
				Exsm.Errmess="<li>可能您很长时间没有活动造成数据停滞！请返回后刷新页面再进行交易。"
				Call Exsm.Endinfo(1)
				Exit Sub
			Else
				TotalStockNum=Rs(1)
				If TotalStockNum<5000000 Or TotalStockNum>20000000 Then TotalStockNum=20000000
				TotalStockNum=TotalStockNum/30
			End if
			Rs.close
			Set Rs=Nothing
			Randomize
			Rate=Rnd
			Rnum=Rnd
			If Rnum<=0.4 then Rnum=Rnum+0.5
			If Rate<Round(Trade_Info(10)/100,2) Then
				NewPrice=Round(-NowPrice*SaleNumhldcg*Rnum/TotalStockNum,2)
				ZD=NewPrice/NowPrice
				ZangDieRange=Round(((NowPrice+NewPrice-ClosingPrice)/ClosingPrice)*100,2)
				If ZangDieRange<-Round(Trade_Info(4),2) Then
					NewPrice=Round(ClosingPrice*(1+Round(-Trade_Info(4)/100,2))-NowPrice,2)
					ZD=Round(-Trade_Info(4)/100,2)-((NowPrice-ClosingPrice)/ClosingPrice)
				End if
				If NowPrice+NewPrice<Round(Trade_Info(5),2) Then NewPrice=0	:	ZD=0
				If Round(ZD,4)=0 Then
					Mycontent="股民["&UserName&"]卖出["&TradeStockName&"]["&SaleNum&"]股，现价没有波动"
				Else
					Mycontent="股民["&UserName&"]卖出["&TradeStockName&"]["&SaleNum&"]股，现价下滑["&Replace(FormatPercent(ZD,2,-1),"-","")&"]"
				End if
				Color=Exsm.RndColor
			Elseif Rate<Round(Trade_Info(10)/100,2)+Round(Trade_Info(11)/100,2) Then
				NewPrice=Round(NowPrice*SaleNumhldcg*Rnum/TotalStockNum,2)
				ZD=NewPrice/NowPrice
				ZangDieRange=Round(((NowPrice+NewPrice-ClosingPrice)/ClosingPrice)*100,2)
				If ZangDieRange>Round(Trade_Info(3),2) Then
					NewPrice=Round(ClosingPrice*(1+Round(Trade_Info(3)/100,2))-NowPrice,2)
					ZD=Round(Trade_Info(3)/100,2)-((NowPrice-ClosingPrice)/ClosingPrice)
				End if
				If NowPrice+NewPrice<Round(Trade_Info(5),2) Then NewPrice=0	:	ZD=0
				If Round(ZD,4)=0 Then
					Mycontent="股民["&UserName&"]卖出["&TradeStockName&"]["&SaleNum&"]股，现价没有波动"
				Else
					Mycontent="股民["&UserName&"]卖出["&TradeStockName&"]["&SaleNum&"]股，现价上涨["&FormatPercent(ZD,2,-1)&"]"
				End if
				Color=Exsm.RndColor
			Else
				NewPrice=0
				ZD=0
				Mycontent="股民["&UserName&"]卖出["&TradeStockName&"]["&SaleNum&"]股，现价没有波动"
				Color=Exsm.RndColor
			End if
			stock_conn.execute("update EX_Stock set SurplusShare=SurplusShare+"&Round(SaleNum)&",TradePrice=TradePrice+"&Round(NewPrice)&",TodayPermitTradeSum="&Round(RemainNum)&",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="&Round(MyNum)&",Selltime="&SqlSmNowString&" Where UserId="&Exsm.UserID&" And Sid="&sid)
			stock_conn.execute("update Ex_User set UserWealth=UserWealth+"&Round(AddMoney-Poundage,2)&",TodaySell=TodaySell+1,TotalSell=TotalSell+1 where ID="&Exsm.UserID)
			If MyNum<=0 Then stock_conn.execute("update Ex_User set PossessSort=PossessSort-1 where ID="&Exsm.UserID)
			stock_conn.execute("delete from EX_Customer Where PossessStockSum<=0")
			Rname=ChangeOptS(sid,Exsm.UserID,Exsm.StockHolder,MyNum,ManageMent)
			If Rname<>"" Then Mycontent=Mycontent&"，["&Rname&"]获得该股的经营权。"
			stock_conn.execute("insert into EX_News (content,Color,addtime) values('"&Mycontent&"','"&Color&"',"&SqlSmNowString&")")
			stock_conn.execute("update EX_Config set TodaySell=TodaySell+1,TodayTotal=TodayTotal+"&Cdbl(AddMoney)&",ExColExp=ExColExp+"&Cdbl(ZD*100)&"")
			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
			call GivePoundage(sid,Poundage)
			call Exsm.CalculateFund(Exsm.UserID,Sid)
			Exsm.ExsmUserInfo(7)=Now()
			Session(Exsm.PlaceName&"ExsmTeUserID")=Exsm.ExsmUserInfo
			Exsm.Sucmess="<li>股票卖出成功！"
			Call Exsm.Endinfo(1)
		End if
	End sub
	Function ChangeOptB(Sid,UserId,UserName,TotalNum,ManageMent)
		ChangeOptB=false
		If ManageMent=0 Then ChangeOptB=false:Exit Function
		set Rs=stock_conn.execute("select ManageMentID from EX_Stock Where Sid="&Sid)
		If Rs(0)=0 Then
			stock_conn.execute("update EX_Stock set ManageMentID="&UserId&",ManageMent='"&UserName&"' where Sid="&Sid)
			ChangeOptB=True
		Elseif Rs(0)<>UserId Then
			set Rs=stock_conn.execute("select top 1 PossessStockSum,UserId from EX_Customer Where Sid="&Sid&" And UserId<>"&UserId&" order by PossessStockSum desc")
			If not Rs.eof Then
				If Cdbl(TotalNum)>Rs(0) Then
					stock_conn.execute("update EX_Stock set ManageMent='"&UserName&"',ManageMentID="&UserId&" where Sid="&Sid)
					ChangeOptB=True
				End if
			End if
		End if
	End Function
	Function ChangeOptS(sid,UserId,UserName,RemNum,ManageMent)
		Dim Rst
		ChangeOptS=""
		If ManageMent=0 Then
			RemNum=0
		End if
		set Rst=stock_conn.execute("select ManageMentID from EX_Stock Where Sid="&sid)
		Set Rs=stock_conn.execute("select top 1 d.PossessStockSum,d.UserName,d.UserId from EX_Customer d inner join EX_User u on d.UserId=u.ID Where d.UserId>0 And d.Sid="&Sid&" And d.UserId<>"&UserId&" And u.RankSecret=1 order by d.PossessStockSum desc")
		If not Rs.eof Then
			If Cdbl(RemNum)>Rs(0) Then
				If Rst(0)=UserId Then
					ChangeOptS=""
					Exit Function
				Else
					stock_conn.execute("update EX_Stock set ManageMent='"&UserName&"',ManageMentID="&UserId&" Where Sid="&sid) 
					ChangeOptS=UserName
				End if
			Elseif Cdbl(RemNum)<Rs(0) Then
				If Rst(0)=Rs(2) Then
					ChangeOptS=""
					Exit Function
				Else
					stock_conn.execute("update EX_Stock set ManageMent='"&Rs(1)&"',ManageMentID="&Rs(2)&" Where Sid="&sid) 
					ChangeOptS=Rs(1)
				End if
			End if
		Elseif RemNum<=0 Then
			stock_conn.execute("update EX_Stock set ManageMent=null,ManageMentID=0 Where Sid="&sid)
		End if
	End Function
	Sub GivePoundage(id,HandleMoney)
		set Rs=stock_conn.execute("select ManageMentID from EX_Stock Where Sid="&id)
		If not Rs.eof Then
			If Not Rs(0)=Exsm.UserID Then
				stock_conn.execute("update Ex_User set UserWealth=UserWealth+"&Round(HandleMoney,2)&",UserAssets=UserAssets+"&Cdbl(HandleMoney)&" Where ID="&rs(0)&"")
			End if
		End if
	End Sub
	Sub UserFh()
		Dim page,ExUserSql,MyUserInfo,Rst,TotalNum,UserNum
		Dim ExRsFh,GupiaoValue,GupiaoCost
		Dim currentPage,page_count,totalrec,Pcount
		If Trade_Info(1)=0 Then
			Exsm.Errmess="<li>股东分红功能已经关闭请返回。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If Exsm.StockAdmin Then
			Exsm.Errmess="<li>管理员["&Exsm.StockHolder&"]您好，请到后台进行股票分红。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		TotalNum=stock_conn.execute("select sum(PossessStockSum) from EX_Customer where Not UserId="&Exsm.UserId&" And UserId>0 And sid="&sid&"")(0)
		UserNum=stock_conn.execute("select count(*) from EX_Customer where Not UserId="&Exsm.UserId&" And UserId>0 and sid="&sid&"")(0)
		set Rst=stock_conn.execute("select top 1 UserId from EX_Customer where sid="&sid&" order by PossessStockSum desc,Buytime desc")
		If not Rst.eof Then
			If UserNum<=0 Then
				Exsm.Errmess="<li>暂时没有人购买或只有您持有这只股票，不需要分红。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If Not Rst(0)=Exsm.UserId Then
				Exsm.Errmess="<li>您不是最大股东不能进行分红操作。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
		Else
			Exsm.Errmess="<li>暂时没有人购买这只股票，不需要分红。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		Exsm.Title 1,""&TradeStockName&"-分红选项"
		page=request("page")
		If page="" Or Not isnumeric(page) Then page=1
		Response.Write "<script language=""JavaScript"" src =""plus/Ex_Stock/Exsm_Plus_MyDispose.js""></script>"
		Response.Write "<script language=""JavaScript"" src =""plus/Ex_Stock/Exsm_Plus_Exchange.js""></script>"
		Response.Write "<Script Language=JavaScript>"
		Response.Write "var assignwidth="""&Exsm.AssignWidth&""";"
		Response.Write "var username='"&Exsm.htmlencode(Exsm.StockHolder)&"';"
		Response.Write "var stockcode="&TradeStockCode&";"
		Response.Write "var stockname='"&Exsm.htmlencode(TradeStockName)&"';"
		Response.Write "var totalnum='"&TotalNum&"';"
		Response.Write "var usernum='"&UserNum&"';"
		Response.Write "var usercash='"&Exsm.UserCash&"';"
		Response.Write "var nowprice='"&NowPrice&"';"
		Response.Write "var closingprice='"&ClosingPrice&"';"
		Response.Write "var stocksid="&sid&";"
		Sql="select * from EX_Customer where Not UserId="&Exsm.UserID&" And UserId>0 And Sid="&sid&" order by PossessStockSum desc,Buytime desc"
		Set Rs=server.createobject("adodb.recordset")
		Rs.open Sql,stock_conn,1,1
		If not Rs.eof Then
			Response.Write "var useron=true;"
			Rs.PageSize=CInt(Exsm.Setting_Info(15))
			If page+0>Rs.PageCount Then page=Rs.PageCount
			Response.Write "var page="&page&";"
			Rs.AbsolutePage=page
			ExUserSql=Rs.GetRows(Rs.PageSize)
			For i=0 To Ubound(ExUserSql,2)
				Response.Write "userstocklist["&i&"]='"&Exsm.htmlencode(ExUserSql(0,i))&","&ExUserSql(1,i)&","&ExUserSql(2,i)&","&ExUserSql(3,i)&","&ExUserSql(4,i)&","&ExUserSql(5,i)&","&ExUserSql(6,i)&","&ExUserSql(7,i)&","&ExUserSql(8,i)&","&ExUserSql(9,i)&"';"
				Response.Write vbNewLine
			Next
		Else
			Response.Write "var useron=false;"
		End if
		Response.Write "var recordcount="&Rs.RecordCount&";"
		Response.Write "var pagesize="&Rs.PageSize&";"
		Response.Write "var pagecount="&Rs.PageCount&";"
		set Rs=stock_conn.execute("select * from Ex_User where ID="&Exsm.UserID&"")
		MyUserInfo=Rs.GetRows(1)
		Response.Write "myuserinfo='"&MyUserInfo(4,0)&","&MyUserInfo(5,0)&","&MyUserInfo(6,0)&","&MyUserInfo(7,0)&","&MyUserInfo(8,0)&","&MyUserInfo(11,0)&","&MyUserInfo(12,0)&"';"
		Response.Write "show_userfh_info();"
		Response.Write "</Script>"
		Exsm.RootShow
	End Sub
	Sub UserHl()
		Dim sid,price,hongliNum,songguNum,title,addMoney
		Dim Addnum,SumNum,UserSumNum,SumSid,UserUid,QiYeName
		Dim Rst,TotalNum,UserNum,Uscontent,Mycontent,l_content
		addMoney=0
		sid=Request.Form("sid")
		hongliNum=Request.Form("hongliNum")
		songguNum=Request.Form("songguNum")
		title=replace(request("title"),"'","")
		Uscontent=replace(request("content"),"'","")
		If Trade_Info(1)=0 Then
			Exsm.Errmess="<li>股东分红功能已经关闭请返回。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If Exsm.StockAdmin Then
			Exsm.Errmess="<li>管理员["&Exsm.StockHolder&"]您好，请到后台进行股票分红。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		set rs=stock_conn.execute("select * from EX_Stock where sid="&sid&"")
		If rs.eof and rs.bof Then
			Exsm.Errmess="<li>指定的股票不存在，请确认传递的参数是否正确。"
			Call Exsm.Endinfo(1)
			Exit Sub
		Elseif Rs("LockStock")=1 Then
			Exsm.Errmess="<li>该股票已经封盘，不能进行操作。"
			Call Exsm.Endinfo(1)
			Exit Sub
		Elseif rs("TradePrice")<Cdbl(Trade_Info(5)) Then
			Exsm.Errmess="<li>停牌的股票不能进行操作请等待复盘。"
			Call Exsm.Endinfo(1)
			Exit Sub
		Else
			price=Rs("TradePrice")
		End if
		If hongliNum<>"" and songguNum<>"" Then
			Exsm.Errmess="<li>您每次只能选择一项进行分红请返回！"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If sid="" or not isnumeric(sid) Then
			Exsm.Errmess="<li>数据传输错误，请重新选择股票！"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If hongliNum<>"" Then
			If hongliNum="" or not isnumeric(hongliNum) Then
				Exsm.Errmess="<li>请输入正确的分红金额。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			hongliNum=Round(hongliNum,2)
			If hongliNum=0 Then
				Exsm.Errmess="<li>请输入正确的分红金额，输入金额不能为[0]。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
		Elseif songguNum<>"" Then
			If songguNum="" or not isnumeric(songguNum)  Then
				Exsm.Errmess="<li>请输入正确的分红金额。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			songguNum=Round(songguNum,2)
			If songgunum<=0 Then
				Exsm.Errmess="<li>送股比例不能为零或者负数。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
		Else
			Exsm.Errmess="<li>非法参数！请返回！"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If title="" or title="公告主题限制[100]Byte以内！" or Exsm.Syllable(title)>100 Then
			Exsm.Errmess="<li>请输入公告标题，或主题长度大于了[100]Byte。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If Uscontent="" or Uscontent="公告内容限制[500]Byte以内！" or Exsm.Syllable(Uscontent)>500 Then
			Exsm.Errmess="<li>请输入公告内容，或内容长度大于了[500]Byte。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		TotalNum=stock_conn.execute("select sum(PossessStockSum) from EX_Customer where Not UserId="&Exsm.UserId&" And UserId>0 And sid="&sid&"")(0)
		UserNum=stock_conn.execute("select count(*) from EX_Customer where Not UserId="&Exsm.UserId&" And UserId>0 and sid="&sid&"")(0)
		set Rst=stock_conn.execute("select top 1 UserId from EX_Customer where sid="&sid&" order by PossessStockSum desc,Buytime desc")
		If not Rst.eof Then
			If UserNum<=0 Then
				Exsm.Errmess="<li>暂时没有人购买或只有您持有这只股票，不需要分红。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If not Rst(0)=Exsm.UserID Then
				Exsm.Errmess="<li>您不是最大股东不能进行分红操作。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
		Else
			Exsm.Errmess="<li>暂时没有人购买这只股票，不需要分红。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If hongliNum<>"" Then
			If Cdbl(Exsm.UserCash)<Cdbl(TotalNum/10*hongliNum) Then
				Exsm.Errmess="<li>您没有足够的可用资金提供分红，请适当减少分红数量或者放弃此次分红。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			If hongliNum+0<-price*0.1+0 Then
				Exsm.Errmess="<li>负红最大值为当前股票价格的百分之十（"&-price*0.1&"）！请重新填写。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			hongliNum=Formatnumber(hongliNum,2,-1)
			stock_conn.execute "update Ex_User set UserWealth=UserWealth-"&Round(TotalNum/10*hongliNum,2)&",UserAssets=UserAssets-"&Round(TotalNum/10*hongliNum,2)&" Where ID="&Exsm.UserID&""
			Set Rs=stock_conn.execute("select * from EX_Customer where Not UserId="&Exsm.UserId&" And UserId>0 and sid="&sid&"")
			do while not rs.eof
				addMoney=hongliNum*(Rs("PossessStockSum")/10)
				stock_conn.execute "update Ex_User set UserWealth=UserWealth+"&Round(addMoney,2)&",UserAssets=UserAssets+"&Round(addMoney,2)&" Where ID="&Rs("UserId")&""
			rs.movenext
			loop
			set rs=stock_conn.execute("select * from EX_Customer Where Sid="&sid&"")
			stock_conn.execute("insert into EX_Announcement (title,content,username,color,addtime) values('"&title&"','"&Uscontent&"','"&Exsm.StockHolder&"','"&request.Form("color")&"',"&SqlSmNowString&")")
			Mycontent=replace("系统信息：上市公司["&Rs("Company")&"]每[10]股现金派息["&honglinum&"]元！分红股东["&Exsm.StockHolder&"]","'","")
			stock_conn.execute("insert into EX_News (content,Color,addtime) values('"&Mycontent&"','"&Exsm.RndColor&"',"&SqlSmNowString&")")
			l_content=replace("股票管理：分红，上市公司["&Rs("Company")&"]每[10]股现金派息["&Formatnumber(hongliNum,2,-1)&"]元，股东["&Exsm.StockHolder&"] ","'","")
			stock_conn.execute("insert into EX_Log (l_boardid,l_touser,l_username,l_content,l_addtime,l_ip,l_type) values('"&Exsm.UserID&"','"&Exsm.ScriptName&"','"&Exsm.StockHolder&"','"&l_content&"',"&SqlSmNowString&",'"&Exsm.UserIP&"',5)")
			Exsm.DelStockCahe("Exsm_Imitate_Ann")
			Exsm.DelStockCahe("Exsm_Imitate_News")
			Exsm.Sucmess="<li>红利分配成功，每[10]股现金派息["&Formatnumber(hongliNum,2,-1)&"]元！"
			Call Exsm.Endinfo(1)
		Elseif songguNum<>"" Then
			If Cdbl(Exsm.UserCash)<Cdbl(TotalNum/10*(songgunum*price)) Then
				Exsm.Errmess="<li>您没有足够的可用资金提供分红，请适当减少分红数量或者放弃此次分红。"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			stock_conn.execute "update Ex_User set UserWealth=UserWealth-"&Round(TotalNum/10*(songgunum*price),2)&",UserAssets=UserAssets-"&Round(TotalNum/10*(songgunum*price),2)&" where ID="&Exsm.UserID&""
			Set Rs=stock_conn.execute("select Sid,PossessStockSum,UserId,Company from EX_Customer where Not UserId="&Exsm.UserId&" And UserId>0 And sid="&sid&"")
			Addnum=0 : SumNum=0
			Do while not Rs.eof
				UserSumNum=Rs(1) : SumSid=Rs(0) : UserUid=Rs(2) : QiYeName=Rs(3)
				Addnum=CDbl((UserSumNum/10)*songguNum)
				SumNum=CDbl(SumNum+Addnum)
				stock_conn.execute("update EX_Customer set PossessStockSum=PossessStockSum+"&Round(Addnum)&" where UserId="&UserUid&" And sid="&SumSid&"")
				Call Exsm.CalculateFund(SumSid,0)
			Rs.movenext
			loop
			stock_conn.execute "update EX_Stock set StockSum=StockSum+"&Round(SumNum)&" Where Sid="&sid&""
			stock_conn.execute("insert into EX_Announcement (title,content,username,color,addtime) values('"&title&"','"&Uscontent&"','"&Exsm.StockHolder&"','"&request.Form("color")&"',"&SqlSmNowString&")")
			Mycontent=replace("系统信息：上市公司["&QiYeName&"]每[10]股赠送["&formatnumber(songgunum,0,-1)&"]股！分红股东["&Exsm.StockHolder&"]","'","")
			stock_conn.execute("insert into EX_News (content,Color,addtime) values('"&Mycontent&"','"&Exsm.RndColor&"',"&SqlSmNowString&")")
			l_content=replace("股票管理：送股，上市公司["&QiYeName&"]每[10]股赠送["&Formatnumber(songgunum,0,-1)&"]股，股东["&Exsm.StockHolder&"] ","'","")
			stock_conn.execute("insert into EX_Log (l_boardid,l_touser,l_username,l_content,l_addtime,l_ip,l_type) values('"&Exsm.UserID&"','"&Exsm.ScriptName&"','"&Exsm.StockHolder&"','"&l_content&"',"&SqlSmNowString&",'"&Exsm.UserIP&"',5)")
			Exsm.DelStockCahe("Exsm_Imitate_Ann")
			Exsm.DelStockCahe("Exsm_Imitate_News")
			Exsm.Sucmess="<li>送股成功，每[10]股赠送["&Replace(Formatnumber(songgunum,0,-1),",","")&"]股！"
			Call Exsm.Endinfo(1)
		End if
	End Sub
%>