<!--#include file="setup.asp"-->
<!--#include file="plus/Ex_Stock/Exsm_Plus_Conn.asp"-->
<!--#include file="plus/Ex_Stock/Exsm_Plus_Const.asp"-->
<%
	'检查用户名和ＩＤ是否合法
	If Exsm.UserID="" or Exsm.UserID=0 or not isnumeric(Exsm.UserID) or Exsm.StockHolder="" Then
		Response.Redirect "Exsm_Plus_Gupiao.asp"
	Else
		set Rs=stock_conn.execute("select UserName,LockUser from Ex_User where ID="&Exsm.UserID&"")
		'是否存在用户
		If Rs.eof and Rs.bof Then
			Response.Redirect "Exsm_Plus_Gupiao.asp"
		'用户是否锁定
		Elseif Rs(1)>1 Then
			Response.Redirect "Exsm_Plus_Gupiao.asp"
		'是否已经登录
		Elseif not Exsm.Members Then
			Response.Redirect "Exsm_Plus_Gupiao.asp"
		'检查用户等级
		Elseif not Exsm.StockAdmin Then
			Response.Redirect "Exsm_Plus_Gupiao.asp"
		'再次验证身份
		Elseif not Rs(0)=Exsm.StockHolder Then
			Response.Redirect "Exsm_Plus_Gupiao.asp"
		Else
			select case request("action")
				case "UserReward"
					call UserReward()
				case "UserList"
					call UserList()
				case "EditUser"
					call EditUser()
				case "SaveUserEdit"
					call SaveUserEdit()
				case "DelUser"
					call DelUser()
				case "SaveDelUser"
					call SaveDelUser()
				case "AdminUserStock"
					call AdminUserStock()
				case "ExAdminSt"
					call ExAdminSt()
				case "DelUserList"
					call DelUserList()
				case else
					call main()
			End select
		End if
	End if
	Sub main()
		Exsm.Title 1,"客户奖扣管理"
%>
		<table class=a2 width=<%=Exsm.AssignWidth%> cellspacing=1 cellpadding=3 align=center border=0 id=Ex>
			<tr>
				<td height="25" align=center height=25 class=a1>-=> 客 户 奖 扣 管 理 <=-</td>
			</tr>
			<form name="form" method="post" action="?action=UserReward">
			<tr>
				<td class=a3><u>操作理由</u>&nbsp;<input name="logtxt" size="70">&nbsp;*</td>
			</tr>
			<tr> 
				<td class=a3><u>奖扣对象</u>&nbsp;<select name="rewardto">
					<option value="0" selected>指定股民</option>
					<option value="1">所有股民</option>
					</select>&nbsp;名称：<input type=text size="54" name=reusername>&nbsp;*</td>
			</tr>
			<tr> 
				<td class=a3><u>奖扣金额</u>&nbsp;<input type=text size="20" name=rewardmoney></td>
			</tr>
			<tr>
				<td class=a3><u>资产刷新</u>&nbsp;<input type=radio name="ReflashInFo" value="no" checked>不同步刷新&nbsp;<input type=radio name="ReflashInFo" value="yes">同步刷新用户资产（较消耗资源！）
			</tr>
			<tr>
				<td class=a3><u>信息发布</u>&nbsp;<input name="messagetxt" size="70" value="">&nbsp;<input type="checkbox" name="use" value=1>使用</td>
			</tr>
			<tr>
				<td class=a3><u>奖扣说明</u><br>①指定用户可以使用英文逗号隔开同时奖扣多位用户。<br>②如果选择了“刷新用户资产信息”则在干预的同时同步刷新用户资产信息（较消耗资源！）。<br>③如果使用了信息发布，系统将发布即时信息以便通知股民。</td>
			</tr>
			<tr>
				<td  class=a4 align=center><input type="submit" name="submit" value="提交">&nbsp;&nbsp;<input type="reset" value="重填"></td>
			</tr>
			</form>
		</table>
		<script language="JavaScript">setTimeout("winwidth()",1000)</script>
<%
		Exsm.RootShowA
	End Sub
	Sub UserReward()
		Dim Reusername,Rei,Rsuser,Rewardto,Rewardmoney,ReuserUser,LogTxt,MessageTxt
		Dim Reii,ReUs,Statist,AddStatist,Statistok,AddStatistok,AddNum,ReUserID
		Rewardto=Request.form("rewardto")
		Rewardmoney=Request.form("rewardmoney")
		LogTxt=trim(replace(Request.form("logtxt"),"'",""))
		MessageTxt=trim(replace(Request.form("messagetxt"),"'",""))
		If LogTxt="" Or Exsm.Syllable(LogTxt)>250 Then
			Exsm.Errmess="<li>操作理由不能为空。"
			Call Exsm.Endinfo(1)
			Exit sub
		Else
			ReuserUser="奖励[所有股民]"
			If Request.form("StockSum")=0 Then ReuserUser="奖励用户["&trim(replace(Request.form("reusername"),"'",""))&"]"
			LogTxt="用户操作："&ReuserUser&" "&LogTxt&""
		End if
		If Rewardto=0 Then
			If trim(replace(Request.form("reusername"),"'",""))="" Then
				Exsm.Errmess="<li>请输入需要奖励的用户名称。"
				Call Exsm.Endinfo(1)
				Exit sub
			End if
		End if
		Reusername=split(trim(replace(Request.form("reusername")," ","")),",")
		If Rewardmoney="" or (not isnumeric(Rewardmoney)) or Rewardmoney=0 Then
			Exsm.Errmess="<li>请正确输入奖励的金额。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If Request.form("use")=1 And MessageTxt="" Or Exsm.Syllable(MessageTxt)>250 Then
			Exsm.Errmess="<li>您选择了使用信息发布功能请填写信息内容。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If Rewardto=0 Then
			AddNum=0
			for Rei=0 to UBound(Reusername)
				set Rsuser=stock_conn.execute("select * from Ex_User where UserName='"&Reusername(Rei)&"'")
				If not Rsuser.eof Then
					Statistok=Reusername(Rei)
					AddStatistok=""&AddStatistok&"["&Statistok&"]"
				Else
					AddNum=AddNum+1
					Statist=Reusername(Rei)
					AddStatist=""&AddStatist&"["&Statist&"]"
				End if
			next
			If AddStatist<>"" Then
				Exsm.Errmess="<li>发现["&AddNum&"]位未知用户"&AddStatist&"，奖励被终止请返回检查！"
				Call Exsm.Endinfo(1)
				Exit Sub
			End if
			for Reii=0 to UBound(Reusername)
				set Rsuser=stock_conn.execute("select * from Ex_User where UserName='"&Reusername(Reii)&"'")
				If not Rsuser.eof Then
					stock_conn.execute("update Ex_User set UserWealth=UserWealth+"&Round(Rewardmoney,2)&",UserAssets=UserAssets+"&Round(Rewardmoney,2)&" where UserName='"&Reusername(Reii)&"'")
				End if
			next
		End if
		If Rewardto=1 Then
			set Rsuser=stock_conn.execute("select ID from Ex_User where LockUser=0")
			Do while not Rsuser.eof
				ReUserID=Rsuser(0)
				stock_conn.execute("update Ex_User set UserWealth=UserWealth+"&Round(Rewardmoney,2)&",UserAssets=UserAssets+"&Round(Rewardmoney,2)&" where ID="&ReUserID&"")
			Rsuser.movenext
			loop
		End if
		If Request.form("use")=1 Then
			stock_conn.execute("insert into EX_News (content,Color,addtime) values('"&MessageTxt&"','"&Exsm.RndColor&"',"&SqlSmNowString&")")
		End if
		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&"','"&LogTxt&"',"&SqlSmNowString&",'"&Exsm.UserIP&"',5)")
		If Request.form("ReflashInFo")="yes" Then Call Exsm.CalculateFund(0,0)
		Exsm.DelStockCahe("Exsm_Imitate_News")
		Exsm.Sucmess="<li>奖励股民成功，请返回。"
		Call Exsm.Endinfo(1)
	End Sub
	Sub UserList()
		If request("search")="search" Then
			Dim username,UserSql
			username=trim(replace(request("username"),"'",""))
			If username="" Then
				Exsm.Errmess="<li>请输入查找关键字。"
				Call Exsm.Endinfo(1)
				Exit sub
			End if
			If request("usernamechk")="yes" Then
				UserSql= "select * from Ex_User where UserName='"&username&"'"
			Else
				UserSql= "select * from Ex_User where UserName like '%"&username&"%'"
			End if
		Else
			UserSql= "select * from Ex_User order by ID desc"
		End if
		Exsm.Title 1,"客户管理"
%>
		<table class=a2 width=<%=Exsm.AssignWidth%> cellspacing=1 cellpadding=3 align=center border=0>
			<tr>
				<td align=center height=25 class=a1>-=> <%=Exsm.Setting_Info(0)%> - 客 户 管 理 <=-</td>
			</tr>
			<tr>
				<form name="form1" method="post" action="?action=UserList&search=search">
				<td class=a3>快速查找：<input type="text" name=username SIZE="20"> <input type="checkbox" name="usernamechk" value="yes" checked>用户名完全匹配<input type="submit" name="Submit" value="查询客户"></td>
				</form>
			</tr>
		</table>
		<br>
		<table class=a2 width=<%=Exsm.AssignWidth%> cellspacing=1 cellpadding=3 align=center border=0>
			<tr align=center height=25 class=a1>
				<td>帐户</td>
				<td>资金</td>
				<td>总资金</td>
				<td>持股种类</td>
				<td>今日买入</td>
				<td>今日卖出</td>
				<td>总买入</td>
				<td>总卖出</td>
				<td>最后日期</td>
				<td>状态</td>
				<td>管理</td>
			</tr>
<%
		Dim currentpage,page_count,Pcount
		Dim totalrec,endpage
		currentPage=request("page")
		If currentpage="" or not isnumeric(currentpage) Then
			currentpage=1
		End if
		Set rs= Server.CreateObject("ADODB.Recordset")
		rs.open UserSql,stock_conn,1,1
		If rs.eof and rs.bof Then
			response.write "<tr><td class=a3 colspan=12> 没有找到任何股民</td></tr>"
		Else
			rs.PageSize=CInt(Exsm.Setting_Info(16))
			rs.AbsolutePage=currentpage
			page_count=0
			totalrec=rs.recordcount
			do while (not rs.eof) and (not page_count = rs.PageSize)
%>
				<tr align=center> 
					<td class=a3><a href="?action=EditUser&username=<%=Rs("UserName")%>"><%=Rs("UserName")%></a></td>
					<td class=a3 align="right"><%=Formatnumber(Rs("UserWealth"),2,-1)%>&nbsp;</td>
					<td class=a3 align="right"><%=Formatnumber(Rs("UserAssets"),2,-1)%>&nbsp;</td>
					<td class=a3 align="right"><%=Rs("PossessSort")%>&nbsp;</td>
					<td class=a3 align="right"><%=Rs("TodayBuy")%>&nbsp;</td>
					<td class=a3 align="right"><%=Rs("TodaySell")%>&nbsp;</td>
					<td class=a3 align="right"><%=Rs("TotalBuy")%>&nbsp;</td>
					<td class=a3 align="right"><%=Rs("TotalSell")%>&nbsp;</td>
					<td class=a3><%=Formatdatetime(Rs("LastTradeDate"),2)%></td>
					<td class=a3><%If Rs("LockUser")=1 Then%><font color=red>锁定</font><%Else%>正常<%End if%></td>
					<td class=a3><a style="cursor:hand" onmouseover="cziemenu(event,'<div><a href=?action=EditUser&username=<%=rs("UserName")%>>编辑用户</a></div><div><a href=?action=AdminUserStock&UserID=<%=rs("ID")%>>持股管理</a></div><%If Rs("LockUser")=0 Then%><div><%If Rs("ID")=Exsm.UserID Then%><a><font color=#555555>锁定用户</font></a><%Else%><a href=?action=SaveUserEdit&UserID=<%=rs("ID")%>&lock=1>锁定用户</a><%End if%></div><%Else%><div><a href=?action=SaveUserEdit&UserID=<%=rs("ID")%>&lock=0>解除锁定</a></div><%End if%><%If Rs("ID")=Exsm.UserID Then%><div><a><font color=#555555>删除用户</font></a></div><%Else%><div><a href=?action=DelUser&userid=<%=Rs("ID")%>&username=<%=Rs("UserName")%>>删除用户</a></div><%End if%>','',0)">操作</a></td>
				</tr>
			<%page_count = page_count + 1
			rs.movenext
			loop
			Pcount=rs.PageCount%>
		</table>
		<table width=<%=Exsm.AssignWidth%> cellspacing=0 cellpadding=3 align=center border=0>
			<tr>
				<td align=left> 共有 <font color=blue><%=totalrec%></font> 个股民，每页 <font color=blue><%=rs.PageSize%></font> 个，第 <font color=red><%=currentpage%></font> 页 / 共 <font color=blue><%=Pcount%></font> 页</td>
				<td align=right>分页：<%
				If currentpage > 4 Then
					response.write "<a href=""?action=UserList&page=1"">[1]</a> ..."
				End if
				If Pcount>currentpage+3 Then
					endpage=currentpage+3
				Else
					endpage=Pcount
				End if
				for i=currentpage-3 to endpage
				If not i<1 Then
					If i = clng(currentpage) Then
						response.write " <font color=red>["&i&"]</font>"
					Else
						response.write " <a href=""?action=UserList&page="&i&""">["&i&"]</a>"
					End if
				End if
				next
				If currentpage+3 < Pcount Then 
					response.write "... <a href=""?action=UserList&page="&Pcount&""">["&Pcount&"]</a>"
				End if
				response.Write "</td></tr>"
		End if
		rs.close
		set rs=nothing
		response.Write "</table>"
		Exsm.RootShowA
	End Sub
	Sub EditUser()
		Dim username,rsusera,Sql
		username=trim(replace(request("username"),"'",""))
		If username="" Then
			Exsm.Errmess="<li>错误的参数，请指定用户名。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if	
		Sql= "select * from Ex_User Where UserName='"&username&"'"
		set rsusera=stock_conn.execute(Sql)
		If rsusera.eof then
			Exsm.Errmess="<li>未发现指定的用户，请确认传递的参数是否正确。"
			Call Exsm.Endinfo(1)
			Exit sub
		Else
			Exsm.Title 1,"客户管理"
%>
			<table class=a2 width=<%=Exsm.AssignWidth%> cellspacing=1 cellpadding=3 align=center border=0 id=Ex>
				<tr>
					<td align=center height=25 class=a1>-=> 编 辑 股 民 <font color=red><%=rsusera("UserName")%></font> 资 料 <=-</td>
				</tr>
				<form method=post action="?action=SaveUserEdit">
				<tr>
					<td class=a3><u>Ｕ Ｉ Ｄ</u>&nbsp;<%=rsusera("ID")%><input type=hidden name=Uid value="<%=rsusera("ID")%>"></td>
				</tr>
				<tr>
					<td class=a3><u>帐　　户</u>&nbsp;<font color=blue><%=rsusera("UserName")%></font><input type=hidden name=username value="<%=rsusera("UserName")%>"></td>
				</tr>
				<tr>
					<td class=a3><u>开户日期</u>&nbsp;<%=rsusera("JoinDate")%></td>
				</tr>
				<tr>
					<td class=a3><u>最后日期</u>&nbsp;<%=rsusera("LastTradeDate")%></td>
				</tr>
				<tr>
					<td class=a3><u>状　　态</u>&nbsp;<input type=radio name=Locked value="0" <%if rsusera("LockUser")<>1 then%> checked <%end if%>>正常 <input type=radio name=Locked value="1" <%if rsusera("LockUser")=1 then%> checked <%end if%>>锁定</td>
				</tr>
				<tr>
					<td class=a3><u>虚拟资金</u>&nbsp;<input type=text name=Crash value="<%=formatnumber(rsusera("UserWealth"),2,-1)%>" size="20"></td>
				</tr>
				<tr>
					<td  class=a4 align=center><input type=submit name=submit value="执行修改"></td>
				</tr>
				</form>
			</table>
			<script language="JavaScript">setTimeout("winwidth()",1000)</script>
<%
		End if
		Exsm.RootShowA
	End Sub
	Sub SaveUserEdit()
		Dim Uid,UserID,UserIDF,UserLock
		Dim UserName,RsUserId,UserCrash,ReportLv,l_content
		UserID=request("UserID")
		UserIDF=request.Form("Uid")
		UserLock=request("lock")
		If UserLock<>"" Then
			If UserID="" or (not isnumeric(UserID)) Then
				Exsm.Errmess="<li>错误的参数，请指定用户名。"
				Call Exsm.Endinfo(1)
				Exit Sub
			Else
				Uid=UserID
			End if
		Else
			If UserIDF="" or (not isnumeric(UserIDF)) Then
				Exsm.Errmess="<li>错误的参数，您所进行的操作非法。"
				Call Exsm.Endinfo(1)
				Exit Sub
			Else
				Uid=UserIDF
			End if
		End if
		Set Rs=stock_conn.execute("select * from Ex_User where id="&Uid&"")
		If Rs.eof then
			Exsm.Errmess="<li>未知用户！请指定有效用户。"
			Call Exsm.Endinfo(1)
			Exit Sub
		Else
			RsUserId=Rs("ID")
			UserName=Rs("UserName")
			UserCrash=Round(Rs("UserWealth"),2)
			If UserLock<>"" Then
				If RsUserId=Exsm.UserID And UserLock=1 Then
					Exsm.Errmess="<li>您不能锁定自己！"
					Call Exsm.Endinfo(1)
					Exit Sub
				Else
					If UserLock=0 Then
						stock_conn.execute("update Ex_User set LockUser=0 where ID="&RsUserId&"")
						ReportLv="正常"
					Else
						stock_conn.execute("update Ex_User set LockUser=1 where ID="&RsUserId&"")
						ReportLv="锁定"
					End if
					l_content=replace("用户操作：修改用户["&UserName&"]状态["&ReportLv&"] ","'","")
					stock_conn.execute("insert into EX_Log (l_boardid,l_touser,l_username,l_content,l_addtime,l_ip,l_type) values('"&Exsm.UserID&"','"&username&"','"&Exsm.StockHolder&"','"&l_content&"',"&SqlSmNowString&",'"&Exsm.UserIP&"',5)")
					If Request.ServerVariables("HTTP_REFERER")<>"" Then
						response.Redirect Request.ServerVariables("HTTP_REFERER")
					Else
						Response.Write "<script language=JavaScript>javascript:history.go(-1)</script>"
						Response.Write "<script language=JavaScript>setTimeout(""window.close()"",1000)</script>"
					End if
				End if
			Else
				If RsUserId=Exsm.UserID And Request.Form("Locked")=1 Then
					Exsm.Errmess="<li>您不能锁定自己！"
					Call Exsm.Endinfo(1)
					Exit Sub
				Else
					stock_conn.execute("update Ex_User set UserWealth="&Round(request.form("Crash"),2)&",LockUser="&request.form("Locked")&" where ID="&RsUserId&"")
					l_content=replace("用户操作：修改用户["&UserName&"]资金由["&UserCrash&"]元 修改为["&Round(request.form("Crash"),2)&"]元 状态：锁定["&request.form("Locked")&"] ","'","")
					stock_conn.execute("insert into EX_Log (l_boardid,l_touser,l_username,l_content,l_addtime,l_ip,l_type) values('"&Exsm.UserID&"','"&username&"','"&Exsm.StockHolder&"','"&l_content&"',"&SqlSmNowString&",'"&Exsm.UserIP&"',5)")
					Exsm.Sucmess="<li>用户["&UserName&"]的资料更新成功。"
					Call Exsm.Endinfo(1)
				End if
			End if
		End if
	End Sub
	Sub DelUser()
		Dim DelUserId,DelUserName
		DelUserId=request("userid")
		DelUserName=trim(replace(request("username"),"'",""))
		If DelUserId="" Or not isnumeric(DelUserId) Or DelUserName="" Then
			Exsm.Errmess="<li>未知用户！请指定有效用户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If DelUserId+0=Exsm.UserID Then
			Exsm.Errmess="<li>您不能删除自己！"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		Set Rs=stock_conn.execute("select * from Ex_User Where ID="&DelUserId&" And UserName='"&DelUserName&"'")
		If Rs.eof and Rs.bof Then
			Exsm.Errmess="<li>未知用户！请指定有效用户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		Exsm.Title 1,"用户管理"
%>
		<table class="tableborder1" cellspacing="1" cellpadding="3" align="center" border="0" id="Ex">
			<tr>
				<td align=center height=25 class=a1>-=> 用 户 管 理 - 删 除 用 户 [<%=DelUserName%>] <=-</td>
			</tr>
			<form method="post" action="?action=SaveDelUser">
			<tr>
				<td class=a3><u>操作理由</u>&nbsp;<input name="logtxt" size="70">&nbsp;*</td>
			</tr>
			<tr>
				<td class=a3><u>资金流向</u>&nbsp;<input type=radio name="UserWealth" value=1 checked>返还到论坛帐户&nbsp;<input type=radio name="UserWealth" value=0>冻结资金（用户资金将消失！）</td>
			</tr>
			<tr>
				<td class=a3><u>股票流向</u>&nbsp;<input type=radio name="StockSum" value=1 checked>返还到<%=Exsm.Setting_Info(0)%>&nbsp;<input type=radio name="StockSum" value=0>注销股票（被删用户股票将消失！）</td>
			</tr>
			<tr>
				<td class=a3><u>信息发布</u>&nbsp;<input name="messagetxt" size="70" value="股民[<%=DelUserName%>]因违规操作被清除出股市！">&nbsp;<input type="checkbox" name="use" value=1>使用</td>
			</tr>
			<tr>
				<td class=a3><u>管理说明</u><br>①如果使用了信息发布，系统将发布即时信息以便通知股民。</td>
			</tr>
			<input type=hidden name=DelUserId value="<%=DelUserId%>">
			<input type=hidden name=DelUserName value="<%=DelUserName%>">
			<tr>
				<td class=a4 align="center"><input type="submit" value="确定" name="b1">&nbsp;&nbsp;<input type="reset" value="重填" name="b2"></td>
			</tr>
			</form>
		</table>
		<script language="JavaScript">setTimeout("winwidth()",1000)</script>
<%
		Exsm.RootShowA
	End Sub
	Sub SaveDelUser()
		Dim DelUserId,DelUserName,LogTxt,MessageTxt,sid,userwealth1,money2
		Dim User_Info,Reg_Info,DelUserWealth,DelStockSum
		Reg_Info=split(Exsm.Stock_Setting(1),",")
		User_Info=split(Exsm.Stock_Setting(3),",")
		DelUserId=request.form("DelUserId")
		DelUserName=trim(replace(request.form("DelUserName"),"'",""))
		LogTxt=trim(replace(Request.form("logtxt"),"'",""))
		MessageTxt=trim(replace(Request.form("messagetxt"),"'",""))
		If DelUserId="" Or not isnumeric(DelUserId) Or DelUserName="" Then
			Exsm.Errmess="<li>未知用户！请指定有效用户。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If DelUserId+0=Exsm.UserID Then
			Exsm.Errmess="<li>您不能删除自己！"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If LogTxt="" Or Exsm.Syllable(LogTxt)>250 Then
			Exsm.Errmess="<li>操作理由不能为空。"
			Call Exsm.Endinfo(1)
			Exit sub
		Else
			DelUserWealth="冻结资金"
			DelStockSum="注销股票"
			If Request.form("UserWealth")=1 Then DelUserWealth="资金返还到论坛帐户"
			If Request.form("StockSum")=1 Then DelStockSum="返还到社区股市"
			LogTxt="用户操作：删除股民["&DelUserName&"] "&LogTxt&" "&DelUserWealth&" "&DelStockSum&""
		End if
		If Request.form("use")=1 And MessageTxt="" Or Exsm.Syllable(MessageTxt)>250 Then
			Exsm.Errmess="<li>您选择了使用信息发布功能请填写信息内容。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If Cdbl(User_Info(5))<=0 Then
			money2=1
		Else
			money2=Cdbl(User_Info(5))
		End if
		Set Rs=stock_conn.execute("select * from Ex_User Where ID="&DelUserId&" And UserName='"&DelUserName&"'")
		If rs.eof Then
			Exsm.Errmess="<li>未知用户！请指定有效用户。"
			Call Exsm.Endinfo(1)
			Exit sub
		Else
			Call ConnectionDatabase()
			If Request.form("UserWealth")=1 And Rs("UserAssets")>Cdbl(Reg_Info(5)) Then
				userwealth1=(Rs("UserAssets")-Cdbl(Reg_Info(5)))/money2
				If userwealth1>1000000000 Then
					userwealth1=1000000000
				Else
					userwealth1=(Rs("UserAssets")-CDbl(Reg_Info(5)))/money2
				End if
				conn.execute("update [Dv_User] set userwealth=userwealth+"&Cdbl(userwealth1)&" where username='"&DelUserName&"'")
			End if
			If Request.form("StockSum")=1 Then
				Set Rs=stock_conn.execute("select Sid,PossessStockSum from EX_Customer Where UserName='"&DelUserName&"' And UserId="&DelUserId&"")
				If not Rs.eof Then
					do while not Rs.eof
						stock_conn.execute("update EX_Stock set SurplusShare=SurplusShare+"&Round(Rs(1))&" Where Sid="&Rs(0)&"")
					Rs.movenext
					loop
				End if
			Rs.close
			End if
			stock_conn.execute "delete from EX_Customer Where UserName='"&DelUserName&"' And UserId="&DelUserId&""
			stock_conn.execute "delete from Ex_User Where ID="&DelUserId&" And UserName='"&DelUserName&"'"
			If Request.form("use")=1 Then
				stock_conn.execute("insert into EX_News (content,Color,addtime) values('"&MessageTxt&"','"&Exsm.RndColor&"',"&SqlSmNowString&")")
			End if
			stock_conn.execute("insert into EX_Log (l_boardid,l_touser,l_username,l_content,l_addtime,l_ip,l_type) values('"&Exsm.UserID&"','"&DelUserName&"','"&Exsm.StockHolder&"','"&LogTxt&"',"&SqlSmNowString&",'"&Exsm.UserIP&"',5)")
			Exsm.DelStockCahe("ExSm_Imitate_UserSequence")
			Exsm.DelStockCahe("Exsm_Imitate_News")
			Exsm.Sucmess="<li>删除股民["&DelUserName&"]成功。"
			Call Exsm.Endinfo(1)
		End if
	End Sub
	Sub AdminUserStock()
		Dim UserID,UserName
		Dim MyGupiaoNum,MyGupiaoValue,MyGupiaoCost,id
		Dim TotalGranRate,Pcount
		Dim rst,currentpage,totalrec,page_count,CurrentPrice,AgvInPrice
		Dim bj,TotalGain,GranRate
		UserID=request("UserID")
		If UserID="" or (not isnumeric(UserID)) Then
			Exsm.Errmess="<li>错误的参数，请指定用户名。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		set Rs=stock_conn.execute("select * from Ex_User where ID="&UserID&"")
		If Rs.eof and Rs.bof Then
			Exsm.Errmess="<li>指定的用户不存在，请确认传递的参数是否正确。"
			Call Exsm.Endinfo(1)
			Exit Sub
		Else
			UserName=Rs("UserName")
		End if
		MyGupiaoNum=0 :	MyGupiaoValue=0 :	MyGupiaoCost=0:		TotalGranRate=0
		sql="select d.*,g.TradePrice from EX_Customer d inner join EX_Stock g on d.sid=g.sid where d.UserId="&UserID&""
		set rs=stock_conn.execute(sql)
		if rs.eof and rs.bof then
			Exsm.Errmess="<li>未发现指定用户的股票信息！他可能没有购买股票或是未知用户。"
			Call Exsm.Endinfo(1)
		Else
			Exsm.Title 1,""&UserName&"-持股管理"
%>
			<table class=a2 width=<%=Exsm.AssignWidth%> cellspacing=1 cellpadding=1 align=center>
			<tr>
				<td colspan=11 align=center height=25 class=a1>-=> [<%=UserName%>] 持 股 管 理 <=-</td>
			</tr>
			<form action="?action=ExAdminSt" method="post" name="form">
			<tr align=center height=20>
				<td class=a4><b>代码</b></td>
				<td class=a4><b>股票名称</b></td>
				<td class=a4><b>拥有数量</b></td>
				<td class=a4><b>持股成本</b></td>
				<td class=a4><b>当前价</b></td>
				<td class=a4><b>持股价</b></td>
				<td class=a4><b>持股现值</b></td>
				<td class=a4><b>每股盈亏</b></td>
				<td class=a4><b>总盈亏</b></td>
				<td class=a4><b>盈亏率</b></td>
				<td class=a4><b>操作</b></td>
			</tr>
<%
			currentPage=request("page")
			if currentpage="" or not isnumeric(currentpage) then
				currentpage=1
			end if
			Set rs= Server.CreateObject("ADODB.Recordset")
			rs.open sql,stock_conn,1,1
			if rs.eof and rs.bof then
			else
				rs.PageSize=CInt(Exsm.Setting_Info(15))
				rs.AbsolutePage=currentpage
				page_count=0
				totalrec=rs.recordcount
				do while (not rs.eof) and (not page_count = rs.PageSize)
					CurrentPrice=formatnumber(Rs("TradePrice"),2,-1)
					AgvInPrice=formatnumber(Rs("AveragePrice"),2,-1)
					MyGupiaoNum=MyGupiaoNum+Rs("PossessStockSum")
					MyGupiaoValue=MyGupiaoValue+(Rs("PossessStockSum"))*CurrentPrice
					MyGupiaoCost=MyGupiaoCost+(Rs("PossessStockSum"))*AgvInPrice
%>
			<tr align=right>
				<td class=a3 align=center><Font color="olive"><%=Rs("Code")%></Font></td>
				<td class=a3 align=center width="15%"><a href="Exsm_Plus_DispCompare.asp?sid=<%=rs("sid")%>"><%=rs("Company")%></a><input type="hidden" name="StockName<%=rs("sid")%>" value="<%=rs("Company")%>"></td>
				<td class=a3 align=center width="145"><input type=text name="NewChiGuShu<%=rs("sid")%>" value="<%=replace(formatnumber(rs("PossessStockSum"),0,-1),",","")%>"><input type="hidden" name="ChiGuShu<%=rs("sid")%>" value="<%=replace(formatnumber(rs("PossessStockSum"),0,-1),",","")%>"></td>
				<td class=a3><%=formatcurrency(AgvInPrice*rs("PossessStockSum"),2,-1)%></td>
				<td class=a3><%=formatcurrency(CurrentPrice,2,-1)%><input type="hidden" name="Price<%=rs("sid")%>" value="<%=formatcurrency(CurrentPrice,2,-1)%>"></td>
				<td class=a3><%=formatcurrency(AgvInPrice,2,-1)%></td>
				<td class=a3><%=formatcurrency(CurrentPrice*rs("PossessStockSum"),2,-1)%></td>
				<td class=a3><%
				bj=CurrentPrice-AgvInPrice
				bj=round(bj,2)
				if bj>0 then
					response.write "<font color=#FF0000>↑"&formatcurrency(bj,2,true)&"</font>"
				elseif bj<0 then
					response.write "<font color=#0000FF>↓"&formatcurrency(abs(bj),2,True)&"</font>"
				elseif bj=0 then
					response.write "<font color=#000000>→ 0.00</font>"
				end if
%>				</td>
				<td class=a3><%
				TotalGain=bj*rs("PossessStockSum")
				GranRate=TotalGain*100/MyGupiaoCost
				if TotalGain>0 then
					response.Write "<font color=#FF0000>↑"&formatcurrency(TotalGain,2,True)&"</font></td>" 
					response.Write "<td class=a3 align=right><font color=#FF0000>↑ "&formatnumber(GranRate,2,True)&"%</font>"
				elseif TotalGain<0 then
					response.Write "<font color=#0000FF>↓"&formatcurrency(-TotalGain,2,True)&"</font></td>"
					response.Write "<td class=a3 align=right><font color=#0000FF>↓ "&formatnumber(-GranRate,2,True)&"%</font>" 
				else
					response.Write "<font color=#000000>→￥0.00</font></td>"
					response.Write "<td class=a3 align=right><font color=#000000>→ 0.00%</font>"	
				end if
%>				</td>
				<td class=a3 align="center"><input type="checkbox" name="GpId" value="<%=rs("sid")%>" checked></td>
			</tr>
<%
				page_count=page_count + 1
				rs.movenext
				loop
				Pcount=rs.PageCount
			If MyGupiaoCost=0 Then
				TotalGranRate=0
			Else
				TotalGranRate=(MyGupiaoValue-MyGupiaoCost)*100/MyGupiaoCost
			End if
%>	
			<tr align=center height=20> 
				<td class=a4>合计</td>
				<td class=a4>-</td>
				<td class=a4><%=replace(Formatnumber(MyGupiaoNum,0,-1),",","")%></td>
				<td class=a4 align=right><%=Formatcurrency(MyGupiaoCost,2,-1)%></td>
				<td class=a4>-</td>
				<td class=a4>-</td>
				<td class=a4 align=right><%=Formatcurrency(MyGupiaoValue,2,-1)%></td>
				<td class=a4>-</td>
				<td class=a4 align=right><%if MyGupiaoValue-MyGupiaoCost>0 then%>↑<%else%>↓<%end if%><%=formatcurrency((MyGupiaoValue-MyGupiaoCost),2,-1)%></td> 
				<td class=a4 align=right><%if TotalGranRate>0 then%>↑ <%else%>↓ <%end if%><%=formatnumber(TotalGranRate,2,true)%>%</td>
				<td class=a4>-</td>
			</tr>
			<input type="hidden" name="UserName" value="<%=UserName%>">
			<input type="hidden" name="UserID" value="<%=UserID%>">
			<tr>
				<td class=a3 colspan=11 align=right>全选所有股票<input type="checkbox" name="chkall" value="on" onclick="CheckAll(this.form)" checked>&nbsp;全选/取消&nbsp;<input type="radio" name="DecideGp" value="删除">删除&nbsp;<input type="radio" name="DecideGp" value="编辑" checked>编辑&nbsp;<input type="submit" name="putin" value="提交" onclick="{if(confirm('确定要执行所选吗？\n如果您减少了股票数量或选择了删除股票，股票将已当前价抛出！')){return true;}return false;}">&nbsp;<input type="submit" name="DelDecideGp" value="清空股票" onclick="{if(confirm('您确定要删除股民[<%=UserName%>]的所有股票吗？股票将已当前价格全部抛出！')){return true;}return false;}">&nbsp;</td>
			</tr>
			</form>
		</table>
		<table width=<%=Exsm.AssignWidth%> cellspacing=0 cellpadding=1 align=center border=0>
			<tr>
				<td align=left>共 <font color=blue><%=totalrec%></font> 条，每页 <font color=blue><%=rs.PageSize%></font> 条，第 <font color=red><%=currentpage%></font> 页 / 共 <font color=blue><%=Pcount%></font> 页</td><td align=right><%call Exsm.DispPageNum(currentpage,Pcount,"""?action=AdminUserStock&UserID="&UserID&"&page=","""")%></td>
			</tr>
			<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>
		</table>
<%
			End if
		End if
		rs.close
		set rs=nothing
		Exsm.RootShowA
	End Sub
	Sub ExAdminSt()
		Dim AdminI,UserID,SidI,GpSid,GpId
		Dim ChiGuShu,NewChiGuShu,GpPrice,Gpname,Rst,RsMix
		Dim AddPrice,AddPriceAn
		UserID=request("UserID")
		If UserID="" or (not isnumeric(UserID)) Then
			Exsm.Errmess="<li>错误的参数，请指定用户名。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		set Rs=stock_conn.execute("select * from Ex_User where ID="&UserID&"")
		If Rs.eof and Rs.bof Then
			Exsm.Errmess="<li>指定的用户不存在，请确认传递的参数是否正确。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		If request("putin")="提交" Then
			If not request("DecideGp")="编辑" Then
				If not request("DecideGp")="删除" Then
					Exsm.Errmess="<li>没有输入参数或参数非！请选择[删除]或[编辑]。"
					Call Exsm.Endinfo(1)
					Exit sub
				End if
			End if
			If request("GpId")="" Then
				Exsm.Errmess="<li>没有输入参数或参数非法。"
				Call Exsm.Endinfo(1)
				Exit sub
			End if
			If request("DecideGp")="编辑" Then
				for SidI=1 to request("GpId").count
					If request("GpId").count=1 then
						GpSid=request("GpId")
					Else
						GpSid=replace(request.form("GpId")(SidI),"'","")
					End if
					Gpname=trim(replace(Request.form("StockName"&GpSid),"'",""))
					ChiGuShu=Request.form("ChiGuShu"&GpSid)
					NewChiGuShu=Request.form("NewChiGuShu"&GpSid)
					GpPrice=Request.form("Price"&GpSid)
					If NewChiGuShu<>"" Then
						If isnumeric(NewChiGuShu) and NewChiGuShu=>0 and not Round(NewChiGuShu)=Round(ChiGuShu) Then
							set Rst=stock_conn.execute("select * from EX_Customer Where Sid="&GpSid&" and UserId="&UserID&"")
							If not Rst.eof Then
								If Round(NewChiGuShu)>Round(ChiGuShu) Then
									stock_conn.execute("update EX_Customer set PossessStockSum="&Round(NewChiGuShu)&" Where Sid="&GpSid&" and UserId="&UserID&"")
									stock_conn.execute("update EX_Stock set StockSum=StockSum+"&Round(NewChiGuShu-ChiGuShu)&" Where Sid="&GpSid&"")
								Else
									stock_conn.execute("update Ex_User set UserWealth=UserWealth+"&Round((ChiGuShu-NewChiGuShu)*GpPrice,2)&" Where ID="&UserID&"")
									stock_conn.execute("update EX_Customer set PossessStockSum="&Round(NewChiGuShu)&" Where Sid="&GpSid&" And UserId="&UserID&"")
									stock_conn.execute("update EX_Stock set SurplusShare=SurplusShare+"&Round(ChiGuShu-NewChiGuShu)&" Where Sid="&GpSid&"")
								End if
							End if
						End if
					End if
				next
			End if
			If request("DecideGp")="删除" Then
				for SidI=1 to request("GpId").count
					If request("GpId").count=1 then
						GpSid=request("GpId")
					Else
						GpSid=replace(request.form("GpId")(SidI),"'","")
					End if
					Gpname=trim(replace(Request.form("StockName"&GpSid),"'",""))
					ChiGuShu=Request.form("ChiGuShu"&GpSid)
					GpPrice=Request.form("Price"&GpSid)
					set RsMix=stock_conn.execute("select d.*,g.TradePrice from EX_Customer d inner join EX_Stock g on d.Sid=g.Sid Where d.Sid="&GpSid&" And d.UserId="&UserID&"")
					If not RsMix.eof Then
						stock_conn.execute("update EX_Stock set SurplusShare=SurplusShare+"&Round(ChiGuShu)&" Where Sid="&GpSid&"")
						stock_conn.execute("update Ex_User set UserWealth=UserWealth+"&Round(ChiGuShu*GpPrice,2)&" Where ID="&UserID&"")
						stock_conn.execute("delete from EX_Customer where sid="&GpSid&" And UserId="&UserID&"")
					End if
				next
			End if
		End if
		If request("DelDecideGp")="清空股票" Then
			AddPrice=0
			set Rs=stock_conn.execute("select d.*,g.TradePrice from EX_Customer d inner join EX_Stock g on d.Sid=g.Sid Where d.UserId="&UserID&"")
			do while not rs.eof
				AddPrice=Rs("PossessStockSum")*Rs("TradePrice")
				AddPriceAn=AddPriceAn+AddPrice
				stock_conn.execute("update EX_Stock set SurplusShare=SurplusShare+"&Round(Rs("PossessStockSum"))&" Where Sid="&Rs("Sid")&"")
			rs.movenext
			loop
			stock_conn.execute("update Ex_User set UserWealth=UserWealth+"&Round(AddPriceAn,2)&" where ID="&UserID&"")
			stock_conn.execute("delete from EX_Customer where UserId="&UserID&"")
		End if
		call Exsm.CalculateFund(UserID,0)
		Exsm.Sucmess="<li>管理["&replace(request("UserName"),"'","")&"]股民股票成功！"
		Call Exsm.Endinfo(1)
	End Sub
	Sub DelUserList()
		Dim DUList
		DUList=replace(request.form("id"),"'","")
		If DUList<>"" then
			stock_conn.execute("delete from EX_Analyse where id in ("&DUList&")")
		Else
			Exsm.Errmess="<li>请指定要清理的在线用户。"
			Call Exsm.Endinfo(1)
			Exit Sub
		End if
		Exsm.DelStockCahe("Exsm_Imitate_Quotations")
		Exsm.Sucmess="<li>在线用户清理成功！"
		Call Exsm.Endinfo(1)
	End Sub
%>