<%@ page language="C#" masterpagefile="~/MasterPage/UserMasterPage.master" autoeventwireup="true" inherits="Rest_System_RevertDatabase, DoodiiShop" title="Untitled Page" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript" src="/js/jquery.js"></script>
    <table class="NewTable">
        <tr>
            <th>
                选择</th>
            <th>
                文件名称</th>
            <th>
                创建日期</th>
            <th>
                操作</th>
        </tr>
        <%if (ds.Tables[0].Rows.Count == 0)
          {
        %>
        <tr style="height: 30px">
            <td colspan="4">
                暂无数据</td>
        </tr>
        <%    
            }
            else
            {
                int i = 0;
                foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                {
                      
        %>
        <tr style="height: 30px" onmouseout="this.style.backgroundColor=''; " onmouseover="this.style.backgroundColor='#e0F3F3';">
            <td align="center">
                <input type="radio" name="filePath"  value="<%=dr["filePath"].ToString().Replace(@"\","-") %>" <%= i==0?"checked=\"checked\"":""%>/>
            </td>
            <td align="center">
                <%=dr["fileName"].ToString() %>
            </td>
            <td align="center">
                <%=dr["fileDate"].ToString() %>
            </td>
            <td align="center">
            <a href="javascript:deletefile('<%=dr["filePath"].ToString().Replace(@"\","-") %>')">删除</a>
            </td>
        </tr>
        <%          i++;
                }
          }
           %>
    </table>
    <input type="button" id="btnRevert" value="恢复" style="margin:5px 0 0 0;"  onclick="Revertfile()"/><br />
    <span id="lberror" style="color:Red;margin-top:10px; display:block; width:100%; text-align:center;"></span>
    <script type="text/javascript">
    function deletefile(filePath)
    { 
        if(confirm("你确定要删除吗"))
        {
            $.ajax({
                type:"get",
                dataType:"html",
                cache:false,
                async:true,
                url:"/Rest/System/Ajax/AjaxDataBase.aspx",
                data:"cmd=Deletefile&filePath="+escape(filePath), 
                success:function(e){ 
                        if(e=="1")
                        {
                            filename=filePath.substring(filePath.lastIndexOf("-")+1)
                            alert(filename+"删除成功！");
                            location.reload();
                        }
                        else
                            alert(e);
                    },
                error:function(e){ 
                        alert(e)
                    }
            });
        }
    }
    
    function Revertfile()
    {
        var filePath="";
        $("input[name='filePath']:checked").each(function(i) { 
                filePath=$(this).val();   
        });
        if(filePath=="")
        {
            alert("请选择你要恢复的文件！");
            return;
        }
        if(!confirm("你确定要恢复选定备份文件吗？"))
            return;
        $("#btnRevert").attr("disabled","disabled");
        $.ajax({
            type:"get",
            dataType:"html",
            cache:false,
            async:true,
            url:"/Rest/System/Ajax/AjaxDataBase.aspx",
            data:"cmd=Revertfile&filePath="+escape(filePath), 
            success:function(e){ 
                    if(e=="1")
                     {   
                        $("#lberror").html("恢复成功！");                        
                     }
                    else
                         $("#lberror").html(e);
                    $("#btnRevert").attr("disabled","");
                },
            error:function(e){ 
                    alert(e)
                }
        });
    }
    </script>
</asp:Content>
