<!--#include file="admin_conn.asp"-->
<%
chkLogin
dim action : action = be("get","action")

select case action
	case "reduction" : reduction
	case "del" : del
	case "delall" : delall
	case "compress":compress
	case "bak":bak
	case "riwen" : headAdmin "内存溢出修复" : riwen
	case else : headAdmin "数据库管理" : main
end select
dispseObj()

Function Jencode(byVal str)
	dim JapArr,i,japanStr
	JapArr=array("ガ","ギ","グ","ゲ","ゴ","ザ","ジ","ズ","ゼ","ゾ","ダ","ヂ","ヅ","デ","ド","バ","ビ","ブ","ベ","ボ","パ","ピ","プ","ペ","ポ","ヴ")
	if isN(str) then Jencode="" : Exit function
	japanStr=str
	for i=0 to 25
		if instr(japanStr,JapArr(i))>0 then japanStr= replaceStr(japanStr,JapArr(i),"")
	next
	Jencode = japanStr
End Function

sub bak
	dim file,filepath,sql
	file = app_dbtype &"_"& getRndStr(10) & ".bak"
	filepath = "bak/" & file
	if app_dbtype="access" then
		objFile.CopyFile app_installdir & app_dbpath,filepath
	elseif app_dbtype="mssql" then
		sql="backup database [" & app_dbname & "] to disk='" & server.MapPath(filepath) & "'"
		objdb.db sql,"exe"
	end if
	writeA "备份成功"
end sub

sub reduction
	dim file,filepath,sql,constr,con,srv,rest
	file = be("get","file")
	filepath = "bak/" & file
	objdb.Class_Terminate()
	if app_dbtype="access" then
		objFile.moveFile filepath,app_installdir&app_dbpath
	elseif app_dbtype="mssql" then
		constr = "Provider = Sqloledb; User ID = " & app_dbuser & "; Password = " & app_dbpass & "; Initial Catalog = " & app_dbname & "; Connect Timeout=600; Data Source = " & app_dbserver & ";"
		set con=Server.createobject("adodb.connection")
		con.Open constr
		sql="use master; restore database [" & app_dbname & "] from disk='" & server.MapPath(filepath) & "' with file=1"
		con.Execute sql
		con.close
		set con = nothing
	end if
	writeA "恢复成功"
end sub

sub compress
	dim tmppath,JetEngine,constr,con
	tmppath = "bak/maccmsdb.mdb"
	objdb.Class_Terminate()
	if app_dbtype="access" then
		set JetEngine = server.CreateObject("JRO.JetEngine")
		JetEngine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath(app_installdir&app_dbpath),"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.MapPath(tmppath)
		objFile.moveFile tmppath,app_installdir&app_dbpath
		set JetEngine = Nothing
	elseif app_dbtype="mssql" then
		constr = "Provider = Sqloledb; User ID = " & app_dbuser & "; Password = " & app_dbpass & "; Initial Catalog = " & app_dbname & "; Connect Timeout=600; Data Source = " & app_dbserver & ";"
		set con = Server.CreateObject("ADODB.Connection")
		con.Open constr
		con.Execute "BACKUP LOG [" & app_dbname & "] WITH NO_LOG"
		con.Execute "BACKUP LOG [" & app_dbname & "] WITH TRUNCATE_ONLY"
		con.Execute "DBCC SHRINKDATABASE(N'" & app_dbname & "' )"
		con.close
		set con = nothing
	end if
	writeA "压缩成功"
end sub

sub del
	dim file,filepath
	file = be("all","file")
	filepath = "bak/" & file
	objFile.DelFile filepath
	writeA "删除成功"
end sub

sub delall
	Dim file,filearr,filepath,i
	file = be("all","file")
	filearr = split(file,",")
	for i=0 to ubound(filearr)
		if not isN(filearr(i)) then
			filepath = "bak/" & trim(filearr(i))
			objFile.DelFile filepath
		end if
	next
	writeA "删除成功"
end sub

sub riwen
%>
<table class="tb">
<tr><td>编号</td><td>标题</td><td>主演</td><td>导演</td><td>状态</td></tr>
<%
    dim d_name,d_starring,d_directed,d_content,d_id,i,stat
	dim isupdate,rs,result,sql,page,j,pcount
	
	page = be("get","page") : if isN(page) then page=1 else page=cint(page)
	set rs = objdb.db("SELECT d_id,d_name,d_starring,d_directed,d_content FROM {pre}vod","rs1")
	if not rs.bof then
		rs.PageSize = 500 : rs.AbsolutePage = page
		pcount = rs.pagecount
		if page > rs.pagecount then writeE "<script>alert('恭喜，所有数据已经替换！');</script>"
		for j=1 to rs.pagesize
			if rs.eof then exit for
			d_name=rs("d_name") :	d_starring=rs("d_starring") : d_directed=rs("d_directed") : d_content=rs("d_content"):d_id=rs("d_id")
			d_name = replace(Jencode(d_name),"'","")
			d_starring = replace(Jencode(d_starring),"'","")
			d_directed = replace(Jencode(d_directed),"'","")
			d_content = replace(Jencode(d_content),"'","")
			if d_name<>rs("d_name") or d_starring<>rs("d_starring") or d_directed <> rs("d_directed") or d_content<> rs("d_content") then isupdate = true else isupdate = false
			
			if isupdate then
				result = objdb.Update("{pre}vod",Array("d_name","d_starring","d_directed","d_content"),Array(d_name,d_starring,d_directed,d_content),"d_id="& d_id)
				
				if result <> false Then  stat = "成功" else stat = "失败"
				writeF "<tr><td>" & d_id & "</td><td>" & d_name & "</td><td>" & d_starring & "</td><td>" & d_directed & "</td><td><font color=""blue"">"&stat&"</font></td></tr>"
			end if
			i = i+1
			rs.movenext
		next
	end if
	objdb.C(rs)
%>
</table>
</body>
</html>
<%
	writeE "<br><font color=red>共有"&pcount&"页数据，当前页第"&page&"页,暂停5秒后继续查询转换下一页请稍后...</font><br><script>setTimeout(""updatenext();"",5000);function updatenext(){location.href='admin_db.asp?action=riwen&page="&page + 1&"';}</script>"
end sub

sub main
	dim path,filelist,filelistarr1,filelistarr2,i
	path = "bak/"
	filelist = objFile.FileItem(path)
%>
<script type="text/javascript">
	$(document).ready(function(){
    	$("#btnDel").click(function(){
    		$("#form1").attr("action","?action=delall");
			$("#form1").submit();
    	});
    	$("#btnCompress").click(function(){
    		$("#form1").attr("action","?action=compress");
			$("#form1").submit();
    	});
    	$("#btnBak").click(function(){
    		$("#form1").attr("action","?action=bak");
			$("#form1").submit();
    	});
    	$("#btnRiwen").click(function(){
    		location.href= '?action=riwen';
    	});
    	$('#form1').form({
		onSubmit:function(){
			if(!$("#form1").valid()) {return false;}
		},
	    success:function(data){
	        $.messager.alert('系统提示', data, 'info',function(){
	        	location.href=location.href;
	        });
	    }
		});
	});
</script>
</head>
<body>
<form action="" method="post" id="form1" name="form1">
<table class="tb">
    <tr>
      <td width="5%">编号</td>
      <td>备份名称</td>
      <td width="10%">文件大小</td>
      <td width="15%">备份时间</td>
      <td width="15%">操作</td>
    </tr>
	 <%
	 if filelist=False then
	 	writeA "<tr><td colspan=""5"" align=center>没有任何文件</td></tr>"
	 else
	 filelistarr1 = split(filelist,"||")
	 for  i = 0 to ubound(filelistarr1)
	 	if not isN(filelistarr1(i)) then
	 	filelistarr2 = split(filelistarr1(i),"|")
	 		if filelistarr2(0)<>"update.xml" then
	 %>
    <tr>
      <td><input name="file" type="checkbox" id="file" value="<%=filelistarr2(0)%>" /></td>
      <td><%=filelistarr2(0)%></td>
      <td><%=filelistarr2(1)%>k</td>
      <td><%=filelistarr2(2)%></td>
      <td><A href="admin_db.asp?action=reduction&file=<%=filelistarr2(0)%>">还原</a> | <A href="admin_db.asp?action=del&file=<%=filelistarr2(0)%>" onClick="return confirm('确定要删除吗?');">删除</a></td>
    </tr>
    <%
    		end if
    	end if
    next
    end if
    %>
    <tr>
    <td colspan="5">
    <input name="chkall" type="checkbox" id="chkall" value="checkbox" onClick="checkAll(this.checked,'file');"/>
    <input type="button" id="btnDel" value="批量删除" class="input">
	<input type="button" id="btnCompress" value="压缩现有数据" class="input">
	<input type="button" id="btnBak" value="备份当前数据" class="input">
	<input type="button" id="btnRiwen" value="内存溢出修复" class="input">
    </td>
    </tr>
</table>
</form>
</body>
</html>
<%
end sub
%>