<!--#include file="../common/conn.asp"-->
<%
'检查用户权限
call checkuser("数据库管理")
%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE>
BODY {
	FONT-SIZE: 9pt
}
TABLE {
	FONT-SIZE: 9pt
}
TH {
	FONT-WEIGHT: 500; FONT-SIZE: 9pt
}
A:link {
	COLOR: #dd006f; TEXT-DECORATION: none
}
A:visited {
	TEXT-DECORATION: none
}
A:active {
	TEXT-DECORATION: none
}
A:hover {
	COLOR: #9933ff; TEXT-DECORATION: underline
}

</STYLE>
<title>数据库管理</title></head>
<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0">
<%
Dim Atcion
Atcion=Request.QueryString ("atcion")

Select Case LCase(Atcion)
Case "diskview"
	call DiskView
Case "backupdata"
	call backupdata
Case "backup"
	call Backup
Case "execute"
	Call Execute()
Case "exe"
	Err.Clear 
	On Error Resume Next
	SQL=Request.Form("text")
	Conn.Execute(SQL)
	If Err.number=0 Then 
		Response.Write "语句已经执行成功！"
	Else
		Response.Write "发生错误，错误信息如下：<br>"&Err.Description 
	End If
End Select
%> 
<%sub DiskView()%> 
<table width="100%" height="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#336600">
  <tr> 
    <td height="26" bgcolor="#669900"> <font color="#FFFFFF"><strong>::数据库管理－系统空间占用情况</strong></font></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td height="100%" valign="top"> 
      <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td>
		  备份数据占用空间：&nbsp;&nbsp; <%showSpaceinfo("../databackup")%>
            <br>
            <br>
          数据库占用空间：&nbsp;&nbsp;
            <%showSpaceinfo("../../data")%>
            <br>
            <br>
		  上传文件占用空间：&nbsp;&nbsp; <%showSpaceinfo("../../upfile")%>
            <br>
            <br>
            管理目录占用空间(包括数据库)：&nbsp;&nbsp;
            <%showSpaceinfo("../")%>
            <br>
            <br>
            系统占用空间总计：&nbsp;&nbsp;
            <%showSpaceinfo("../../")%></td>
        </tr>
      </table> 
    </td>
  </tr>
</table>
<%
End Sub
%>
<%sub backupdata()%> 
<table width="100%" height="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#336600">
  <tr> 
    <td height="26" bgcolor="#669900"> <font color="#FFFFFF"><strong>::数据库管理－备份系统数据库</strong></font></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td height="100%" valign="top"> 
      <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr> 
          <td>&nbsp;</td>
        </tr>
        <form name="form1" method="post" action="?atcion=Backup">
          <tr> 
            <td>备份目录： 
              <input type=text size=20 name=bkfolder value="Databackup" disabled> </td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td>备份文件名： <input type=text size=20 name=bkDBname value="<%=date()%>.mdb"></td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><input type=submit value="备份数据" id=submit2 name=submit2></td>
          </tr>
        </form>
      </table> 
    </td>
  </tr>
</table>
<%
End Sub
%>
<%
	Sub Backup()
		Dim dbpath,bkfolder,bkdbname
		Dim fso
		Set Fso=server.createobject("scripting.filesystemobject")
		
		dbpath=server.MapPath ("../../data/#data.mdb")
		bkfolder=server.MapPath("../Databackup")
		bkdbname=Request.Form ("bkDBname")
		
		If fso.fileexists(dbpath) Then
			If fso.FolderExists(bkfolder) = True Then
			Else
				fso.CreateFolder(bkfolder)
			End If		
			if fso.fileexists (bkfolder& "\"& bkdbname) then
				response.write "此备份已存在"
			else
				fso.copyfile dbpath,bkfolder& "\"& bkdbname
				Response.Write "备份数据库完成，<a href='../Databackup\"& Request.Form ("bkDBname")&"'><font color=red>点击下载</font></a>。"
			end if
		End If
		Set fso=Nothing
	End Sub
%>

<%sub Execute()%> 
<table width="100%" height="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#336600">
  <tr> 
    <td height="26" bgcolor="#669900"> <font color="#FFFFFF"><strong>::数据库管理－数据库高级管理</strong></font></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td height="100%" valign="top"> <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr> 
          <td>&nbsp;</td>
        </tr>
        <form name="form1" method="post" action="?atcion=exe">
          <tr> 
            <td>&nbsp;SQL&nbsp;&nbsp; <textarea name="text" cols="55" rows="4" wrap="VIRTUAL"></textarea></td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td><input type=submit value="执行语句" id=submit23 name=submit22></td>
          </tr>
        </form>
      </table></td>
  </tr>
</table>
<%
End Sub
%>

<%Sub ShowSpaceInfo(drvpath)
 		dim fso,d,size,showsize
 		set fso=server.createobject("scripting.filesystemobject") 		
 		drvpath=server.mappath(drvpath)
 		set d=fso.getfolder(drvpath) 		
 		size=d.size
 		showsize=size & "&nbsp;Byte" 
 		if size>1024 then
 		   size=(size\1024)
 		   showsize=size & "&nbsp;KB"
 		end if
 		if size>1024 then
 		   size=(size/1024)
 		   showsize=formatnumber(size,2) & "&nbsp;MB"		
 		end if
 		if size>1024 then
 		   size=(size/1024)
 		   showsize=formatnumber(size,2) & "&nbsp;GB"	   
 		end if   
 		response.write "<font face=verdana>" & showsize & "</font>"
 	End Sub	
 	
 	Sub Showspecialspaceinfo(method)
 		dim fso,d,fc,f1,size,showsize,drvpath 		
 		set fso=server.createobject("scripting.filesystemobject")
 		drvpath=server.mappath("pic")
 		drvpath=left(drvpath,(instrrev(drvpath,"\")-1))
 		set d=fso.getfolder(drvpath) 		
 		
 		if method="All" then 		
 			size=d.size
 		elseif method="Program" then
 			set fc=d.Files
 			for each f1 in fc
 				size=size+f1.size
 			next	
 		end if	
 		
 		showsize=size & "&nbsp;Byte" 
 		if size>1024 then
 		   size=(size\1024)
 		   showsize=size & "&nbsp;KB"
 		end if
 		if size>1024 then
 		   size=(size/1024)
 		   showsize=formatnumber(size,2) & "&nbsp;MB"		
 		end if
 		if size>1024 then
 		   size=(size/1024)
 		   showsize=formatnumber(size,2) & "&nbsp;GB"	   
 		end if   
 		response.write "<font face=verdana>" & showsize & "</font>"
 	end sub 	 	 	
 	
 	Function Drawbar(drvpath)
 		dim fso,drvpathroot,d,size,totalsize,barsize
 		set fso=server.createobject("scripting.filesystemobject")
 		drvpathroot=server.mappath("pic")
 		drvpathroot=left(drvpathroot,(instrrev(drvpathroot,"\")-1))
 		set d=fso.getfolder(drvpathroot)
 		totalsize=d.size
 		
 		drvpath=server.mappath(drvpath) 		
 		set d=fso.getfolder(drvpath)
 		size=d.size
 		
 		barsize=cint((size/totalsize)*400)
 		Drawbar=barsize
 	End Function 	
 	
 	Function Drawspecialbar()
 		dim fso,drvpathroot,d,fc,f1,size,totalsize,barsize
 		set fso=server.createobject("scripting.filesystemobject")
 		drvpathroot=server.mappath("pic")
 		drvpathroot=left(drvpathroot,(instrrev(drvpathroot,"\")-1))
 		set d=fso.getfolder(drvpathroot)
 		totalsize=d.size
 		
 		set fc=d.files
 		for each f1 in fc
 			size=size+f1.size
 		next	
 		
 		barsize=cint((size/totalsize)*400)
 		Drawspecialbar=barsize
 	End Function 	
%>
</body>
</html>