<%@ page language="C#" autoeventwireup="true" inherits="SB_admin_index_backup, App_Web_wywlgbzm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>操作</title>

    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.min.js?v=1")%>"></script>

    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.easyui.min.js?v=1.3")%>"></script>

    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/locale/easyui-lang-zh_CN.js?v=1.0")%>"></script>

    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.load.js?v=1.0")%>"></script>

    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.json.js?v=1.0")%>"></script>

    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.easyui.validtor.js?v=1.0")%>"></script>

    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/js/PageDialog.js?v=1.0")%>"></script>

    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/SB/control/easy_ui/themes/gray/easyui.css?v=1.0")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/SB/control/easy_ui/themes/icon.css?v=1.0")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/SB/control/easy_ui/load.css?v=1.0")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/SB/control/css/main.css?v=1.0")%>" />
    
    <script language="javascript" type="text/javascript">
    var isEdit = false;
    $(function(){
       $("#dlg").dialog({
            iconCls:'icon-save',
            closed:true
            });
            
        $("#dataview").datagrid({
            toolbar:"#toolbar",
            fit:true,
            idfield:"id",
            border:false,
            pageSize:30,
            resizable:true,
            pagination:false,
            rownumbers:true,
            url:"backup.aspx?showData=1",
            onLoadSuccess:function(){ $('#dataview').datagrid("unselectAll"); }
          
        });
        
        $("#btnBackDatabase").click(function(){
            if(!isEdit)
            BackDataBase();
            else
            saveEditFile();
            
        });
    });
    
    function BackDataBase(){
         $.messager.confirm('确认','确定备份当前数据库吗？',function(r){
                 if(!r){ return }
                 load("备份中，根据数据库大小等待不同的时间...");
                 $.ajax({
                    type: "POST",
                    url:"backup.aspx?backData=1",
                    dataType:"json",
                    data: {"fileName": $("#txtBName").val()},
                    success: function(data){
                      unload();
                      if(data.state==1){
                          $.messager.show({title: '提示', msg: data.data});
                          $('#dataview').datagrid('reload');
                      }
                      else{
                         $.messager.alert('错误',data.data,'message');
                      }
                   }
                 });
         });
    }
    function saveEditFile(){
         $.messager.confirm('确认','确认保存编辑吗？',function(r){
                 if(!r){ return }
                 load("保存中...");
                 $.ajax({
                    type: "POST",
                    url:"backup.aspx?edit=1",
                    dataType:"json",
                    data: {"fileName": $("#editID").val(),"newName":$("#txtBName").val()}, 
                    success: function(data){
                      unload();
                      if(data.state==1){
                          $('#dataview').datagrid('reload');
                      }
                      else{
                         $.messager.alert('错误',data.data,'message');
                      }
                   }
                 });
         });
    }
    
    function Down(fileName){
        location.href= 'backup.aspx?down=1&filename='+encodeURI(fileName) ;
    }
    		
	function OperFormat(value,row,index){
	    return "<a href='#' onclick=\"deleteItem('"+value+"')\">删除</a>&nbsp;|&nbsp;<a href='javascript:void(0)' onclick=\"editFile('"+value+"')\">编辑</a>&nbsp;|&nbsp;<a href='#' onclick=\"Down('"+value+"')\">下载</a>&nbsp;|&nbsp;<a href='javascript:void(0)' onclick=\"restoreFile('"+value+"')\">还原</a>";
	}
																																	             
    function restoreFile(id){
        $.messager.confirm('确认','确定要还原数据库吗?',function(r){
             if(!r){ return }
             
             
             $.messager.confirm('确认','确定要还原数据库吗?',function(r){
             if(!r){ return }
             
                         load("还原中 请等待...");
                         $.ajax({
                            type: "POST",
                            url:"backup.aspx?restore=1",
                            dataType:"json",
                            data: {"fileName": id},
                            success: function(data){
                              unload();
                              if(data.state==1){
                                  $.messager.show({title: '提示', msg: data.data});
                              }
                              else{
                                 $.messager.alert('错误',data.data,'message');
                              }
                           }
                        });
            
              });
            
            
        });
    }
    
    function editFile(value){
         isEdit = true;
         $("#txtBName").val('');
         $("#dlg").dialog("open");
         $("#editID").val(value);
         $("#btnBackDatabase").val("保存编辑");
    }
      
   
    function deleteItem(key){
        $.messager.confirm('确认','确定要删除选中吗?',function(r){
             if(!r){ return }
             load("删除中...");
             $.ajax({
                type: "POST",
                url:"backup.aspx?remove=1",
                dataType:"json",
                data: {"fileName": key},
                success: function(data){
                  unload();
                 
                  $('#dataview').datagrid('reload').datagrid("unselectAll");
               
               }
            });
        });
    }
    
    
    

	   function editItem(key){

		    ShowDialog("edit","N25175_Student/N25175_Student_Edit.aspx?id="+key,600,400,100,100);
	   }
	   function deleteList(){
	         var row = $('#dataview').datagrid('getSelections');
	         if(row==null){
	             $.messager.alert('提示',"请选择删除项！",'message');
	             return;
	         }
	         $.messager.confirm('确认','确定要删除选中吗?',function(r){
	                 if(r){
	                     load("删除中...");
	                     var list = new Array();
	                     for(var index =0; index<row.length;index++){
	                        list.push(row[index].id);
	                     }
	                     $.ajax({
	                        type: "POST",
	                        url:"N25175_Student/N25175_Student_Delete.aspx",
	                        dataType:"json",
	                        data: {"deleteList": list.join(",")}, 
	                        success: function(data){
	                          unload();
	                          if(data.state==1){
	                              $.messager.show({ title: '提示', msg: "总共删除"+data.data+"条信息" });
	                              $('#dataview').datagrid('reload').datagrid("unselectAll");
	                          }else{
                                 $.messager.alert('错误',data.data,'message');
                              }
	                  
	                       }
	                    });
	                 }
	         });
       }

	   function Add(){
            isEdit = false;
            $("#txtBName").val('');
		 	$("#dlg").dialog("open");
		 	$("#btnBackDatabase").val("备份当前数据库");
	   }
       function reload(param){
            if(param=='last'){
                var grid = $('#dataview'); 
                var gridOptions = grid.datagrid("options"); 
                var options = grid.datagrid('getPager').data("pagination").options;  
                var pagenumber = options.total==0?1:Math.ceil( options.total/options.pageSize);
                gridOptions.pageNumber = pagenumber 
                options.pageNumber = pagenumber;
                $('#dataview').datagrid('reload');
            }
            $('#dataview').datagrid('reload');
       }
       function query(){
	        var query = $("#txtQuery").val();
	        $("#dataview").datagrid("load",{
	             query: query
	        });
   	   }
   	   
   	   function uploadFile(){
   	         ShowDialog("edit","restoreDatabase.aspx",600,250,100,100);
   	   }
   	   
    </script>

</head>
<body class="easyui-layout">
    <div region="center" border="false">
        <table id="dataview">
            <thead>
                <tr>
                    <th field="ck" checkbox="true"></th>
                    <th field="id" width="145" formatter='OperFormat'>操作</th>
                    <th field="f_name" width="450">备份文件名称</th>
                    <th field="f_size" width="100">文件大小</th>
                    <th field="f_date" width="150">创建日期</th>
                </tr>
            </thead>
        </table>
    </div>
    <div id="toolbar" style="height:60px">
    
        <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="Add()"> 备份当前数据库</a> 
        
        <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="uploadFile()"> 上传本地备份文件</a> 
        

        <span style="color:red">注：点击“备份当前数据库”按数据库大小备份的时间可能有长短</span>&nbsp;<br />
        
        &nbsp;&nbsp;备份的文件名称 ：
        <input id="txtQuery" name="name" type="text" maxlength="100" onkeydown="if(event.keyCode==13)query()" style="width: 350px" />

        <a href="#" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="query()">查询 </a>

        <a href="#" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="$('#dataview').datagrid('load',{})">显示所有 </a>
        
    </div>
    
    <div id="dlg"  title="输入当前备份文件名称"  style="width:560px;height:127px;" >  
        <table>
            <tr>
                <td style="width: 123px">
                </td>
                <td style="width: 273px">
                    默认文件名称当前日期</td>
                <td style="width: 139px">
                </td>
            </tr>
            <tr>
                <td style="width: 123px" align="right">
                    文件名称：</td>
                <td style="width: 273px">
                    <input id="txtBName" style="width: 265px" type="text" maxlength="100" /></td>
                <td style="width: 139px">
                    <input id="btnBackDatabase" type="button" value="备份数据库" /></td>
            </tr>
        </table>
        <input id="editID" type="hidden" /></div>
    
    
</body>
</html>
