<%

%>
<!--#include file="te_config.asp"-->
<!--#include file="te_header.asp"-->
<br><br>
<table border=0 cellspacing=1 cellpadding=2 bgcolor = "#ffe4b5" width=100%>
	<tr>
		<td class="smallertext">
			<a href="index.asp">管理首页</a> <a href="te_admin.asp">编辑页面</a> 压缩数据库
		</td>
		<td class="smallerheader" width=130 align=right>
		<%
		if bProtected then 
			response.write session("teFullName")
			response.write "<a href=""te_logout.asp""> (退出)</a>" 
		end if
		%>
		</td>
	</tr>
</table>

<%

	lConnID = request("cid")
	
	on error resume next
	
	sub ShowForm
	%>
		<p class="smallertext">
			原始数据库 <%=sFileFrom%><br>
			将被压缩 <%=sFileTo%><br><br>
			在压缩完成后, 原始文件将被重命名为 
			".(date/time).bak" 扩展名被当作备份, 然后目标文件将被重、命名到你的原始文件如果任何临时文件已经存在，它们将被删除。
			<br><br>
			压缩需要一些时间，这取决与你的数据库大小. 压缩时数据库的任何改变将不被保存。
		</p>
		<p class="smallerheader">
			你确定要压缩数据库?
		</p>
		<a href="te_compactdb.asp?<%=request.querystring%>&sure=1">是</a>&nbsp;
		<a href="<%=request.servervariables("http_referer")%>">否</a>	
	<%
	end sub

	Sub RenameFile(sFrom, sTo)
	   Dim fso, f
	   Set fso = CreateObject("Scripting.FileSystemObject")
	   sDateTimeStamp = "." & year(now) & month(now) & day(now) & "-" & hour(now) & minute(now) & second(now)
	   fso.MoveFile sTo, Server.MapPath(arrDBs(lConnID) & sDateTimeStamp & ".bak")
	   fso.MoveFile sFrom, sTo
	End Sub
	   
	

	sConnFrom = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
	     "Data Source=" & Server.MapPath(arrDBs(lConnID))

	sConnTo = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
	     "Data Source=" & Server.MapPath("te_tempdb.mdb")

	sFileFrom = Server.MapPath(arrDBs(lConnID))
	sFileTo = Server.MapPath("te_tempdb.mdb")


	if request("sure")<>""  then

		if bTableEdit then
			set jro = server.createobject("jro.JetEngine")
			jro.CompactDatabase sConnFrom, sConnTo
			
			if err <> 0 then
				bError = True
				response.write "错误:<br>" & err.description
			end if
			
			RenameFile sFileTo, sFileFrom
			
			if err <> 0 then
				bError = True
				response.write "错误:<br>" & err.description
			end if
			
			if not bError then
				response.write "<br><br>压缩成功！"
			else
				response.write "<br><br>错误发现."
			end if
			
		else
			response.write "你未被允许压缩数据库。"
		end if
	else
	
		ShowForm
		
	end if
	
%>
<br><br>
<!--#include file="te_footer.asp"-->
 

