<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.tool.*" %>
<%@ include file="/sessionInfo.jsp"%>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<%
    String backDir = "d:\\SZOA\\database\\";
	
	
	SzBackUp backUp = new SzBackUp();
	String time = backUp.getTime();
	String cycle = backUp.getCycle();
	
	int iCount = SzConvert.toInt(request.getParameter("fileCount"));
	if (iCount <= 0) {
		iCount = 10;
	}
	String strName = SzConvert.strWriteData(request.getParameter("fileName"));
	ArrayList list  = backUp.getFileList(iCount, backDir, strName);
	if (!backUp.getBackDir().equals("")) {
		backDir = backUp.getBackDir();
	}
	boolean autoBackup = backUp.getAutoBackup();
	
	int iLen = list.size();
%>
<!-----上面的工具栏------>
<%@ include file="/share/title.jsp"%>
<form name="formUpdate" method="post" action="control.jsp">
  <input type="hidden" name="OPERATOR" value="">
<table width="100%">
  <tr>
    <td>&nbsp;<b>数据库备份信息</b>
    </td>
  </tr>
</table>

<!-----信息维护------>
<table width="700" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td width="150" align="right">数据库备份路径（文件夹）</td>
    <td><input type="text" class="txtClass2" name="backDir" value="<%=backDir %>">
    	<input type="button" class="btnClass" value="手动备份" disabled  OnClick="javascript:BackUp();"><br>
    	<font color="red">系统自动按照“数据库名称 + 年-月-日_时-分.bak”的名称备份</font>
    </td>
  </tr>
  <tr>
    <td align="right">自动备份</td>
    <td>
    	<input type="radio" name="cycle" value="1" <% if (cycle.equals("1")) { out.println("checked"); } %> <%if (autoBackup) { out.println("disabled");} %> >每周周一
    	<input type="radio" name="cycle" value="2" <% if (cycle.equals("2")) { out.println("checked"); } %> <%if (autoBackup) { out.println("disabled");} %> >每天
    	备份时间<input type="text" name="time1" class="txtClass60" value="<%=time %>" <%if (autoBackup) { out.println("disabled");} %>>
    	(默认凌晨1点)
    	<input type="button" class="btnClass" value="启动" disabled OnClick="javascript:Start();" <%if (autoBackup) { out.println("disabled");} %>>
    	<input type="button" class="btnClass" value="停止" disabled OnClick="javascript:Stop();" <%if (!autoBackup) { out.println("disabled");} %>>
    </td>
  </tr>
</table>
<br>
<table width="100%">
  <tr>
    <td>&nbsp;<b>数据库还原信息</b>
    </td>
  </tr>
</table>
<table width="700" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td colspan="2">
    	显示的文件数量：<input type="text" class="txtClass60" name="fileCount" value="<%=iCount %>">
    	文件名检索：<input type="text" class="txtClass" name="fileName" value="<%=strName%>">
    	<input type="button" class="btnClass" value="确定" OnClick="javascript:SearchOk();";><br>
    	<font color="red"><b>注意：</b>还原操作会暂停数据库服务，系统暂时无法使用！</font>
    	
    </td>
  </tr>  
  <tr class="trClassTitle">
    <td>当前文件夹下的备份文件
    </td>
    <td>操作</td>
  </tr>
  <%
    String sName = "";
  	for (int i = iLen -1; i>=0; i--) {
  		sName = (String)list.get(i);
  %>
  <tr>
    <td><%=sName %></td>
    <td>
    <input type="button" class="btnClass" value="删除" OnClick="javascript:Delete('<%=sName %>');" <%if (i == iLen -1) { out.println("disabled");} %>>
    <input type="button" class="btnClass" value="还原" OnClick="javascript:StoreUp('<%=sName %>');">
    </td>
  </tr>  
  <%  		
  	}
  %>
</table>

</form>

<script language="javascript">
  //第一个表示对象，form，第二个表示字符串
  function FormSubmit(oFormName, vUrl) {
    oFormName.action = vUrl;
    oFormName.submit();
  }
</script>
<script language="javascript">
  function Start() {
  	formUpdate.OPERATOR.value = "start";
  	formUpdate.action = "control.jsp";
  	formUpdate.submit();
  }

  function Stop() {
  	formUpdate.OPERATOR.value = "stop";
  	formUpdate.action = "control.jsp";
  	formUpdate.submit();
  }
  
  function BackUp() {
  	formUpdate.OPERATOR.value = "backup";
  	formUpdate.action = "control.jsp";
  	formUpdate.submit();
  }
  
  function SearchOk() {
  	formUpdate.action = "index.jsp";
  	formUpdate.submit();  
  }
  
  function Delete(sFile) {
    if (confirm("确定删除已经备份的文件?")) {    
  	  formUpdate.OPERATOR.value = "delete";
  	  formUpdate.action = "control.jsp?sFile=" + sFile;
  	  formUpdate.submit();
  	}	
  }

  function StoreUp(sFile) {
    if (confirm("确定还原?")) {    
  	  formUpdate.OPERATOR.value = "store";
  	  formUpdate.action = "control.jsp?sFile=" + sFile;
  	  formUpdate.submit();
  	}	
  }
  
  function FormSave(formName, url) {
    //检查是否可以保存
    if (formName.szDLMM.value != formName.DLMM.value) {
      formName.DLMM.focus();
      alert("原始密码不正确，请重新输入");
      return false;
    }
    if (formName.DLMM1.value != formName.DLMM2.value) {
      formName.DLMM1.focus();
      alert("新的密码和确认密码不一样，请重新输入");
      return false;
    }
    //提交
    formName.action = url;
    formName.submit();
  }
</script>