<!--#include file="../../Common/Config.asp"-->
<!--#include file="../../Common/Function/Function.asp"-->
<!--#include file="../Include/Check.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%
session("nowpage")=Request.ServerVariables("PATH_INFO")
if Request.ServerVariables("QUERY_STRING")<>"" then
	session("nowpage")=session("nowpage")&"?"&Request.ServerVariables("QUERY_STRING")
end if
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=Web_Name%>数据库备份</title>
<link href="<%=Web_Root%>Admin/Css/Style.css" rel="stylesheet" type="text/css" />
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="../Main/Right.asp">首页</a></li>
    <li><a href="#">数据库备份</a></li>
    </ul>
    </div>
    
    <div class="formbody">
    
<table width="400" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30" align="center" class="title"><a href="?action=backdata">备份数据库</a></td>
    <td height="30" align="center" class="title"><a href="?action=redata">恢复数据库</a></td>
    <td height="30" align="center" class="title"><a href="?action=godata">压缩数据库</a></td>
  </tr>
</table>

<%
select case request("action")
case ""
call backdata()
case "godata"
call godata()
case "backdata"
if request("act")="Backup" then
call updata()
else		
call backdata()
end if
case "redata"
if request("act")="data" then
dim Dbpath,backpath,fso
			Dbpath=request.form("Dbpath")
			backpath=request.form("backpath")
			if dbpath="" then
			response.write "请输入您要恢复成的数据库全名"	
			else
			Dbpath=server.mappath(Dbpath)
			end if
			backpath=server.mappath(backpath)
		
			Set Fso=server.createobject("scripting.filesystemobject")
			if fso.fileexists(dbpath) then  					
			fso.copyfile Dbpath,Backpath
%>

<table width="400" border="0" cellspacing="0" cellpadding="2" class=bk style="border-collapse: collapse">

<tr class=ds><td height=66 align="left">您的数据库已经成功恢复!</td></tr></table>
<%else%>
<table width="400" border="0" cellspacing="0" cellpadding="2" class=bk style="border-collapse: collapse">

<tr class=ds><td height=66 align="left">备份目录下并无您的备份文件！ </td></tr></table>
<%end if
else
call redata()
end if
end select
%>
<%
'====================压缩数据库 =========================
sub godata()
%>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class=bk style="border-collapse: collapse">
<form action="?action=godata" method="post">
<tr>
<td  class="ds" height=70>数据库文件：
  <input name="dbpath" type="text" class="dfinput" style="width:250px;" value="<%=Db%>"  >
&nbsp;
<p>      
    <input type="checkbox" name="boolIs97" value="True">
    如果使用 Access 97 数据库请选择
    (默认为 Access 2000 数据库) </p></td>
</tr>
<tr>
<td class="qs" height=45 align=left>
<input type="submit" value="压 缩" class="btn" >
</td>
</tr>
<form>
</table>
<br>
<%
dim dbpath,boolIs97
dbpath = request("dbpath")
boolIs97 = request("boolIs97")

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

end sub

'=====================压缩参数=========================
Function CompactDB(dbPath, boolIs97)
Dim fso, Engine, strDBPath,JET_3X
strDBPath = left(dbPath,instrrev(DBPath,"\"))
Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(dbPath) Then
	fso.CopyFile dbpath,strDBPath & "temp.mdb"
	Set Engine = CreateObject("JRO.JetEngine")

	If boolIs97 = "True" Then
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
		"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb;" _
		& "Jet OLEDB:Engine Type=" & JET_3X
	Else
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
		"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"
	End If

fso.CopyFile strDBPath & "temp1.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")
fso.DeleteFile(strDBPath & "temp1.mdb")
Set fso = nothing
Set Engine = nothing
%>

<table width="100%" border="0" cellspacing="0" cellpadding="4" class=bk style="border-collapse: collapse">
  <tr class=ds>
    <td height=66 align="left"><%
CompactDB = "你的数据库【" & dbpath & "】已经压缩成功!" & vbCrLf
%>
        <%Else%>
        <table width="100%" border="0" cellspacing="0" cellpadding="4" class=bk style="border-collapse: collapse">
          <tr class=ds>
            <td height=66 align="left"> 数据库名称或路径不正确. 请重试! </td>
          </tr>
      </table>
      <%End If
End Function
%>
    </td>
  </tr>
</table>
<%sub backdata()%>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class=bk style="border-collapse: collapse;">

  <form method="post" action="?action=backdata&act=Backup">
    <tr>
      <td class="ds" height=45>当前数据库路径(相对路径)：
          <input name=DBpath type=text class="dfinput" style="width:250px;" value="<%=Db%>" size=20></td>
    </tr>
    <tr>
      <td class="ds" height=45>备份数据库目录(相对路径)：
        <input name=bkfolder type=text class="dfinput" style="width:250px;" value="../../Data/" size=20>
&nbsp;
<i>如目录不存在，程序将自动创建</i></td>
    </tr>
    <tr>
      <td class="ds" height=45>备份数据库名称(填写名称)：
        <input name=bkDBname type=text class="dfinput" style="width:250px;" value="#Back_01.mdb" size=20 />
&nbsp;
<i>如备份目录有该文件，将覆盖，如没有，将自动创建</i></td>
    </tr>
    <tr>
    <td class="qs" height=45 align=left>
      <input type=submit value="备 份" class="btn">
      </td>
    </tr>
  </form>
</table>
<%end sub
sub updata()
        dim Dbpath,bkfolder,bkdbname,fso
		Dbpath=request.form("Dbpath")
		Dbpath=server.mappath(Dbpath)
		bkfolder=request.form("bkfolder")
		bkdbname=request.form("bkdbname")
		Set Fso=server.createobject("scripting.filesystemobject")
		if fso.fileexists(dbpath) then
			If CheckDir(bkfolder) = True Then
			fso.copyfile dbpath,bkfolder& "\"& bkdbname
			else
			MakeNewsDir bkfolder
			fso.copyfile dbpath,bkfolder& "\"& bkdbname
			end if
%>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class=bk style="border-collapse: collapse">

  <tr>
    <td height=66 align="left"> 备份数据库成功，您备份的数据库路径为<%=bkfolder%>\<%=bkdbname%> </td>
  </tr>
</table>
<%Else%>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class=bk style="border-collapse: collapse">

  <tr class="ds">
    <td height=66 align="left"> 找不到您所需要备份的文件! </td>
  </tr>
</table>
<%End if
end sub
'------------------检查某一目录是否存在-------------------
Function CheckDir(FolderPath)
    dim fso1
	folderpath=Server.MapPath(".")&"\"&folderpath
    Set fso1 = CreateObject("Scripting.FileSystemObject")
    If fso1.FolderExists(FolderPath) then
       '存在
       CheckDir = True
    Else
       '不存在
       CheckDir = False
    End if
    Set fso1 = nothing
End Function
'-------------根据指定名称生成目录-----------------------
Function MakeNewsDir(foldername)
	dim f,fso1
    Set fso1 = CreateObject("Scripting.FileSystemObject")
        Set f = fso1.CreateFolder(foldername)
        MakeNewsDir = True
    Set fso1 = nothing
End Function
%>
<%
'====================恢复数据库=========================
sub redata()
%>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class=bk style="border-collapse: collapse">

  <form method="post" action="?action=redata&act=data">
    <tr>
      <td class="ds" height=45>&nbsp;备份数据库路径(相对)：
          <input name=DBpath type=text class="dfinput" style="width:250px;" value="../../Data/#Back_01.mdb" size=30  ></td>
    </tr>
    <tr>
      <td class="ds" height=45>&nbsp;目标数据库路径(相对)：
          <input name=backpath type=text class="dfinput" style="width:250px;" value="<%=Db%>" size=30  ></td>
    </tr>
    <tr>
      <td class="qs" height=45 align=left >&nbsp;
          <input type=submit value="恢 复" class="btn">
      </td>
    </tr>
  </form>
</table>
<%end sub%>

</div>


</body>

</html>

