<%@ Page Title="" Language="C#" MasterPageFile="~/whir_system/master/SystemMasterPage.master" AutoEventWireup="true" CodeFile="DataExprot.aspx.cs" Inherits="whir_system_module_developer_DataExprot" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
     <table width="100%" class='border' border="0" cellpadding="2" cellspacing="1">
        <tr align="center">
            <td class="spacingtitle" colspan="2">
                <asp:Label runat="server" Text="数据导出" ID="LblTitle"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="tdbgleft" style="text-align: right">
                <b>选择脚本:</b>
            </td>
            <td class="tdbg">
                <asp:Literal runat="server" ID="DropScript" ></asp:Literal>
            </td>
        </tr>
        <tr>
            <td class="tdbg" colspan="2" align="center">
                <asp:HiddenField runat="server" ID="HdnSql" />
                <asp:HiddenField runat="server" ID="HdnTitle" />
                <input type="button" value="预览数据" id="btnPreview" />
                <asp:Button ID="btnSave" runat="server" Text="导出Excel" 
                OnClientClick=" return confirm('若导出数据量较大时，需要较长时间，需耐心等待。\r\n确定现在就导出数据吗？') "
                            OnClick="btnSave_Click" />
            </td>
        </tr>
        <tr>
            <td class="tdbg" colspan="2" align="center">
                <div id="waitTips">
                </div>
                <div id="data" style="border: 0px solid gray; overflow: scroll; width: 1100px;">
                </div>
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        var _BasePath = "<%= AppName %>";
        //        $.ajaxSetup({
        //            async: false
        //        });
        $(function () {
            $("#btnPreview").click(function () {
                var sql = $('#scriptSelect option:selected').attr("sql");
                var title = $('#scriptSelect option:selected').text();
                document.getElementById("<%= HdnSql.ClientID %>").value = sql;
                document.getElementById("<%= HdnTitle.ClientID %>").value = title;
                if (sql.length > 0) {
                    $("#waitTips").html("<span style='color:red'>数据加载中，请稍后...</span>");
                    sql = encodeURI(sql);
                    $.post(_BasePath + 'ajax.aspx?HandlerName=AdminAjaxHandler', "<?xml version='1.0' encoding='utf-8'?><root><type>dataquery</type><sql>" + sql + "</sql></root>",
                        function (s) {
                            var status = $("status", s).text();
                            var msg = $("msg", s).text();
                            if (status == "ok") {
                                $("#data").html(msg);
                                $("#waitTips").html("<span style='color:green'>查询完毕！</span>");
                            } else {
                                whir.toastr.error(decodeURI(msg));
                            }
                        });
                } else {
                    whir.toastr.error("请选择数据库查询脚本！");
                    $("#data").html("");
                }
            });
        });
    </script>
</asp:Content>

