<!--#include file="conn.asp"-->
<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆！');window.location.href='login.asp';</script>"
response.End
else
if session("flag")>1 then
response.Write "<p align=center><font color=red>您没有此项目管理权限！</font></p>"
response.End
end if
end if
%>
<html>
<link href="../images/css.css" rel="stylesheet" type="text/css">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body topmargin="0" leftmargin="0" rightmargin="0">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="52">&nbsp;</td>
        <td background="images/main_2.jpg" class="title1"><b><font color="#ffffff">数据库管理操作</font></b></td>
        <td width="52">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" background="images/main_4.gif">&nbsp;</td>
        <td class="td">

<%
dbfolder="cnhwwdata/"   '数据库路径，如果你更改了数据库的路径，这里也请进行修改
dbname="cnhww.asp"    
dbfolder="../"&dbfolder
%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href=../images/css.css rel=STYLESHEET type=text/css>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
      <td> 
        <table class="tableBorder" width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#6a7f9a">
         
         
          <tr > 
            
          <td height="30" > 

<%
SET FSO=Server.CreateObject("Scripting.FileSystemObject")
 IF Err<>0 THEN
 Err.Clear
 Response.Write("<p>您的服务器关闭了FSO，无法进行数据库操作")
 response.end
end if
action=request("action")
IF action<>"" THEN
strfileName=Request("FileName")

Function goaler_isFloderExist(strFolderName)
IF FSO.FolderExists(strFolderName) THEN
 goaler_isFloderExist=1
ELSE
 goaler_isFloderExist=-1
END IF
End Function

Function goaler_isfileExist(strfileName)
IF FSO.FileExists(strfileName) THEN
 goaler_isfileExist=1
ELSE
 goaler_isfileExist=-1
END IF
End Function

Function goaler_DeleteFile(strfileName)
 If FSO.FileExists(strfileName) Then
  FSO.DeleteFile strfileName,True
  goaler_DeleteFile=1
 Else
  goaler_DeleteFile=-1
 End If
End Function 
Function CopyFiles(TempSource,TempEnd)
 IF FSO.FileExists(TempEnd) THEN
  Response.Write "目标文件 <b><font color=red>" & TempEnd & "</font></b> 已存在，请先删除!"
  SET FSO=Nothing
  Exit Function
 End IF
 If Not FSO.FileExists(TempSource) Then
  Response.Write "源文件 <b><font color=red>"&TempSource&"</font></b> 不存在!"
  Set FSO=Nothing
  Exit Function
 End If
 FSO.CopyFile TempSource,TempEnd
 Response.Write "已经成功复制文件 <b><font color=red>"&TempSource&"</font></b> 到 <b><font color=red>"&TempEnd&"</font></b>"
End Function


 IF action="compact" THEN
 
  Response.write "<br><div align=center> 压缩数据库可以去除冗余数据，为数据库减肥，同时也能提高速度，此功能无须经常使用！</div><div align=center><a href=?action=compact2>点此压缩数据库！</a></div>"
 
  
   ELSEIF action="compact2" THEN
  
  conn.close
  set conn=nothing
		
  Response.Write("<p>")
  IF goaler_isFileExist(Server.Mappath(dbfolder&dbname))=1 THEN
   Response.Write "压缩数据库开始...<br>"
   Set Engine=CreateObject("JRO.JetEngine")
   Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(dbfolder&dbname), "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath(dbfolder&"temp.mdb")
   SET FSO=Server.CreateObject("Scripting.FileSystemObject")
   FSO.CopyFile Server.Mappath(dbfolder&"temp.mdb"),Server.Mappath(dbfolder&dbname)
   FSO.DeleteFile(Server.Mappath(dbfolder&"temp.mdb"))
   Set Engine=Nothing
   Response.write "数据库：<font color=red>"&Server.MapPath(dbfolder&dbname)&"</font>压缩完成！"
  ELSE
   Response.Write("数据库源文件：<b><font color=red>"&Server.Mappath(dbfolder&dbname)&"</font></b>不存在！")
  END IF
 

 
 ELSEIF action="backup" THEN
	  Response.write "<br><div align=center>数据库备份可以防止以后网站出现问题后及时得到恢复，建议经常备份数据库并下载保存</div><div align=center><a href=?action=backup2>点此备份开始！</a></div>"
 
  
   ELSEIF action="backup2" THEN
  BackUpTime=right(year(now()),4)&month(now())&day(now())&hour(now())&minute(now())&second(now())
  Response.Write("备份数据库开始...<br>")
  CopyFiles Server.Mappath(dbfolder&dbname),Server.Mappath(dbfolder&BackUpTime &".bak")
  Response.write "<br>数据库备份完成！<br>"
  Response.write "注：多次备份数据会占用较多的空间，请及时对备份的数据库进行下载备份或删除。 "
  
 ELSEIF action="restore" THEN
  RestoreFileName=strFileName
  Response.Write("<p>")
  IF goaler_isFileExist(Server.Mappath(dbfolder&RestoreFileName))=1 THEN
   Response.Write "开始恢复数据库...<br>"
   FSO.CopyFile Server.Mappath(dbfolder&RestoreFileName),Server.Mappath(dbfolder&dbname)
   Response.write "数据库恢复完成，从备份数据库：<b><font color=red>"&Server.MapPath(dbfolder&RestoreFileName)&"</font></b> 到：<b><font color=red>"&Server.MapPath(dbfolder&dbname)&"</font></b>！"
  ELSE
 
   Response.Write("备份文件：<b><font color=red>"&Server.Mappath(dbfolder&RestoreFileName)&"</font></b>不存在,或者含有特殊字符！！")
  END IF
  Response.Write("<br><a href="""&Request.ServerVariables("HTTP_REFERER")&""">请点击返回</a>")
  response.end
   ELSEIF(action="view")THEN
   
Function GetTotalSize(GetLocal,GetType)
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
If Err<>0 Then
   Err.Clear
   GetTotalSize="服务器不支持FSO，查看空间失败"
Else
   Dim SiteFolder
   If GetType="Folder" Then
      Set SiteFolder=FSO.GetFolder(GetLocal) 
   Else
      Set SiteFolder=FSO.GetFile(GetLocal) 
   End If
   GetTotalSize=SiteFolder.Size
   If GetTotalSize>1024*1024 Then
      GetTotalSize=GetTotalSize/1024/1024
      If inStr(GetTotalSize,".") Then GetTotalSize=Left(GetTotalSize,inStr(GetTotalSize,".")+2)
         GetTotalSize=GetTotalSize&" MB"
      Else
         GetTotalSize=Fix(GetTotalSize/1024)&" KB"
      End If
         Set SiteFolder=Nothing
   End If
Set FSO=Nothing
End Function
response.write "当前数据库大小为:<strong>"&GetTotalSize(Server.Mappath(dbfolder&dbname),File)&"</strong>  您可以进行如下操作:<br>"
response.write "<a href=mgdata.asp?action=backup>※备份当前数据库</a>"&"<br>"
response.write "<a href=mgdata.asp?action=backupList>※恢复所备份数据</a>"&"<br>"
response.write "<a href=mgdata.asp?action=compact>※压缩当前数据库</a>"&"<br>"
response.write "注意：数据库名称中不能包含特殊字符，否则影响以上操作。<br>"
response.write "多次备份数据会占用较多的空间，请及时对备份的数据库进行下载备份或删除。"
 
 ELSEIF(action="delfile")THEN
  Response.Write("<p>")
  IF goaler_isFileExist(Server.Mappath(dbfolder&strFileName))=1 THEN
   IF goaler_DeleteFile(Server.Mappath(dbfolder&strFileName))=1 THEN
    Response.Write("已成功删除备份文件：<b><font color=red>"&Server.Mappath(dbfolder&strFileName)&"</font></b>！")
   ELSE
    Response.Write("删除备份文件：<b><font color=red>"&Server.Mappath(dbfolder&strFileName)&"</font></b> 失败！")
   END IF
  ELSE
    Response.Write("备份文件：<b><font color=red>"&Server.Mappath(dbfolder&strFileName)&"</font></b> 不存在,或者含有特殊字符！")
  END IF 
  Response.Write("<br><a href="""&Request.ServerVariables("HTTP_REFERER")&""">请点击返回</a>")
  response.end
 ELSEIF(action="backupList")THEN
  Response.Write("<p>")
  dcheck=0
  Set DataFolder=FSO.GetFolder(Server.MapPath(dbfolder))
  Set DataFileList=DataFolder.Files
   For Each DataFile in DataFileList
    If Instr(DataFile,"bak") Then
     DataFileName=DataFile.Name
     Response.Write "<font color=#FF0000>"&DataFileName&"</font>&nbsp;&nbsp;|&nbsp;&nbsp;"
     Response.Write "备份时间："&DataFile.DateCreated&"&nbsp;&nbsp;|&nbsp;&nbsp;"
     Response.Write "<a href="&dbfolder&DataFileName&">下载</a>&nbsp;|&nbsp;"
     Response.Write "<a href=mgdata.asp?action=delfile&FileName="&DataFileName&" onclick=""return confirm('确认要删除该备份文件吗？')"">删除</a>&nbsp;|&nbsp;"
     Response.Write "<a href=mgdata.asp?action=restore&FileName="&DataFileName&" onclick=""return confirm('确认要从该备份文件还原数据吗？')"">从此备份文件还原数据</a><br>"
     dcheck=1
    End If
   Next
   if dcheck=0 then Response.Write "数据库尚未备份，或备份数据已被删除!(请备份后再执行恢复)"
 END IF
END IF 
SET FSO=Nothing
%>

</td>
          </tr>
        </table>
				
      </td>

</tr>
</table>
  <!--#include file="foot.asp"--></td>
        <td width="15" background="images/main_5.gif">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" background="images/main_4.gif">&nbsp;</td>
        <td background="images/main_9.gif">&nbsp;</td>
        <td width="15" background="images/main_5.gif">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="52">&nbsp;</td>
        <td background="images/main_7.gif" width="100%"></td>
        <td width="52">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

