Ku_Data.asp
Upload User: pengwei803
Upload Date: 2021-02-10
Package Size: 3311k
Code Size: 12k
Development Platform:

HTML/CSS

  1. <!--#include file="../Ku_inc/Ku_sql.asp"-->
  2. <!--#include file="../Ku_inc/Ku_config.asp"-->
  3. <!--#include file="Ku_conn.asp"-->
  4. <!--#include file="../Ku_inc/Ku_md5.asp"-->
  5. <!--#include file="../Ku_inc/inc.asp"-->
  6. <!-- #include file="Session.asp"-->
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  10. <title><%=webname%>-数据库管理</title>
  11. <link href="include/style.css" rel="stylesheet" type="text/css">
  12. <style type="text/css">
  13. <!--
  14. input{
  15. height:22px;
  16. border:1px solid #BEBEBE;
  17. background-color:#FFF;
  18. padding-top: 2px;
  19. padding-right: 8px;
  20. padding-bottom: 0pt;
  21. padding-left: 3px;
  22. }
  23. -->
  24. </style>
  25. </head>
  26. <body>
  27. <script>
  28. <!--
  29.  function del_check()
  30.  {
  31.     if(confirm("确定删除吗?"))
  32.         return true;
  33.     else
  34.        return false;
  35.  } 
  36. -->
  37. </script>
  38. <div class="div_3"></div>
  39. <table width="100%" border="0">
  40.     <tr>
  41.       <td>
  42.   <%
  43.  
  44. '**************************************************
  45. '函数名:IsObjInstalled
  46. '作  用:检查组件是否已经安装
  47. '参  数:strClassString ----组件名
  48. '返回值:True  ----已经安装
  49. '       False ----没有安装
  50. '**************************************************
  51. Function IsObjInstalled(strClassString)
  52. On Error Resume Next
  53. IsObjInstalled = False
  54. Err = 0
  55. Dim xTestObj
  56. Set xTestObj = Server.CreateObject(strClassString)
  57. If 0 = Err Then IsObjInstalled = True
  58. Set xTestObj = Nothing
  59. Err = 0
  60. End Function
  61. function deletefile(filename)
  62.     if filename<>"" then
  63.       set fso=server.CreateObject("scripting.FileSystemObject")
  64.       if fso.FileExists(filename) then
  65.         fso.DeleteFile filename
  66.       else
  67.     response.Write ""
  68.       end if
  69.   set fso=nothing
  70.     end if
  71. end function 
  72. ''------删除备份文件
  73. if request("action")="del" then
  74.    filename=server.MapPath(request("filename"))
  75.    deletefile(filename)
  76.    response.Redirect("ku_data.asp")
  77. end if
  78. 'RootUrl="http://"&Request.ServerVariables("server_name")&Request.ServerVariables("path_info")
  79. 'RootUrl="http://"&Request.ServerVariables("server_name")
  80. response.Write RootUrl
  81. Sub BackupData()
  82. ' On error resume next
  83. Dim FileConnStr, Fileconn, B_DBpath, B_BKpath, B_FileName
  84. B_DBpath = Request.Form("B_DBpath")
  85. B_DBpath = Server.Mappath(B_DBpath)
  86. B_BKpath = Request.Form("B_BKpath")
  87. B_BKpath = Server.Mappath(B_BKpath)
  88. B_FileName = Request.Form("B_FileName")
  89. FileConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & B_DBpath
  90. Set Fileconn = Server.CreateObject("ADODB.Connection")
  91. Fileconn.open FileConnStr
  92. Set Fileconn = Nothing
  93. Set Fso = Server.Createobject("scripting.FileSystemObject")
  94. If Fso.fileexists(B_DBpath) Then
  95. If CheckDir(B_BKpath) = True Then
  96. Fso.copyfile B_DBpath,B_BKpath& ""& B_FileName
  97. Else
  98. MakeNewsDir(B_BKpath)
  99. Fso.copyfile B_DBpath,B_BKpath& ""& B_FileName
  100. End If
  101. response.Write("备份数据库成功,您备份的数据库路径为" & B_BKpath & ""& B_FileName &"")
  102. Else
  103. response.Write("找不到您所需要备份的文件。。")
  104. End if
  105. End Sub
  106. '------------------检查某一目录是否存在-------------------
  107. Function CheckDir(FolderPath)
  108. ' folderpath=Server.MapPath(".")&""&folderpath
  109.     Set fso1 = CreateObject("Scripting.FileSystemObject")
  110.     If fso1.FolderExists(FolderPath) then
  111.        '存在
  112.        CheckDir = True
  113.     Else
  114.        '不存在
  115.        CheckDir = False
  116.     End if
  117.     Set fso1 = Nothing
  118. End Function
  119. '-------------根据指定名称生成目录-----------------------
  120. Function MakeNewsDir(foldername)
  121. dim f
  122.     Set fso1 = CreateObject("Scripting.FileSystemObject")
  123.         Set f = fso1.CreateFolder(foldername)
  124.         MakeNewsDir = True
  125.     Set fso1 = nothing
  126. End Function
  127. '=====================压缩参数=========================
  128. Function CompressData()
  129. Dim fso, Engine, strDBPath, JET_3X, dbPath
  130. dbPath = Trim(Request.Form("Y_DBpath"))
  131. dbPath = Server.Mappath(dbPath)
  132. strDBPath = left(dbPath,instrrev(DBPath,""))
  133. Set fso = CreateObject("Scripting.FileSystemObject")
  134. If fso.FileExists(dbPath) Then
  135. fso.CopyFile dbpath,strDBPath & "temp.mdb"
  136. Set Engine = CreateObject("JRO.JetEngine")
  137. Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
  138. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"
  139. fso.CopyFile strDBPath & "temp1.mdb",dbpath
  140. fso.DeleteFile(strDBPath & "temp.mdb")
  141. fso.DeleteFile(strDBPath & "temp1.mdb")
  142. Set fso = Nothing
  143. Set Engine = Nothing
  144. response.Write("你的数据库"&dbpath&"已经压缩成功!")
  145. Else
  146. response.Write("数据库名称或路径不正确,请重新操作!")
  147. End If
  148. End Function
  149. %>
  150.         <%
  151. Dim fso,fso1, Action, H_Level 
  152. 'Action = GetSafeStr(Trim(Request("action")))
  153. Action =Trim(Request("action"))
  154. H_Level = Session("Sys_Level")
  155. Select Case Action
  156. Case "CompressData" '压缩数据
  157. 'If H_Level <> 3 Then
  158. ' response.Write("您的权限不够进行此操作!")
  159. 'Else
  160. Call CompressData()
  161. 'End If
  162. Case "BackupData" '备份数据
  163. 'If H_Level <> 3 Then
  164. ' response.Write("您的权限不够进行此操作!")
  165. 'Else
  166. Call BackupData()
  167. 'End If
  168. Case "RestoreData" '恢复数据
  169. 'If H_Level <> 3 Then
  170. ' response.Write("您的权限不够进行此操作!")
  171. 'Else
  172. Dim H_DBpath, H_Backpath
  173. H_DBpath = request.form("H_DBpath")
  174. H_Backpath = request.form("H_Backpath")
  175. If H_DBpath = "" then
  176. response.Write("请输入您要恢复成的数据库全名!")
  177. Else
  178. H_DBpath = Server.Mappath(H_DBpath)
  179. End if
  180. H_Backpath = Server.Mappath(H_Backpath)
  181. Set Fso = Server.CreateObject("scripting.FileSystemObject")
  182. If fso.fileexists(H_Backpath) Then  
  183. fso.copyfile H_Backpath,H_DBpath
  184. response.Write("成功恢复数据!")
  185. Else
  186. response.Write("备份目录下并无您的备份文件!")
  187. End If
  188. 'End If
  189. End Select
  190. '====================恢复数据库=========================
  191. 'Call Header("数据库操作处理")
  192. Call Content()
  193. 'Call Footer()
  194. ' 开始写入内容
  195. Sub Content()
  196. %>
  197.         <%'====================恢复数据库=========================%>
  198.         <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  199.           <tr>
  200.             <td height="25" class="td_title"><b><font color="#FF0000">数据库操作</font></b></td>
  201.           </tr>
  202.         </table>
  203.         <%'====================备份数据库=========================%>
  204.         <table width="100%" border="0" align="center" cellpadding="5"  cellspacing="1" bgcolor="#DDDDDD">
  205.           <tr>
  206.             <td width="713" bgcolor="#999999"><b style="color:#000000">备份数据 </b>(所有路径都是相对与程序空间根目录的相对路径)</td>
  207.           </tr>
  208.           <form method="post" action="ku_data.asp?action=BackupData">
  209.             <tr>
  210.               <td> 当前数据库路径(绝对路径):
  211.                 <input name="B_DBpath" type="text" id="B_DBpath" value="<%=db%>" size="60" class="button1" / readonly></td>
  212.             </tr>
  213.             <tr>
  214.               <td height="25">备份数据库目录(绝对路径):
  215.                 <input name="B_BKpath" type="text" id="B_BKpath" value="../Databackup" size="60" class="button1" / readonly></td>
  216.             </tr>
  217.             <tr>
  218.               <td>备份数据库名称(填写名称):
  219.                 <input type="button" name="tjiao" value="加日期" onClick="B_FileName.value='<%=formatdatetime(now(),Vbshortdate)%><%=dataBak_name%>beifen.sql'"/>
  220.                 <input name="B_FileName" type="text" id="B_FileName" value="<%=dataBak_name%>beifen.sql" size="35" class="button1" / readonly>
  221.                 <input name="submit2" type="submit" value="确定备份" class="button2" /></td>
  222.             </tr>
  223.             <tr>
  224.               <td bgcolor="#FFFFFF">-----------------------------------------------------------------------------------------<br />
  225.                 <b>注意:</b>您可以用这个功能来备份您的法规数据,以保证您的数据安全!如备份目录不存在,程序将自动创建;如备份目录有该数据库文件,将覆盖,如没有,将自动创建。在上面填写本程序的数据库路径全名,本程序的默认数据库文件为“<%=data_path%>”,<font color="#FF0000">请不要用默认名称命名备份数据库。</font></td>
  226.             </tr>
  227.           </form>
  228.         </table>
  229.         <%'====================压缩数据库 =========================%>
  230.         <table border="0"  cellspacing="1" cellpadding="3" align="center" width="100%">
  231.           <form action="ku_data.asp?action=CompressData" method="post">
  232.             <tr>
  233.               <td><b>压缩系统数据 </b>(所有路径都是相对与程序空间根目录的相对路径)</td>
  234.             </tr>
  235.             <tr>
  236.               <td>压缩数据库:
  237.                 <input name="Y_DBpath" type="text" id="Y_DBpath" value="<%=db%>" size="60" class="button1" / readonly>
  238.                 <input name="submit3" type="submit" value="开始压缩" class="button2" /></td>
  239.             </tr>
  240.             <tr>
  241.               <td><b>注意:</b>输入数据库所在相对路径,并且输入数据库名称。(本系统采用 Access 2000 数据库)</td>
  242.             </tr>
  243.           </form>
  244.           <form>
  245.           </form>
  246.         </table>
  247.         <table border="0"  cellspacing="0" cellpadding="5" align="center" width="100%">
  248.           <form action="ku_data.asp?action=CompressData" method="post">
  249.             <tr>
  250.               <td class="td_title"><div align="center"><span class="STYLE1">当前数据库文件大小:</span>
  251.                 <%
  252. If not IsObjInstalled("Scripting.FileSystemObject") Then
  253.            Response.Write "<b><font color=red>服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
  254.        Else
  255.     Set fso=Server.CreateObject("Scripting.FileSystemObject")
  256.     file_=db      ''当前数据库路径
  257.            If fso.FileExists(file_) Then
  258.               response.Write "找不到文件"
  259.    Else
  260.       set fz=fso.getfile(server.MapPath(file_))
  261.   response.Write FormatNumber(fz.size/1024,0)&"KB"
  262.   set fz=nothing
  263.    end if
  264. '   set fso=nothing
  265.    end if
  266. %>
  267.                 </div></td>
  268.             </tr>
  269.           </form>
  270.           <form>
  271.           </form>
  272.         </table>
  273.         <table width="100%" border="0" align="center" cellpadding="3"  cellspacing="0" bgcolor="#CCCCCC">
  274.           <form action="ku_data.asp?action=CompressData" method="post">
  275.             <tr>
  276.               <td>
  277.                 <table width="100%" border="0">
  278.                   <tr>
  279.                     <td width="180" class="td2">文件名</td>
  280.                       <td width="91" class="td2">文件大小</td>
  281.                       <td width="113" class="td2">备份日期</td>
  282.                       <td width="44" class="td2">删除</td>
  283.                   </tr>
  284.                   <%
  285.                   dataUP_dir="Databackup/"
  286.    If not IsObjInstalled("Scripting.FileSystemObject") Then
  287.  Response.Write "<b><font color=red>服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
  288.    Else
  289.      If fso.FolderExists(dataUP_dir&dataBak_path) Then
  290.         response.Write "找不到备份文件夹"
  291.  Else
  292.     Set theFolder=fso.GetFolder(server.MapPath("../"&dataUP_dir&dataBak_path))
  293.     response.Write "备份数据库文件夹占空间大小为:"&FormatNumber(theFolder.Size/1024/1024,5)&"MB"
  294.         For Each theFile In theFolder.Files   
  295.   %>
  296.                   <tr height="22">
  297.                     <td bgcolor="#FFFFFF"><%=theFile.Name%></td>
  298.                       <td bgcolor="#FFFFFF"><%=FormatNumber(theFile.Size/1024,0)%>KB</td>
  299.                       <td bgcolor="#FFFFFF"><%=theFile.DateLastModified%></td>
  300.                       <td bgcolor="#FFFFFF"><a href="?action=del&amp;filename=<%=server.URLEncode("../"&dataUP_dir&dataBak_path&theFile.Name)%>" onClick="return del_check();">删除</a></td>
  301.                   </tr>
  302.                   <%
  303.        next
  304.    set theFolder=nothing
  305.    set fso=nothing
  306.   end if    
  307.   end if
  308.   %>
  309.                 </table></td>
  310.             </tr>
  311.           </form>
  312.           <form>
  313.           </form>
  314.         </table>
  315.         <p>&nbsp; </p>
  316.       <%
  317. End Sub
  318. %></td>
  319.     </tr>
  320.   </table>
  321. <!--#include file="Ku_bottom.asp" -->
  322. </body>
  323. </html>
  324. <%
  325. %>