<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Function.asp" -->
<%
dim conn,RsConfig,DBC,SQLStr
set DBC=New DataBaseClass
set conn=DBC.OpenConnection
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P0604") then Call ReturnError1()
dim fso,DataBasePath,month1,day1,hour1,minute1,second1,FileName,BackupDatabase
if request.Form("Reduce")="压缩数据库" then
call Reduce()
end if
if request.form("backup")="备份数据库" then
  set fso=Server.CreateObject("Scripting.FileSystemObject")
    DataBasePath=request.form("DataBasePath")	
	month1=month(now)
    if Month1<10 then Month1="0"&Month1
    day1=day(now)
    if day1<10 then day1="0"&day1
    hour1=hour(now)
    if hour1<10 then hour1="0"&hour1
    minute1=minute(now)
    if minute1<10 then minute1="0"&minute1
    second1=second(now)
    if second1<10 then second1="0"&second1
    if request.form("FileName")="" then
      FileName=Year(now)&Month1&Day1&Hour1&Minute1&Second1
    else
      Filename=request.form("FileName")
    end if
	BackupDatabase=Server.Mappath("../../FooSun_Data")

	if fso.FileExists(Server.Mappath(""&DataBasePath&"")) then
      if fso.FolderExists(BackupDatabase&"\BackupDatabase")=false then fso.CreateFolder(BackupDatabase&"\BackupDatabase")
	 fso.CopyFile(Server.Mappath(""&DataBasePath&"")),(server.mappath("../../FooSun_Data\BackupDatabase\Back"&FileName&".mdb"))
%>
	<script language="javascript">
	alert ("备份成功");
	</script>
<%
	else
%>
	<script language="javascript">
	alert ("找不到数据库文件");
	</script>
<%
	end if
  end if
%>
<html>
<head>
<title>数据库备份/压缩</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<link href="../../CSS/css.css" rel="stylesheet">
<body topmargin="0" leftmargin="0">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="100%" height="30" class="ButtonList"> <div align="center"><b>数据库备份/压缩</b></div></td>
  </tr>
</table>
<table width="100%" border="0" align="center" cellspacing="0">
<tr><td height="50">&nbsp;</td>
</tr></table>
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="3" bordercolor="e6e6e6">
  <form  action="?" method="post">
    <tr > 
      <td height="50" ><div align="center">
          <p>&nbsp;</p>
          <p>当前数据库路径： 
            <input name="DataBasePath" type="text" size="40" value="../../FooSun_Data/FooSun_Data.mdb">
          </p>
          <p>
            <input name="backup" type="submit" class="Anbut2" value="备份数据库">
            <input type="submit" name="Reduce" class="Anbut2" value="压缩数据库">
          </p><p></p>
        </div></td>
    </tr>
  </form>
</table>
</body>
</html>
<%
Sub Reduce()
    Dim I
    Dim TargetDB,ResourceDB
    Dim oJetEngine
    Dim Fso
    Const Jet_Conn_Partial = "Provider=Microsoft.Jet.OLEDB.4.0; Data source="
    Set oJetEngine = Server.CreateObject("JRO.JetEngine")
    Set Fso= CreateObject("Scripting.FileSystemObject")
    '关闭数据库链接
    Conn.Close
    Set Conn=Nothing
       ResourceDB=Server.MapPath("../../FooSun_Data/FooSun_Data.mdb")

        If Fso.FileExists(ResourceDB) Then
            '建立临时文件
            TargetDB=Server.MapPath("../../FooSun_Data/FooSun_Data.mdb.bak")
            If Fso.FileExists(TargetDB) Then
                Fso.DeleteFile(TargetDB)
            End If
            oJetEngine.CompactDatabase Jet_Conn_Partial&ResourceDB,Jet_Conn_Partial&TargetDB
            Fso.DeleteFile ResourceDB
            Fso.MoveFile TargetDB,ResourceDB
        End If
   
    Set Fso=Nothing
    Set oJetEngine=Nothing
	%>
	<script language="javascript">
	alert ("压缩成功！")
	</script>
	<%
End Sub
%>