⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin_db.asp

📁 发布整站源码 可以再开发~ 本人实用中 效果嗷嗷滴~
💻 ASP
字号:
<!--#include file="config.asp"-->
<!--#include file="conn.asp"-->
<!--#include file="code.asp"-->
<%
'检查管理员是否登录
AdminName = ReplaceBadChar(Trim(Request.Cookies(webkey)("AdminName")))
AdminPassword = ReplaceBadChar(Trim(Request.Cookies(webkey)("AdminPassword")))
RndPassword = ReplaceBadChar(Trim(Request.Cookies(webkey)("RndPassword")))
If AdminName = "" Or AdminPassword = "" Or RndPassword = "" Then
	Response.Redirect "Admin_login.asp"
End If
%>
<%
dim action
action=trim(request("action"))
dim dbpath,bkfolder,bkdbname,fso,fso1
select case action
case "CompressDB"  '压缩数据库
	call CompressDB()
case "BackupDB"  '备份数据库
	if request("act")="Backup" then
		call updata()
	else
		call BackupDB()
	end if
case "RestoreDB" '恢复数据库
	if request("act")="Restore" then
		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
			response.write "成功恢复数据!"
		else
			response.write "备份目录下并无您的备份文件!"	
		end if
	else
		call RestoreDB()
	end if
case else
	call top()
	response.write "<p align=center><b>数据库管理说明:</b>对数据库操作的时候,需要FSO支持,FSO相关帮助请看微软网站</p>"
end select
%>
<html>
<head>
<title>管理员管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="image/css.css" rel="stylesheet" type="text/css">
<body leftMargin=0 bgcolor="#EFEFEF" topMargin=15>
<%sub top()%>
<br>
<table width="90%"  border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666">
  <tr>
    <td height="25" bgcolor="#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;数据库管理:&nbsp;&nbsp;<a href="?action=CompressDB">压缩数据库</a> <a href="?action=BackupDB">备份数据库</a> <a href="?action=RestoreDB">恢复数据库</a></td>
  </tr>
</table>
<%end sub%>
<%
'====================压缩数据库=========================
sub CompressDB()
call top()
%>
<br>
<form action="?action=CompressDB" method="post">
<table width="90%" border="0" align=center cellpadding="3"  cellspacing="1" bgcolor="#666666">
<tr>
<td height=25 bgcolor="#FFFFFF"><font color="#FF0000"><b>注意:</b></font><br>
    输入数据库所在相对路径,并且输入数据库名称(正在使用中数据库不能压缩,请选择备份数据库进行压缩操作) </td>
</tr>
<tr>
<td bgcolor="#EFEFEF">  压缩数据库:
  <input name="dbpath" type="text" value=<%=db_set%> size="25">
  &nbsp;
<input type="submit" value="开始压缩"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">  <input type="checkbox" name="boolIs97" value="True">
  如果使用 Access 97 数据库请选择(默认为 Access 2000 数据库)</td>
</tr>
</table>
<form>
<%
dim dbpath,boolIs97
dbpath = request("dbpath")
boolIs97 = request("boolIs97")
If dbpath <> "" Then
dbpath = server.mappath(dbpath)
	'response.write(CompactDB(dbpath,boolIs97))
	response.write "<p align=center>"&CompactDB(dbpath,boolIs97)&"</p>"
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
	CompactDB = "你的数据库“" & dbpath & "”已经压缩成功!" & vbCrLf
Else
	CompactDB = "数据库名称或路径不正确. 请重试!" & vbCrLf
End If
End Function
%>
<%
'====================备份数据库=========================
sub BackupDB()
call top()
%>
<br>
<form method="post" action="?action=BackupDB&act=Backup">
  <table width="90%" border="0" align=center cellpadding="3"  cellspacing="1" bgcolor="#666666">
    <tr>
      <td height=25 bgcolor="#EFEFEF">&nbsp;&nbsp;<B>备份数据库</B>( 需要FSO支持,FSO相关帮助请看微软网站 )</td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" class="forumrow">&nbsp;&nbsp; 当前数据库路径(相对路径):
          <input type=text size=25 name=DBpath value="<%=db_set%>">
          <BR>
&nbsp;&nbsp; 备份数据库目录(相对路径):
        <input type=text size=25 name=bkfolder value=Backup>
&nbsp;如目录不存在,程序将自动创建<BR>
&nbsp;&nbsp; 备份数据库名称(填写名称):
        <input type=text size=25 name=bkDBname value=3316.MDB>
&nbsp;如备份目录有该文件,将覆盖,如没有,将自动创建</td>
    </tr>
    <tr>
      <td align="center" bgcolor="#FFFFFF" class="forumrow"><input type=submit value="备份数据库"></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" class="forumrow">&nbsp;&nbsp;在上面填写本程序的数据库路径全名,本程序的默认数据库文件为<%=db_set%>,<B>请一定不能用默认名称命名备份数据库</B><br>
&nbsp;&nbsp;您可以用这个功能来备份您的法规数据,以保证您的数据安全!<br>
&nbsp;&nbsp;注意:所有路径都是相对与程序空间根目录的相对路径</td>
    </tr>
  </table>
</form>
<%
end sub
sub updata()
		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
			response.write "备份数据库成功,您备份的数据库路径为" &bkfolder& "\"& bkdbname
		Else
			response.write "找不到您所需要备份的文件。"
		End if
end sub
'------------------检查某一目录是否存在-------------------
Function CheckDir(FolderPath)
	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
    Set fso1 = CreateObject("Scripting.FileSystemObject")
        Set f = fso1.CreateFolder(foldername)
        MakeNewsDir = True
    Set fso1 = nothing
End Function
%>
<%
'====================恢复数据库=========================
sub RestoreDB()
call top()
%>
<form method="post" action="?action=RestoreDB&act=Restore">
  <table width="90%" border="0" align=center cellpadding="3"  cellspacing="1" bgcolor="#666666">
    <tr>
      <td height=25 bgcolor="#EFEFEF" >&nbsp;&nbsp;<B>恢复数据库</B>( 需要FSO支持,FSO相关帮助请看微软网站 ) </td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" class="forumrow">&nbsp;&nbsp;备份数据库路径(相对):
          <input type=text size=30 name=DBpath value="Backup\3316.MDB">
&nbsp;&nbsp;<BR>
&nbsp;&nbsp;目标数据库路径(相对):
        <input type=text size=30 name=backpath value="<%=db_set%>">
        <BR>
&nbsp;&nbsp;填写您当前使用的数据库路径,如不想覆盖当前文件,可自行命名(注意路径是否正确),然后修改配置文件,如果目标文件名和当前使用数据库名一致的话,不需修改</td>
    </tr>
    <tr>
      <td align="center" bgcolor="#FFFFFF" class="forumrow"><input type=submit value="恢复数据库"></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" class="forumrow">&nbsp;&nbsp;在上面填写本程序的数据库路径全名,本程序的默认备份数据库文件为Backup\3316.MDB,请按照您的备份文件自行修改。<br>
&nbsp;&nbsp;您可以用这个功能来备份您的法规数据,以保证您的数据安全!<br>
&nbsp;&nbsp;注意:所有路径都是相对与程序空间根目录的相对路径</td>
    </tr>
  </table>
</form>
<%
end sub
%>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -