<%
if request.Cookies("sunzom_username")="" then
%>
<script language="javascript">
top.location.href="../index.asp"
</script>
<%  
  response.end
end if
%>

<html>
<head>
<title><%=dianming%> - 数据库压缩</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../images/sunzom.css" rel="stylesheet" type="text/css">

</HEAD>
<BODY>
<%if request("hid1")="" then%> 
<form name="form1" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#C4D8ED">
<tr>
<td><img src="../images/r_1.gif" alt="" /></td>
<td width="100%" background="../images/r_0.gif">
  <table cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td>&nbsp;压缩数据库 <input onclick="location.href='backup.asp'" value="数据备份"  type="button">  <input onclick="location.href='backup2.asp'" value="数据还原"  type="button">  <input onclick="location.href='backup3.asp'" value="压缩数据库"  type="button"></td>
	  <td align="right">　</td>
    </tr>
  </table>
</td>
<td><img src="../images/r_2.gif" alt="" /></td>
</tr>
<tr>
<td></td>
<td>
<table align="center" cellpadding="4" cellspacing="1" class="toptable grid" border="1">
      <tr>
        <td height="30" colspan="2" align="center" class="category">你的空间只有支持fso才可以进行如下操作，否则你只能手动压缩</td>
	  </tr>
      <tr>
        <td width="25%" height="30" align="right">当前数据库路径：</td>
        <td width="75%" class="category">
		  <input type="text" name="mdbpath" size="30" value="data/sunzom_mcs.mdb">
		  <input type="radio" value="false" checked name="ys"> 使用 Access 2000 数据库
		</td>	
	  </tr>	
	  <tr>
        <td height="30" align="right">　</td>
        <td class="category">
		  （为了安全，请注意用备份的数据库文件来压缩，不要用当前正在运行的数据库文件）
		</td>	
	  </tr>	  
      <tr class="a3">
        <td align="center" colspan="2" class="category">
		  <input type="submit" value=" 确认压缩 " class="button">
		  <input type="hidden" name="hid1" value="ok"></td>
      </tr>	    
</table>
</td>
<td></td>
</tr>
<tr>
<td><img src="../images/r_4.gif" alt="" /></td>
<td></td>
<td><img src="../images/r_3.gif" alt="" /></td>
</tr>
</table>
</form>
<%
else
'-----------------------------------------
Dim dbpath,boolIs97

dbpath="../"&request.form("mdbpath")
boolIs97=request.form("ys")

If dbpath <> "" Then
dbpath = server.mappath(dbpath)
response.write(CompactDB(dbpath,boolIs97))
End If

Const JET_3X = 4

Function CompactDB(dbPath, boolIs97)
Dim fso, Engine, strDBPath
strDBPath = left(dbPath,instrrev(DBPath,"\"))
set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(dbPath) Then
set Engine = CreateObject("JRO.JetEngine")
cnmaips="cnmai784512"

	If boolIs97 = "true" Then
'		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
'		"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb;" _
'		& "Jet OLEDB:Engine Type=" & JET_3X
 
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=true;Data Source="&dbpath&";Jet OLEDB:Database Password="&cnmaips, _
		"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=true;Data Source="&strDBPat&"temp.mdb;Jet OLEDB:Database Password="&cnmaips&";" _
		& "Jet OLEDB:Engine Type=" & JET_3X
		
'conn.open "provider=microsoft.jet.oledb.4.0;data source=" & mypath
'conn.open "dbq="+server.mappath(mypath)+";defaultdir=;driver={microsoft access driver (*.mdb)};uid=;password="&cnmaips&";"		
	Else
	
		'Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
		'"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb"
	Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=true;Data Source="&dbpath&";Jet OLEDB:Database Password="&cnmaips, _
	"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=true;Data Source="&strDBPath&"temp.mdb;Jet OLEDB:Database Password="&cnmaips&""	
	End If

fso.CopyFile strDBPath & "temp.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")
set fso = nothing
set Engine = nothing
response.write"<script>alert('您的数据库已经压缩成功!');history.go(-1)</script>"
response.End()
Else
response.write"<script>alert('数据库名称或路径不正确. 请重试!');history.go(-1)</script>"
response.End()
End If

End Function
'--------------------------------------------
end if
%>
</body>
</html>