<%
'程序名称：千纸鹤网站管理系统
'程序作者：千纸鹤
'作者邮箱：qzhxxw@sina.com
'作者 Q Q：138999501
'作者电话：0000000000
'官方主页：http://www.qqzzhh.com/
'官方论坛：http://www.qqzzhh.com/bbs
%>
<!--#include file="inc/conn.asp"-->
<!--#include file="inc/set.asp"-->
<!--#include file="inc/dll.asp"-->
<%call hacker()
if session("superlogin")<>yecao then
response.Write "<script>alert('您还没有登陆！');this.location.href='index.asp';</script>"
Response.End
elseif session("superadmin")<>"admin" then
response.Write "<script>alert('您不是超级管理员！您的权限不足！');this.location.href='index.asp';</script>"
Response.End
end if
Dim SQL_Statement,RecordsAffected,RetRs,oField,Page_Count,TotalRec,i,abgcolor,CurPage,PCount,EndPage%>
<link rel="STYLESHEET" type="text/css" href="img/admin.css"><script src=img/adminjs.js></script>
<table width="100%" align=center border="0" cellpadding="0" cellspacing="0" rules=none class=3d><tr class="title"  height="22"><td><b>&nbsp;<img src=img/ie.gif border=0 width=15 height=15 align=absMiddle>&nbsp;SQL语句执行操作说明！
</b></td></tr><tr>
<TD height=60 ><br>
<ul type=1 style="line-height:200%;">
<li>本操作仅限高级、对SQL编程比较熟悉的用户！
<li>您可以直接输入SQL执行语句，比如〖 select * from YC_art 〗查询友情链接信息。
<li>数据记录筛选：select * from 数据表 [ where 字段名=字段值 order by 字段名 ]
<li>更新数据记录：update 数据表 set 字段名1=字段值1,……字段名n=字段值n [where 条件表达式]
<li>删除数据记录：delete from 数据表 [where 条件表达式]
<li>添加数据记录：insert into 数据表 (字段1，字段2，字段3……) value (值1，值2，值3……)
</ul></td></tr></table>
<table width="100%" align=center border="0" cellpadding="0" cellspacing="0" rules=none class=3d>
<%If Request("action") = "sql_done" Then
SQL_Statement=Request("SQL_Statement")
If SQL_Statement<>"" then
On Error Resume Next
Server.ScriptTimeOut=999999
Set RetRs=Conn.Execute(SQL_Statement,RecordsAffected)
If Err.number="0" then
On Error Goto 0
Response.write "<tr class=title height=22><td colspan=2><b>&nbsp;<img src=img/ie.gif border=0 width=15 height=15 align=absMiddle>&nbsp;SQL语句执行结果</td></tr><tr><td align=center colspan=2 height=100>"
If RetRs.State=0 Then
If RecordsAffected>0 Then
Response.write "<span class=current_font>执行成功，共有 "&RecordsAffected&" 条记录被处理。<span><br><br>[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></Table>"
Else
Response.write "执行成功，没有任何记录被处理。<br><br>[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></Table>"
End If
Else
RetRs.Close
RetRs.Open SQL_Statement,Conn,1,1
If RetRs.Bof And RetRs.Eof Then
Response.write "执行成功，没有任何记录被返回。<br><br>[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></Table>"
Else
CurPage=request("page")
If CurPage="" or not IsNumeric(CurPage) Then
CurPage=1
Else
CurPage=CLng(CurPage)
End If
'删除语句
If RetRs.RecordCount>0 Then
RetRs.AbsolutePage=CurPage
Page_Count=0
TotalRec=RetRs.RecordCount
Response.write "<span class=current_font>执行成功，共返回 "&TotalRec&" 条记录。</span><br><br>[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></Table>"
Response.Write "<br><table  align=center border=0 class=3d width='100%'><tr height=22 bgcolor=67749C style=color:#ffffff>"
For Each oField In RetRs.Fields
Response.Write "<Td align=center >" & oField.Name &"</Td>"
Next
Do While (not RetRs.eof) And (not Page_Count = Cint(RetRs.PageSize))
Response.Write "<tr>"
If Page_Count mod 2 = 0 Then
abgcolor="ForumRow"
Else
abgcolor="ForumRowHilight"
End If
For i=0 To RetRs.Fields.Count-1
Response.write "<td class="&abgcolor&" align=center height=25>"
If IsNull(RetRs(i)) Then
Response.Write ""
Else
Response.Write Server.HTMLEncode(RetRs(i))
End If
Response.write "</td>"
Next
Response.Write "</tr>"
Page_count = Page_Count + 1
RetRs.MoveNext
Loop
Response.Write "<tr><td colspan="&RetRs.Fields.Count&" class=forumrow align=center>分页："
Pcount=RetRs.PageCount
If CurPage > 4 Then
Response.write "<a href=""?page=1&action=sql_done&sql_statement="&SQL_Statement&""">[1]</a> ..."
End If
If PCount>CurPage+3 Then
EndPage=CurPage+3
Else
EndPage=PCount
End If
For i=CurPage-3 To EndPage
If i>=1 Then
If i = CLng(CurPage) Then
Response.write " <font color=red>["&i&"]</font>"
Else
Response.write " <a href=""?page="&i&"&action=sql_done&sql_statement="&SQL_Statement&""">["&i&"]</a>"
End If
End If
Next
If CurPage+3 < PCount Then 
Response.write "... <a href=""?page="&PCount&"&action=sql_done&sql_statement="&SQL_Statement&""">["&PCount&"]</a>"
End If
Else
Response.write "执行成功，返回如下记录：<br><br>[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></Table>"
Response.Write "<br><table width=95% border='1' cellspacing='1' cellpadding='3' align=center class=3d><tr>"
For Each oField In RetRs.Fields
If oField.Name<>"" Then
Response.Write "<Th>" & oField.Name &"</Th>"
Else
Response.Write "<Td>执行结果：</Td>"
End If
Next
Do While not RetRs.eof
Response.Write "<tr>"
If Page_Count mod 2 = 0 Then
abgcolor="ForumRow"
Else
abgcolor="ForumRowHilight"
End If
For i=0 To RetRs.Fields.Count-1
Response.write "<td class="&abgcolor&">"
If IsNull(RetRs(i)) Then
Response.Write ""
Else
Response.Write RetRs(i)
End If
Response.write "</td>"
Next
Response.Write "</tr>"
RetRs.MoveNext
Loop
End If
Response.Write "</table></td></tr></Table>"
End If
RetRs.Close
End If
Else
Response.write "<tr class=bg><td colspan=2>执行结果</td></tr><tr><td align=center colspan=2>SQL语句有问题，具体错误信息如下：<br>"&Err.Description&"<br><br>[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></Table>"
Err.clear
End if
On Error Goto 0
Set RetRs=Nothing
End If
Else
%></Table><script>
function sql()
if(document.SQLForm.SQL_Statement.value=="")
{alert("操作语句不能为空！");
document.SQLForm.SQL_Statement.focus();
return false;}}
return true;}</script>
<table width="100%" align=center border="0" cellpadding="0" cellspacing="0" rules=none class=3d><tr class="title"  height="22"><td><b>&nbsp;<img src=img/ie.gif border=0 width=15 height=15 align=absMiddle>&nbsp;请输入SQL语句！
</b></td></tr><tr>
<TD height=60 align=center><br>
<Form Name="SQLForm" Method="Post"  onsubmit="return sql();" action="?action=sql_done">
<textarea name="SQL_Statement" style="width:98%;height:60" class=yecao></textarea>
<br><br>
<Input type="Submit" Value=" 执  行 " class=adminbutton><br><br></Form></td></tr>
<tr><td class="hr"></td></tr><TR>
<TD height=22 ALIGN=center>&nbsp;&nbsp;Copyright&copy;2004-2005 FY Design Studio&nbsp;</TD></TR>
</table>
<%End If%>
