<!--#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
			Dim IntTrade_Info
			IntTrade_Info=Split(Exsm.Stock_Setting(2),",")
			Select case Request("action")
				case "Upintervene"
					call Upintervene()
				case else
					call main()
			End select
		End if
	End if
	Sub main()
		Dim stockid
		stockid=request("sid")
		If stockid="" Or not isnumeric(stockid) Then stockid=0
		If stockid<>0 Then
			Set Rs=stock_conn.execute("select * from EX_Stock where sid="&stockid&"")
			If Rs.eof And Rs.bof then
				Exsm.Errmess="<li>没有找到该股票。"
				Call Exsm.Endinfo(1)
				Exit sub
			End if
		End if
		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>-=>  社 区 干 预  <=-</td>
			</tr>
			<form method="post" action="?action=Upintervene">
			<tr>
				<td class=a3><u>操作理由</u>&nbsp;<input name="logtxt" size="70">&nbsp;*</td>
			</tr>
			<tr>
				<td class=a3 height="28"><font color="#006633"><u>被调整股票名称</u></font>
				<select name="wholestock"><option value="Whole">全部股票</option>
				<%Dim guestlist
				If stockid<>0 Then
					SQL="select Sid,Company from EX_stock Where Sid="&stockid&""
				Else
					SQL="select Sid,Company from EX_stock order by sid"
				End if
				set Rs=stock_conn.execute(SQL)
				If Rs.eof and Rs.bof then
					Response.Write "<option value=0>没有股票</option>"
				Else
					Do while not Rs.eof
						If Rs(0)=Cint(stockid) Then
							Response.Write "<option value="&Rs(0)&" style=""color: #FF0000"" selected>"&Rs(1)&"</option>"
						Else
							Response.Write "<option value="&Rs(0)&">"&Rs(1)&"</option>"
						End if
					Rs.movenext
					loop
				End if%></select>，<font color="#006633"><u>干涉价格百分比</u></font> 
				<input name="intervenenum" size="10" value="3">&nbsp;%&nbsp;。</td>
			</tr>
			<tr>
				<td class=a3><u>调整说明</u>&nbsp;<input name="newstxt" size="70">&nbsp;<input type="checkbox" name="newson" value="yes">使用</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><br>①如果调整的股票已经涨跌停价格将不会变化。<br>②<font color=red>调整方式：</font>以上调整将影响大盘，降低所有股票价格请填写负数。<br>③如果调整说明未使用系统将自动发布信息，不发布信息请选择使用后不填写信息。<br>④如果选择了“刷新用户资产信息”则在干预的同时同步刷新用户资产信息（较消耗资源！）。</td>
			</tr>
			<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 Upintervene()
		Dim intervenenum,wholestock,newson,newstxt
		Dim TradePrice,ClosingPrice,Intindex,ii,StockName,NewPrice,ZD,ZangDieRange,MyContent,Color,LogTxt
		LogTxt=trim(replace(Request.form("logtxt"),"'",""))
		wholestock=trim(Request.form("wholestock"))
		intervenenum=trim(Request.form("intervenenum"))
		newson=trim(Request.form("newson"))
		newstxt=trim(Request.form("newstxt"))
		newstxt=replace(newstxt,"'","''")
		If LogTxt="" Or Exsm.Syllable(LogTxt)>250 Then
			Exsm.Errmess="<li>操作理由不能为空。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If intervenenum="" Or not isnumeric(intervenenum) Then
			Exsm.Errmess="<li>涨跌幅度不能为空只能使用数字，请重新输入。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If intervenenum=0 Then
			Exsm.Errmess="<li>涨跌幅度不能为[0]请重新输入。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If int(intervenenum)>10 Or int(intervenenum)<-10 Then
			Exsm.Errmess="<li>请控制上涨或降低的百分比在[10%]内。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If wholestock="Whole" Then
			Intindex="order by sid"
		Else
			Intindex="where sid="&wholestock&" order by sid"
		End if
		SQL="select TradePrice,ClosingPrice,sid,Company from EX_stock "&Intindex&""
		set rs=stock_conn.execute(SQL)
		If not Rs.eof Then
			StockName=Rs(3)
			i=0:ii=0
			Do while not rs.eof
				TradePrice=Round(Rs(0),2)
				ClosingPrice=Round(Rs(1),2)
				If intervenenum>0 Then
					NewPrice=Round((intervenenum/100)*ClosingPrice,2)
					ZD=NewPrice/ClosingPrice
					ZangDieRange=Round(((TradePrice+NewPrice-ClosingPrice)/ClosingPrice)*100,2)
					If ZangDieRange>Round(IntTrade_Info(3),2) Then
						NewPrice=Round(ClosingPrice*(1+IntTrade_Info(3)/100)-TradePrice,2)
						ZD=Round(IntTrade_Info(3)/100,2)-((TradePrice-ClosingPrice)/ClosingPrice)
					End if
					MyContent="社区干预，向市场投入巨额资金，上市公司["&Rs(3)&"]股票价格上扬["&FormatPercent(ZD,2,-1)&"]"
					Color=Exsm.RndColor
				Else
					NewPrice=Round((intervenenum/100)*ClosingPrice,2)
					ZD=NewPrice/ClosingPrice
					ZangDieRange=Round(((TradePrice+NewPrice-ClosingPrice)/ClosingPrice)*100,2)
					If ZangDieRange<Round(-IntTrade_Info(4),2) Then
						NewPrice=Round(ClosingPrice*(1+-IntTrade_Info(4)/100)-TradePrice,2)
						ZD=Round(-IntTrade_Info(4)/100,2)-((TradePrice-ClosingPrice)/ClosingPrice)
					End if
					MyContent="经济发展过热，通货膨胀严重，上市公司["&Rs(3)&"]股票价格下挫["&Replace(FormatPercent(ZD,2,-1),"-","")&"]"
					Color=Exsm.RndColor
				End if
				If Round(NewPrice,2)<>0 And TradePrice+NewPrice>=1 Then
					i=i+1
					ii=ii+ZD
					stock_conn.execute("update EX_Stock Set TradePrice=TradePrice+"&Round(NewPrice,2)&",TodayWave=TodayWave+"&Cdbl(ZD*100)&",TotalWave=TotalWave+"&Cdbl(ZD*100)&" Where Sid="&Rs(2)&"")
					stock_conn.execute("update EX_Config Set ExColExp=ExColExp+"&Cdbl(ZD*100)&"")
					If Not newson="yes" Then stock_conn.execute("insert into EX_News(content,Color,addtime) values ('"&Mycontent&"','"&Color&"',"&SqlSmNowString&")")
				End if
			Rs.movenext
			loop
		End if
		If ii=0 Then
			Exsm.Errmess="<li>干预失败！可能是所选股票已经涨停或跌停。"
			Call Exsm.Endinfo(1)
			Exit sub
		End if
		If newson="yes" And Not newstxt="" And Not Exsm.Syllable(newstxt)>250 Then
			MyContent=""&newstxt&""
			Color=Exsm.RndColor
			stock_conn.execute("insert into EX_News(content,Color,addtime) values ('"&Mycontent&"','"&Color&"',"&SqlSmNowString&")")
		End if
		If Request.form("ReflashInFo")="yes" Then Call Exsm.CalculateFund(0,0)
		If wholestock="Whole" Then
			Exsm.Sucmess="<li>社区干预成功，所有股票价格平均变动["&FormatPercent(ii/i,2,-1)&"]。"
			LogTxt="股票管理：所有股票价格平均变动["&FormatPercent(ii/i,2,-1)&"] "&LogTxt&" "
		Else
			Exsm.Sucmess="<li>社区干预成功，股票["&StockName&"]价格变动["&FormatPercent(ii/i,2,-1)&"]。"
			LogTxt="股票管理：股票["&StockName&"]价格变动["&FormatPercent(ii/i,2,-1)&"] "&LogTxt&" "
		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&"',3)")
		Exsm.DelStockCahe("Exsm_Imitate_News")
		Call Exsm.Endinfo(1)
	End sub
%>