<!--#include file="setup.asp"-->
<!--#include file="plus/Ex_Stock/Exsm_Plus_Conn.asp"-->
<!--#include file="plus/Ex_Stock/Exsm_Plus_Const.asp"-->
<%
	Dim page,Reg_Info,User_Info
	Reg_Info=split(Exsm.Stock_Setting(1),",")
	User_Info=split(Exsm.Stock_Setting(3),",")
	select case request("action")
		case "new"
			call Create()
		case "Userinfo"
			call Userinfo()
		case "SaveMyInfo"
			call SaveMyInfo()
		case "ReflashInFo"
			call ReflashInFo()
		case "AccountAdopt"
			call AccountAdopt()
		case "AccountDeposit"
			call AccountDeposit()
		case "AccountTransfer"
			call AccountTransfer()
		case else
			call main()
	End select
	Sub main()
		sql="select * from Ex_User where id="&Exsm.UserID&" And LockUser=0"
		set rs=stock_conn.execute(sql)
		if rs.eof and rs.bof then
			call Create()
		Else
			Exsm.Title 1,"股市帐户"
			page=request("page")
			If page="" Or Not isnumeric(page) Then page=1
			Dim ExRs
			Response.Write "<script language=""JavaScript"" src =""plus/Ex_Stock/Exsm_Plus_Mymanage.js""></script>"
			Response.Write "<Script Language=JavaScript>"
			Response.Write "var assignwidth="""&Exsm.AssignWidth&""";"
			Response.Write "var UserName="""&Exsm.htmlencode(Exsm.StockHolder)&""";"
			Response.Write "var usercutamelon="""&Split(Exsm.Stock_Setting(2),",")(1)&""";"
			Response.Write "var UserID="""&Exsm.UserID&""";"
			sql="select d.Code,d.Company,d.Sid,d.PossessStockSum,d.BuyPrice,d.AveragePrice,g.TradePrice,g.ManageMent,g.ManageMentID from EX_Customer d inner join EX_Stock g on d.Code=g.Code Where d.UserId="&Exsm.UserID&" order by d.PossessStockSum desc"
			Set Rs=server.createobject("adodb.recordset")
			rs.open sql,stock_conn,1,1
			If not Rs.eof Then
				Response.Write "var stockuserdivon=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
				ExRs=Rs.GetRows(Rs.PageSize)
				For i=0 To Ubound(ExRs,2)
					Response.Write "userstocklist["&i&"]='"
					Response.Write ExRs(0,i)
					Response.Write ","
					Response.Write Exsm.htmlencode(ExRs(1,i))
					Response.Write ","
					Response.Write ExRs(2,i)
					Response.Write ","
					Response.Write ExRs(3,i)
					Response.Write ","
					Response.Write ExRs(4,i)
					Response.Write ","
					Response.Write ExRs(5,i)
					Response.Write ","
					Response.Write ExRs(6,i)
					Response.Write ","
					Response.Write ExRs(7,i)
					Response.Write ","
					Response.Write ExRs(8,i)
					Response.Write "';"
				Next
				Response.Write "var recordcount="&Rs.RecordCount&";"
				Response.Write "var pagesize="&Rs.PageSize&";"
				Response.Write "var pagecount="&Rs.PageCount&";"
			Else
				Response.Write "var stockuserdivon=false;"
			End if
			Response.Write "stockuserdiv();"
			Response.Write "</Script>"
			Response.Write "<Script Language=JavaScript>"
			sqlbbs="select money from [user] where username='"&Exsm.StockHolder&"'"
			set rsbbs=conn.execute(sqlbbs)
			Response.Write "var assignwidth='"&Exsm.AssignWidth&"';"
			Response.Write "var userwealth='"&rsbbs(0)&"';"
			Response.Write "var usercash='"&Exsm.UserCash&"';"
			Response.Write "var user_info='"&Exsm.Stock_Setting(3)&"';"
			Response.Write "mymanage_show();"
			Response.Write "</Script>"
		End if
		Exsm.RootShow
	End Sub
	Sub Userinfo()
		If Not Exsm.Members Then
			Exsm.Errmess="<li>您还没有股票帐户，请先开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		Exsm.Title 1,"帐户设置"
		Set Rs=stock_conn.execute("select ID,TransferSecret,RankSecret,TradeSecret from EX_User Where ID="&Exsm.UserID&"")
		If not Rs.eof Then
			Response.Write "<script language=""JavaScript"" src =""plus/Ex_Stock/Exsm_Plus_Mymanage.js""></script>"
			Response.Write "<Script Language=JavaScript>"
			Response.Write "var assignwidth='"&Exsm.AssignWidth&"';"
			Response.Write "var transfersecret="&Rs(1)&";"
			Response.Write "var ranksecret="&Rs(2)&";"
			Response.Write "var tradesecret="&Rs(3)&";"
			Response.Write "mymanage_myinfo();"
			Response.Write "</Script>"
		End if
		Exsm.RootShow
	End Sub
	Sub Create()
		Dim Mycontent
		If Exsm.StockHolder="" Then
			Exsm.Errmess="<li>您是游客，不能开设股票帐户！请注册后在来。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If Exsm.Members Then
			Exsm.Errmess="<li>您已经有股票帐户了，怎么还来开户？"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If Cint(Reg_Info(0))=0 Then
			Exsm.Errmess="<li>股市暂停开户，请与管理员联系。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		sqlbbs="select posttopic,userlife,experience,money from [user] where username='"&Exsm.StockHolder&"'"
		set rsbbs=conn.execute(sqlbbs)
		if rsbbs(0)<Cint(Reg_Info(1)) Then
			Exsm.Errmess="<li>本股市已限制了开户最少发帖数为["&Reg_Info(1)&"]，您现在不符合本要求，暂时不能开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If rsbbs(1)<Cint(Reg_Info(2)) Then
			Exsm.Errmess="<li>本股市已限制了开户最少体力值为["&Reg_Info(2)&"]，您不符合本要求，暂时不能开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If rsbbs(2)<Cint(Reg_Info(3)) Then
			Exsm.Errmess="<li>本股市已限制了开户最少经验值为["&Reg_Info(3)&"]，您不符合本要求，暂时不能开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If rsbbs(3)<Cdbl(Reg_Info(4)) Then
			Exsm.Errmess="<li>本股市已限制了开户最少现金值为["&Reg_Info(4)&"]，您不符合本要求，暂时不能开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		rsbbs.close
		set rsbbs=nothing
		If Exsm.UserID<>0 Then
			sql="update Ex_User set LockUser=0,JoinDate="&SqlSmNowString&",LastTradeDate="&SqlSmNowString&" where ID="&Exsm.UserID&""
			stock_conn.execute (sql)
			Exsm.Sucmess="<li>股票帐户申请成功！由于你以前已经领取过股市资金，本次不再发放！"
			Call Exsm.Endinfo(1)
		Else
			sql="insert into Ex_User (UserName,UserWealth,UserAssets) values('"&Exsm.StockHolder&"',"&Reg_Info(5)&","&Reg_Info(5)&")"
			stock_conn.execute (sql)
			set rs=stock_conn.execute("select top 1 ID from Ex_User order by ID desc")
			Mycontent=replace("欢迎新股民[<a href=Exsm_Plus_Dispu.asp?uid="&Rs(0)&"><font color=#3366FF>"&Exsm.StockHolder&"</font></a>]进入["&Exsm.Setting_Info(0)&"]！","'","")
			stock_conn.execute("insert into EX_News (content,Color,addtime) values('"&Mycontent&"','"&Exsm.RndColor&"',"&SqlSmNowString&")")
			Exsm.DelStockCahe("ExSm_Imitate_UserSequence")
			Exsm.Sucmess="<li>股票帐户申请成功！["&Exsm.Setting_Info(0)&"]欢迎您的到来！并赠送给您["&Reg_Info(5)&"]元股市虚拟资金。"
			Call Exsm.Endinfo(1)
		End if
	End Sub
	Sub AccountAdopt()
		Dim Money(3),bbsqc,l_content
		If not Exsm.Members Then
			Exsm.Errmess="<li>您还没有股票帐户，请先开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If cint(User_Info(0))=0 Then
			Exsm.Errmess="<li>帐户提款暂时关闭不能进行操作。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		sqlbbs="select money from [user] where username='"&Exsm.StockHolder&"'"
		set rsbbs=conn.execute(sqlbbs)
		bbsqc=rsbbs(0)
		If bbsqc>1000000000 Then
			Exsm.Errmess="<li>错误您的帐户中资金大于[10]亿不能进行取款操作。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If not isnumeric(request.form("money")) Then
			Exsm.Errmess="<li>您没有输入提款金额或者输入的不是数字！"
			Call Exsm.Endinfo(1)
			Exit sub
		Elseif request.form("money")<=0 Then
			Exsm.Errmess="<li>您输入的提款金额不能小于等于零。"
			Call Exsm.Endinfo(1)
			Exit sub
		Elseif request.form("money")>=1000000000 Then
			Exsm.Errmess="<li>错误每次您取钱不能大于[10]亿。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		Money(0)=Round(request.form("money"),2)
		Money(3)=Round(Money(0)*(User_Info(6)/100),2)
		If Cdbl(User_Info(5))<=0 Then
			Money(2)=1
		Else
			Money(2)=Cdbl(User_Info(5))
		End if
		Money(1)=Round(Money(0)/Money(2),2)
		if Cdbl(Exsm.UserCash-(Money(0)+Money(3)))<Cdbl(Reg_Info(5)) Then
			Exsm.Errmess="<li>本股市规定：股票帐户基本资金不得低于["&FormatNumber(Reg_Info(5),2,-1)&"]元。"
			Call Exsm.Endinfo(1)
			Exit Sub
		Elseif Cdbl(Money(0))>Cdbl(User_Info(2)) And Cdbl(User_Info(2))>0 Then
			Exsm.Errmess="<li>对不起！您每次提款不能超过["&FormatNumber(User_Info(2),2,-1)&"]元。"
			Call Exsm.Endinfo(1)
			Exit Sub
		Elseif Cdbl(Money(0)+Money(3))>Cdbl(Exsm.UserCash) Then
			Exsm.Errmess="<li>对不起！您的取款数额大于帐户资金（取款数额["&FormatNumber(Money(0),2,-1)&"]手续费["&FormatNumber(Money(3),2,-1)&"]元），请重新填写。"
			Call Exsm.Endinfo(1)
			Exit Sub
		Else
			Sql="update Ex_User set UserWealth=UserWealth-"&Cdbl(Money(0)+Money(3))&",UserAssets=UserAssets-"&Cdbl(Money(0)+Money(3))&" where Id="&Exsm.UserID
			stock_conn.execute (Sql)
			SqlBbs="select * from [user] where username='"&Exsm.StockHolder&"'"
			Set Rs=server.createobject("adodb.recordset")
			Rs.Open SqlBbs,Conn,1,3
			Rs("money")=Rs("money")+Cdbl(Money(1))
			Rs.update
			Rs.close
			l_content=replace("资金流向：用户["&Exsm.StockHolder&"]，把股市资金["&Money(0)&"]元（手续费["&Money(3)&"]元），折合论坛帐户资金["&Money(1)&"]元，提取到论坛帐号 ","'","")
			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&"',6)")
			Exsm.Sucmess="<li>你提取股市虚拟资金["&FormatNumber(Money(0),2,-1)&"]元（手续费["&FormatNumber(Money(3),2,-1)&"]元），折合论坛帐户资金["&FormatNumber(Money(1),2,-1)&"]元，请妥善保管。"
			Call Exsm.Endinfo(1)
		End if
	End Sub
	sub AccountDeposit()
		Dim Money(3),bbsCash,l_content
		If not Exsm.Members Then
			Exsm.Errmess="<li>您还没有股票帐户，请先开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If Cint(User_Info(1))=0 Then
			Exsm.Errmess="<li>帐户存钱暂时关闭不能进行操作。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If not isnumeric(request.form("money")) Then
			Exsm.Errmess="<li>您没有输入提款金额或者输入的不是数字！"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		Money(0)=Round(request.form("money"),2)
		If Cdbl(Money(0))<=0 Then
			Exsm.Errmess="<li>您输入的提款金额不能小于等于零。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If Cdbl(User_Info(5))<=0 Then
			Money(2)=1
		Else
			Money(2)=Cdbl(User_Info(5))
		End if
		Money(1)=Round(Money(0)*Money(2),2)
		Money(3)=Round(Money(0)*(User_Info(7)/100),2)
		If CDbl(Money(1))>Cdbl(User_Info(3)) And Cdbl(User_Info(3))>0 Then
			Exsm.Errmess="<li>存钱操作每次最多只能存入["&FormatNumber(User_Info(3),2,-1)&"]元。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if	
		sqlbbs="select * from [user] where username='"&Exsm.StockHolder&"'"
		set rsbbs=conn.execute (sqlbbs)
		bbsCash=rsbbs("money")
		If Cdbl(Money(0)+Money(3))>Cdbl(bbsCash) Then
			Exsm.Errmess="<li>对不起！您在论坛中没有足够的资金（存款数额["&formatnumber(Money(0),2,-1)&"]手续费["&formatnumber(Money(3),2,-1)&"]元）。"
			Call Exsm.Endinfo(1)
			Exit sub
		Else
			SqlBbs= "select * from [user] where username='"&Exsm.StockHolder&"'"
			Set Rs=server.createobject("adodb.recordset")
			Rs.Open SqlBbs,Conn,1,3
			Rs("money")=Rs("money")-Cdbl(Money(0)+Money(3))
			Rs.update
			Rs.close
			Sql="update Ex_User set UserWealth=UserWealth+"&Cdbl(Money(1))&",UserAssets=UserAssets+"&Cdbl(Money(1))&" Where ID="&Exsm.UserID
			stock_conn.execute (Sql)
			l_content=replace("资金流向：用户["&Exsm.StockHolder&"]，把论坛帐户资金["&Money(0)+Money(3)&"]元（手续费["&Money(3)&"]元），折合股市资金["&Money(1)&"]元，存入了股市帐号 ","'","")
			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&"',6)")
			Exsm.Sucmess="<li>你已经把论坛帐户资金["&FormatNumber(Money(0)+Money(3),2,-1)&"]元（手续费["&FormatNumber(Money(3),2,-1)&"]元），折合股市虚拟资金["&FormatNumber(Money(1),2,-1)&"]元，存进了你的股票帐户。"
			Call Exsm.Endinfo(1)
		End if
	End Sub
	Sub AccountTransfer()
		Dim MingCheng,Money(1),JiSuan,ZiJin,RsM,Sql2,Mycontent,l_content
		If not Exsm.Members Then
			Exsm.Errmess="<li>您还没有股票帐户，请先开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		MingCheng=trim(replace(Request.form("MingCheng"),"'",""))
		if Cint(User_Info(4))=0 Then
			Exsm.Errmess="<li>论坛过户功能已经关闭。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		Money(0)=Request.form("XianJin")
		If Money(0)="" Or Not isnumeric(Money(0)) Then
			Exsm.Errmess="<li>请输入正确的过户资金。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		Money(0)=Round(Money(0),2)
		Money(1)=Round(Money(0)*(User_Info(8)/100),2)
		If Cdbl(Money(0))<=0 Then
			Exsm.Errmess="<li>请输入正确的过户资金。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		JiSuan=Cdbl(Exsm.UserCash-(Money(0)+Money(1)))
		If JiSuan=<1 Then
			Exsm.Errmess="<li>您的现有股市虚拟资金不足（过户数额["&formatnumber(Money(0)-Money(1),2,-1)&"]手续费["&formatnumber(Money(1),2,-1)&"]元）。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If MingCheng="" Then
			Exsm.Errmess="<li>请输入收取人名称！"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		SQL="select * from [Ex_User] Where UserName='"&MingCheng&"'"
		Set RsM=stock_conn.execute(SQL)
		If RsM.eof Then
			Exsm.Errmess="<li>股市里没有这用户！他可能不存在或没开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If RsM("TransferSecret")=0 Then
			Exsm.Errmess="<li>股市中没有找到该用户！他可能不存在或没开户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If MingCheng=Exsm.StockHolder Then
			Exsm.Errmess="<li>股市虚拟资金不能自己送给自己。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If Cdbl(Exsm.UserCash-(Money(0)+Money(1)))<Cdbl(Reg_Info(5)) Then	
			Exsm.Errmess="<li>本股市规定：股票帐户基本资金不得低于["&FormatNumber(Reg_Info(5),2,-1)&"]元（过户数额["&FormatNumber(Money(0),2,-1)&"]手续费["&FormatNumber(Money(1),2,-1)&"]元）。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		Sql="update Ex_User set UserWealth=UserWealth-"&Cdbl(Money(0)+Money(1))&",UserAssets=UserAssets-"&Cdbl(Money(0)+Money(1))&" where ID="&Exsm.UserID
		Set rs=stock_conn.execute(sql)
		Sql2="update Ex_User set UserWealth=UserWealth+"&Cdbl(Money(0)-Money(1))&",UserAssets=UserAssets+"&Cdbl(Money(0)-Money(1))&" Where UserName='"&MingCheng&"'"
		Set rs=stock_conn.execute(sql2)
		Mycontent=replace("股民[<a href=Exsm_Plus_Dispu.asp?uid="&Exsm.UserID&"><Font color="&Exsm.RndColor&">"&Exsm.StockHolder&"</Font></a>]过户给[<a href=Exsm_Plus_Dispu.asp?uid="&RsM("ID")&"><Font color="&Exsm.RndColor&">"&RsM("UserName")&"</Font></a>]股民["&Money(0)&"]元虚拟资金！请注意查收。","'","")
		stock_conn.execute("insert into EX_News(content,Color,addtime) values ('"&Mycontent&"','"&Exsm.RndColor&"',"&SqlSmNowString&")")
		l_content=replace("资金流向：用户["&Exsm.StockHolder&"]，过户给["&RsM("UserName")&"]["&Money(0)&"]元（手续费["&Money(1)&"]元）虚拟资金 ","'","")
		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&"',6)")
		Exsm.Sucmess="<li>您的虚拟资金["&FormatNumber(Money(0),2,-1)&"]元（手续费["&FormatNumber(Money(1),2,-1)&"]）已经成功送出。"
		Call Exsm.Endinfo(1)
	End sub
	Sub SaveMyInfo()
		Dim RankSecret,TradeSecret,TransferSecret
		If Not Exsm.Members Then
			Exsm.Errmess="<li>您还没有股票帐户，请先开户。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		RankSecret=Request.form("ranksecret")
		TradeSecret=Request.form("tradesecret")
		TransferSecret=Request.form("transfersecret")
		If RankSecret="" Or TradeSecret="" Or TransferSecret="" Or Not isnumeric(RankSecret) Or Not isnumeric(TradeSecret) Or Not isnumeric(TransferSecret) Then
			Exsm.Errmess="<li>非法参数！请返回。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		Sql="Update Ex_User set RankSecret="&RankSecret&",TradeSecret="&TradeSecret&",TransferSecret="&TransferSecret&" Where ID="&Exsm.UserID
		Set Rs=stock_conn.execute(sql)
		Exsm.DelStockCahe("ExSm_Imitate_UserSequence")
		Exsm.Sucmess="<li>帐户设置成功。"
		Call Exsm.Endinfo(1)
	End Sub
	Sub ReflashInFo()
		If not datediff("n",Session(Exsm.PlaceName&"ExsmTeUserID")(6),Now())>=10 Then
			Exsm.Errmess="<li>您可能刚刚登录或已经刷新过个人情况总揽，请["&Cint(10-datediff("n",Session(""&Exsm.PlaceName&"ExsmTeUserID")(6),Now()))&"]分钟后再次刷新。"
			Call Exsm.Endinfo(1)
			Exit sub
		Else
			Call Exsm.CalculateFund(Exsm.UserID,0)
			Exsm.ExsmUserInfo(6)=Now()
			Session(Exsm.PlaceName&"ExsmTeUserID")=Exsm.ExsmUserInfo
			response.Redirect Request.ServerVariables("HTTP_REFERER")
		End if
	End Sub
%>