<html>
<head>
<META content=ywnt,云网互动影视管理系统 name=keywords>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>云网互动影视6.0--数据库管理</title>
<LINK href="css/css.css" type=text/css rel=stylesheet>
</head>
<BODY leftMargin=0 topMargin=0 scroll=yes MARGINHEIGHT="0" MARGINWIDTH="0">
<!--#include file="../Conn.asp" -->
<!--#include file="YWNT_TMS_inc/YWNT_TMS_Function.asp" -->
<%
'===================================================================================================================
'软件名称：云网影视管理系统
'Copyright (C) 2002-2007 ywnt.net  All rights reserved.
'产品咨询QQ：489234,2813712
'程序版权：云网互动科技有限公司
'程序开发：云网互动科技有限公司
'官方网站：http://www.ywnt.net 
'郑重声明:
'    1、免费版本请在程序首页保留版权信息，并做上本站LOGO友情连接,商业版本无此要求;
'    2、任何个人或组织不得在授权允许的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    3、云网互动科技有限公司保留此软件的法律追究权利
'===================================================================================================================
Call CheckLogin("Data")%>
<TABLE class=table cellSpacing=1 cellPadding=3 width="98%" align=center border=0>
  <TBODY>
    <TR>
      <TD class=xingmu colSpan=3>数据库管理</TD>
    </TR>
    <TR>
      <TD class="hback"> <a href="Admin_Data.asp?action=Backup">备份数据库</a> | <a href="Admin_Data.asp?action=Restore">还原数据库</a> | <a href="Admin_Data.asp?action=Compact">压缩数据库</a></TD>
    </TR>
  </TBODY>
</TABLE>
<%Action=Trim(request("Action"))
Select Case Action
Case "Backup"
	call ShowBackup()
Case "BackupData"
	Call AddLog("备份数据库",1)
	call BackupData()
Case "Compact"
	call ShowCompact()
Case "CompactData"
	Call AddLog("压缩数据库",1)
	call CompactData()
Case "Restore"
	call ShowRestore()
Case "RestoreData"
    if request("submit")<> "" then
	call RestoreData()
	else
	Call AddLog("删除备份数据库",1)
	call DelBackup()
	end if
Case else
	call Admin_ShowErr("<li>错误参数</li>","Admin_Data.asp?action=Backup",0)
End Select
Function TimeName(DataBackName)
	DataBackName=Replace(DataBackName,"-","")
	DataBackName=Replace(DataBackName,":","")
	DataBackName=Replace(DataBackName," ","")
	TimeName=DataBackName
end Function
sub BackupData()
	dim DataBackName,DataBackDir,fso
	DataBackDir=Trim(request.form("DataBackDir"))
	DataBackName=Trim(request.form("DataBackName"))
	if DataBackDir="" then
		FoundErr=True
		call Admin_ShowErr("<li>备份目录不能为空！</li>","Admin_Data.asp?action=Backup",0)
	end if
	if DataBackName="" then
		FoundErr=True
		call Admin_ShowErr("<li>备份文件名不能为空！</li>","Admin_Data.asp?action=Backup",0)
	end if
	if FoundErr=True then exit sub
	DataBackDir=server.MapPath("../database/"&DataBackDir)
	Set Fso=server.createobject("Scripting.FileSystemObject")
	if fso.FileExists(server.mappath(datapath)) then
		If fso.FolderExists(DataBackDir)=false Then
			fso.CreateFolder(DataBackDir)
		end if
		fso.copyfile server.mappath(datapath),DataBackDir & "\" & DataBackName
		call Admin_ShowErr("<li>备份数据库成功！</li><li>备份的数据库为" & DataBackDir & "\" & DataBackName & "</li>","Admin_Data.asp?action=Backup",1)
	Else
		call Admin_ShowErr("<li>找不到源数据库文件，请检查Conn.asp中的配置！</li>","Admin_Data.asp?action=Backup",0)
	End if
	Set fso = Nothing
end sub

 sub CompactData()
	Dim fso, Engine, strdatapath
	DataPathx=Server.mappath(datapath)
	strdatapath = left(DataPathx,instrrev(DataPathx,"\"))
	on error resume next
	Set Conn = Nothing
	Set Fso=server.createobject("Scripting.FileSystemObject")
	If fso.FileExists(Datapathx) Then
		Set Engine = CreateObject("JRO.JetEngine")
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataPathx," Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strdatapath & "temp.mdb"
		fso.CopyFile strdatapath & "temp.mdb",DataPathx
		fso.DeleteFile(strdatapath & "temp.mdb")
		Set fso = Nothing
		Set Engine = Nothing
		call Admin_ShowErr("<li>数据库压缩成功！</li>","Admin_Data.asp?action=Compact",1)
	Else
		call Admin_ShowErr("<li>没有找到数据库！</li>","Admin_Data.asp?action=Compact",0)
	End If
end sub 

sub RestoreData()
	dim backpath,fso
	backpath=request.form("backpath")
	if backpath="" then
		FoundErr=True
		call Admin_ShowErr("<li>请指定原备份的数据库文件名！</li>","Admin_Data.asp?action=Restore",0)
		exit sub	
	end if
	backpath=server.mappath(backpath)
	on error resume next
	Set Conn = Nothing
	Set Fso=server.createobject("Scripting.FileSystemObject")
	if fso.fileexists(backpath) then  					
		fso.copyfile Backpath,Server.mappath(datapath)
		call Admin_ShowErr("<li>成功恢复数据！</li>","Admin_Data.asp?action=Restore",1)
	else
		call Admin_ShowErr("<li>找不到指定的备份文件！</li>","Admin_Data.asp?action=Restore",0)
	end if
	Set Fso=Nothing
end sub

Sub DelBackup()
	dim Document,fso
	backpath=request.form("backpath")
	if backpath="" then
		FoundErr=True
		call Admin_ShowErr("<li>请指定备份的数据库文件名！</li>","Admin_Data.asp?action=Restore",0)
		exit sub	
	end if
	Set Fso=server.createobject("Scripting.FileSystemObject")
	fso.DeleteFile(server.mappath(backpath))
	call Admin_ShowErr("<li>成功删除数据库！</li>","Admin_Data.asp?action=Restore",1)
	Set Fso=Nothing
End sub

sub ShowBackup()%>
<TABLE class=table cellSpacing=1 cellPadding=3 width="98%" align=center border=0>
<form method="post" action="Admin_Data.asp?action=BackupData">
  <TBODY>
    <TR>
      <TD colspan="2" class=xingmu>备份数据库</TD>
    </TR>
    <TR>
      <TD width="21%" height=32 align="right" class="hback">数据库备份目录：</TD>
      <TD width="79%" class="hback"><input name="DataBackDir" type="text" id="DataBackDir" value="DataBackup" size="40" ReadOnly>
      如果目录不存在，程序将自动创建！</TD>
    </TR>
    <TR>
      <TD width="21%" height=32 align="right" class="hback">备份数据库名称：</TD>
      <TD class="hback"><input name="DataBackName" type="text" id="DataBackName" value="<%=TimeName(Now())%>_Bak.asa" size="40">
如果备份目录有该文件，将覆盖，如果没有，程序将自动创建！</TD>
    </TR>
    <TR align="center">
      <TD height=32 colspan="2" class="hback"><input name="submit" type=submit value=" 开始备份 "></TD>
    </TR>
  </TBODY>
  </form>
</TABLE>
<%end sub
sub ShowRestore()%>
  <TABLE class=table cellSpacing=1 cellPadding=3 width="98%" align=center border=0>
    <TBODY>
      <TR>
        <TD colspan="4" class=xingmu>还原数据库</TD>
      </TR>
	        <TR>
        <TD width="39%" height=32 align="center" class="hback">备份数据库名称</TD>
        <TD width="18%" align="center" class="hback">文件大小</TD>
        <TD width="16%" align="center" class="hback">备份时间</TD>
        <TD width="27%" align="center" class="hback">操作</TD>
	        </TR>
	<% Dim Fso
	Set Fso=server.createobject("Scripting.FileSystemObject")
	dim theFolder,theFile,strFileType
	if Not fso.FolderExists(Server.MapPath("../database/DataBackup")) then
		response.write "找不到数据库备份文件夹 DataBackup"
		response.end
	end if
	Set theFolder=fso.GetFolder(Server.MapPath("../database/DataBackup"))
	For Each theFile In theFolder.Files %>
	  <form method="Post" action="Admin_Data.asp?action=RestoreData">
      <TR>
        <TD width="39%" height=32 class="hback"><%=theFile.Name%></TD>
        <TD width="18%" align="center" class="hback"><%=round(theFile.size/1024) & " K"%></TD>
        <TD width="16%" align="center" class="hback"><%=theFile.DateLastModified%></TD>
        <TD width="27%" align="center" class="hback"><input name="backpath" type="hidden" value="../database/DataBackup/<%=theFile.Name%>"><input name="submit" type="submit" value=" 恢复数据 " onClick="return confirm('确定恢复数据库吗？，此操作将替换现在使用中的数据库！');">
          <input name="Del" type="submit" value=" 删除备份 " onClick="return confirm('确定删除备份文件吗？');"></TD>
      </TR>
	  </form>
<%Next
Set Fso=Nothing%>
    </TBODY>
  </TABLE>
 <%end sub
 sub ShowCompact()%>
  <TABLE class=table cellSpacing=1 cellPadding=3 width="98%" align=center border=0>
    <TBODY>
      <TR>
        <TD class=xingmu>压缩数据库</TD>
      </TR>
      <TR>
        <TD height=32 align="center" class="hback">压缩前，建议先备份数据库，以免发生意外错误。 </TD>
      </TR>
    <form method="post" action="Admin_Data.asp?action=CompactData">
      <TR>
        <TD height=32 align="center" class="hback"><input name="submit" type=submit value=" 压缩数据库 "></TD>
      </TR>
    </form>
	  </TBODY>
  </TABLE>
 <%end sub
 call connclose()%>
</BODY></HTML>
