<!--#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"-->
<!--#include file="inc/ex_stock/ex_admin/ex_admin_index.asp"-->
<%
	if not exsm.stockadmin then
		exsm.errmess="您没有管理权限！请返回。"
		call exsm.endinfo("no")
	else
		select case request("action")
			case "cut"
				call excut()
			case "hongli"
				call hongli()
			case "songgu"
				call songgu()
			case else
				call main()
		end select
	end if
	sub main()
		dim sid,totalnum,gupiaocode,gupiaoname,currentprice
		dim page,currentpage,page_count,totalrec,pcount
		sid=request("sid")
		page=request("page")
		if sid="" or (not isnumeric(sid)) then
			exsm.errmess="数据传输错误，请重新选择股票。"
			call exsm.endinfo("no")
			exit sub
		else
			set rs=stock_conn.execute("select * from ex_stock where sid="&sid&"")
			if rs.eof and rs.bof then
				exsm.errmess="指定的股票不存在，请确认传递的参数是否正确。"
				call exsm.endinfo("no")
				exit sub
			else
				currentprice=rs("tradeprice")
				set rs=stock_conn.execute("select * from ex_customer where userid>0 and sid="&sid&"")
				if not rs.eof then
					gupiaocode=rs("code")
					gupiaoname=rs("company")
				else
					exsm.errmess="暂时没有人购买或这只股票，不需要分红。"
					call exsm.endinfo("no")
					exit sub
				end if
			end if
		end if
		adminmenutop "分红-第"&gupiaocode&"号股票-"&gupiaoname&""
		session("ex_sm")=0
%>
		<table class="tableborder1" cellspacing="1" cellpadding="3" align="center" border="0" style="width:100%">
			<tr>
				<th height="25">-=> 第 <%=gupiaocode%> 号 股 票 <%=gupiaoname%> 分 红 <=-</th>
			</tr>
			<tr>
				<td class="tablebody1" align="center" valign="center">
				<form name="form1" method="post" action="?action=cut">
					<input type="hidden" name="sid" value="<%=sid%>">
					<input type="hidden" name="stockcode" value="<%=gupiaocode%>">
					<input type="hidden" name="stockname" value="<%=gupiaoname%>">
					<input type="hidden" name="object" value="hongli"><br>
					<font color="red">现金派息：</font>&nbsp;
					<font color="#006633">每[10]股分红金额：</font>
					<input name="quantity" size="20" value="0">
					<input type="submit" value="确定" name="b1">
					<input type="reset" value="重填" name="b2"><br>
				</form>
				<form name="form2" method="post" action="?action=cut">
					<input type="hidden" name="sid" value="<%=sid%>">
					<input type="hidden" name="stockcode" value="<%=gupiaocode%>">
					<input type="hidden" name="stockname" value="<%=gupiaoname%>">
					<input type="hidden" name="object" value="songgu">
					<font color="red">　　送股：</font>&nbsp;
					<font color="#006633">每[10]股送股比例：</font>
					<input name="quantity" size="20" value="0">
					<input type="submit" value="确定" name="b3">
					<input type="reset" value="重填" name="b2"><br>
				</form>
				</td>
			</tr>
		</table>
		<table class="tableborder1" cellspacing="1" cellpadding="3" align="center" border="0" style="width:100%"><br>
			<tr align="center"> 
				<th height="25">股东</th>
				<th>持股数量</th>
				<th>持股比例</th>
				<th>当前价格</th>
				<th>持股价格</th>
				<th>持股现值</th>
				<th>持股成本</th>
				<th>总盈亏</th>
				<th>盈亏率</th>
			</tr>
<%
		dim gupiaovalue,gupiaocost
		totalnum=stock_conn.execute("select sum(possessstocksum) from ex_customer where userid>0 and sid="&sid&"")(0)
		sql="select * from ex_customer where userid>0 and sid="&sid&" order by possessstocksum desc,buytime desc"
		set rs=stock_conn.execute(sql)
		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
		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
			gupiaovalue=currentprice*(rs("possessstocksum"))		'持股现值
			gupiaocost =rs("averageprice")*(rs("possessstocksum"))		'持股成本
%>
			<tr align="right">
				<td class="tablebody1" align="center"><a href="ex_sm_dispu.asp?uid=<%=rs("userid")%>"><%=rs("username")%></a></td>
				<td class="tablebody1"><%=replace(formatnumber(rs("possessstocksum"),0,-1),",","")%></td>
				<td class="tablebody1"><%=formatnumber(rs("possessstocksum")*100/totalnum,2,-1)%>%</td>
				<td class="tablebody1"><%=formatcurrency(currentprice,2,-1)%></td>
				<td class="tablebody1"><%=formatcurrency(rs("averageprice"),2,-1)%></td>
				<td class="tablebody1"><%=formatcurrency(gupiaovalue,2,-1)%></td>  
				<td class="tablebody1"><%=formatcurrency(gupiaocost,2,-1)%></td>
				<td class="tablebody1"><%=formatcurrency(gupiaovalue-gupiaocost,2,-1)%></td>   
				<td class="tablebody1"><%=formatnumber((gupiaovalue-gupiaocost)*100/gupiaocost,2,-1)%>%</td>  
			</tr>
<%		page_count=page_count+1
		rs.movenext
		loop
		pcount=rs.pagecount
		response.write "</table>"
		call exsm.disppagenum(totalrec,page_count,currentpage,pcount,"?sid="&sid&"&page=","?sid="&sid&"")
		rs.close
		set rs=nothing
		adminmenubottom
		exsm.rootshowa
	end sub
	sub excut()
		dim sid,quantity,stockcode,stockname
		sid=request.form("sid")
		quantity=request.form("quantity")
		if sid="" or (not isnumeric(sid)) then
			exsm.errmess="数据传输错误，请重新选择股票。"
			call exsm.endinfo("no")
			exit sub
		else
			set rs=stock_conn.execute("select * from ex_stock where sid="&sid&"")
			if rs.eof and rs.bof then
				exsm.errmess="指定的股票不存在，请确认传递的参数是否正确。"
				call exsm.endinfo("no")
				exit sub
			else
				set rs=stock_conn.execute("select * from ex_customer where userid>0 and sid="&sid&"")
				if rs.eof and rs.bof then
					exsm.errmess="暂时没有人购买或这只股票，不需要分红。"
					call exsm.endinfo("no")
					exit sub
				end if
			end if
			if quantity="" or quantity=0 or not isnumeric(quantity) then
				exsm.errmess="请输入正确的分红数量。"
				call exsm.endinfo("no")
				exit sub
			end if
		end if
		stockcode=replace(request.form("stockcode"),"'","")
		stockname=replace(request.form("stockname"),"'","")
		adminmenutop "分红-第"&stockcode&"号股票-"&stockname&""
		session("ex_sm")=0
%>
		<table class="tableborder1" cellspacing="1" cellpadding="3" align="center" border="0" style="width:100%">
			<tr>
				<th height="25">-=> 第 <%=stockcode%> 号 股 票 <%=stockname%> 分 红 <=-</th>
			</tr>
			<form method="post" action="?action=<%=replace(request.form("object"),"'","")%>">
			<tr>
				<td class="tablebody1"><u>操作理由</u>&nbsp;<input name="logtxt" size="70">&nbsp;*</td>
			</tr>
			<tr>
				<td class="tablebody1"><u>股票状态</u>&nbsp;<input type="radio" name="lockstock" value="3" checked>保持当前状态&nbsp;<input type="radio" name="lockstock" value="0">分红后开盘&nbsp;<input type="radio" name="lockstock" value="1">分红后封盘</td>
			</tr>
			<tr>
				<td class="tablebody1"><u>资产刷新</u>&nbsp;<input type="radio" name="reflashinfo" value="0" checked>不同步刷新&nbsp;<input type="radio" name="reflashinfo" value="1">同步刷新用户资产（较消耗资源！）
			</tr>
			<tr>
				<td class="tablebody1"><u>信息发布</u>&nbsp;<input name="messagetxt" size="70" value="">&nbsp;<input type="checkbox" name="use" value="1">使用</td>
			</tr>
			<tr>
				<td class="tablebody1"><u>管理说明</u><br>①[分红后封盘]选项为分红结束后被分红股票自动封盘。<br>②如果分红说明未使用系统将自动发布信息，不发布信息请选择使用后不填写信息。<br>③如果选择了[刷新用户资产信息]则在干预的同时同步刷新用户资产信息（较消耗资源！）。</td>
			</tr>
			<input type="hidden" name="sid" value="<%=sid%>">
			<input type="hidden" name="quantity" value="<%=quantity%>">
			<input type="hidden" name="stockname" value="<%=stockname%>">
			<tr>
				<td class="tablebody2" align="center"><input type="submit" value="确定" name="b1">&nbsp;&nbsp;<input type="reset" value="重填" name="b2"></td>
			</tr>
			</form>
		</table>
<%
		adminmenubottom
		exsm.rootshowa
	end sub
	sub hongli()
		dim sid,logtxt,honglinum,addmoney,mycontent,l_content
		sid=trim(request.form("sid"))
		logtxt=trim(replace(request.form("logtxt"),"'",""))
		if sid="" or (not isnumeric(sid)) then
			exsm.errmess="数据传输错误，请重新选择股票。"
			call exsm.endinfo("no")
			exit sub
		end if
		if logtxt="" or exsm.syllable(logtxt)>250 then
			exsm.errmess="操作理由不能为空。"
			call exsm.endinfo("no")
			exit sub
		else
			l_content=replace("股票管理：分红，上市公司["&replace(request.form("stockname"),"'","")&"]每[10]股现金派息["&formatnumber(honglinum,2,-1)&"]元，状态["&request.form("lockstock")&"] 操作理由["&logtxt&"] ","'","")
		end if
		if request.form("quantity")="" or (not isnumeric(request.form("quantity"))) then
			exsm.errmess="请输入正确的分红金额。"
			call exsm.endinfo("no")
			exit sub
		end if
		honglinum=round(request.form("quantity"),2)
		set rs=stock_conn.execute("select * from ex_customer where userid>0 and sid="&sid&"")
		addmoney=0
		do while not rs.eof
			addmoney=honglinum*(rs("possessstocksum")/10)
			stock_conn.execute "update ex_user set userwealth=userwealth+"&addmoney&" where id="&rs("userid")&""
		rs.movenext
		loop
		if not request.form("use")=1 then
			mycontent=replace("系统信息: 上市公司["&replace(request.form("stockname"),"'","")&"]每[10]股现金派息["&honglinum&"]元完成。 ","'","")
			stock_conn.execute("insert into ex_news(content,color,addtime) values ('"&mycontent&"','"&exsm.rndcolor&"',"&sqlsmnowstring&")")
		end if
		if request.form("use")=1 and not replace(request.form("messagetxt"),"'","")="" and not exsm.syllable(replace(request.form("messagetxt"),"'",""))>250 then
			mycontent=replace(request.form("messagetxt"),"'","")
			stock_conn.execute("insert into ex_news(content,color,addtime) values ('"&mycontent&"','"&exsm.rndcolor&"',"&sqlsmnowstring&")")
		end if
		call exsm.savelog(exsm.scriptname,l_content,3)
		if request.form("lockstock")<3 then
			stock_conn.execute("update ex_stock set lockstock="&request.form("lockstock")&" where sid="&sid&"")
			stock_conn.execute("update ex_oneselfstock set lockstock="&request.form("lockstock")&" where decideid="&sid&"")
		end if
		if request.form("reflashinfo")=1 then call exsm.calculatefund(0,0)
		exsm.delstockcahe("exsm_imitate_news")
		exsm.sucmess="红利分配成功，上市公司["&replace(request.form("stockname"),"'","")&"]每[10]股现金派息["&formatnumber(honglinum,2,-1)&"]元！"
		call exsm.endinfo("ok")
	end sub
	sub songgu()
		dim sid,logtxt,songgunum,addnum,sumnum,mycontent,l_content
		dim usersumnum,sumsid,useruid
		sid=trim(request.form("sid"))
		logtxt=trim(replace(request.form("logtxt"),"'",""))
		if exsm.outsiderefer() then
			exsm.errmess="请不要从外部提交数据。"
			call exsm.endinfo("stop.gif")
			exit sub
		end if
		if exsm.repeatrefer() then
			exsm.errmess="您提交的数据已经保存，请不要重复提交。"
			call exsm.endinfo("stop.gif")
			exit sub
		end if
		if sid="" or (not isnumeric(sid)) then
			exsm.errmess="数据传输错误，请重新选择股票。"
			call exsm.endinfo("no")
			exit sub
		end if
		if logtxt="" or exsm.syllable(logtxt)>250 then
			exsm.errmess="操作理由不能为空。"
			call exsm.endinfo("no")
			exit sub
		else
			l_content=replace("股票管理：送股，上市公司["&replace(request.form("stockname"),"'","")&"]每[10]股赠送["&formatnumber(songgunum,2,-1)&"]股，状态["&request.form("lockstock")&"] 操作理由["&logtxt&"]  ","'","")
		end if
		if request.form("quantity")="" or (not isnumeric(request.form("quantity"))) then
			exsm.errmess="请输入正确的送股比例。"
			call exsm.endinfo("no")
			exit sub
		end if
		songgunum=round(request.form("quantity"),2)
		if songgunum<=0 then
			exsm.errmess="送股比例不能为零或者负数。"
			call exsm.endinfo("no")
			exit sub
		end if
		set rs=stock_conn.execute("select sid,possessstocksum,userid from ex_customer where userid>0 and sid="&sid&"")
		addnum=0 : sumnum=0
		do while not rs.eof
			usersumnum=rs(1) : sumsid=rs(0) : useruid=rs(2)
			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&"")
		rs.movenext
		loop
		stock_conn.execute("update ex_stock set stocksum=stocksum+"&round(sumnum)&",surplusshare=surplusshare+"&round(sumnum)&" where sid="&sid&"")
		if not request.form("use")=1 then
			mycontent=replace("系统信息: 上市公司["&replace(request.form("stockname"),"'","")&"]每[10]股赠送["&formatnumber(songgunum,0,-1)&"]股完成。 ","'","")
			stock_conn.execute("insert into ex_news(content,color,addtime) values ('"&mycontent&"','"&exsm.rndcolor&"',"&sqlsmnowstring&")")
		end if
		if request.form("use")=1 and not replace(request.form("messagetxt"),"'","")="" and not exsm.syllable(replace(request.form("messagetxt"),"'",""))>250 then
			mycontent=replace(request.form("messagetxt"),"'","")
			stock_conn.execute("insert into ex_news(content,color,addtime) values ('"&mycontent&"','"&exsm.rndcolor&"',"&sqlsmnowstring&")")
		end if
		call exsm.savelog(exsm.scriptname,l_content,3)
		if request.form("lockstock")<3 then
			stock_conn.execute("update ex_stock set lockstock="&request.form("lockstock")&" where sid="&sid&"")
			stock_conn.execute("update ex_oneselfstock set lockstock="&request.form("lockstock")&" where decideid="&sid&"")
		end if
		if request.form("reflashinfo")=1 then call exsm.calculatefund(0,0)
		exsm.delstockcahe("exsm_imitate_news")
		session("ex_sm")=1
		exsm.sucmess="送股成功，上市公司["&replace(request.form("stockname"),"'","")&"]每[10]股赠送["&formatnumber(songgunum,0,-1)&"]股！"
		call exsm.endinfo("ok")
	end sub
%>