<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PointObjectExcel.aspx.cs" Inherits="M_Main.ComprehensivePatrols.PointObjectExcel" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>项目点位导入</title>
    <link href="../css/base.css" rel="stylesheet" />
    <link href="../css/button.css" rel="stylesheet" />

    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.4/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.4/themes/icon.css" />
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.extend.js"></script>

    <script src="../jscript/jquery.tool.new.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Jscript-Ui/JQForm/JQForm.js"></script>
    <script src="../jscript/DateFormat.js" type="text/javascript"></script>
    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <script src="../jscript/self-vilidate.js" type="text/javascript"></script>
    <script src="../jscript/PersonDictionaryCanNull.js" type="text/javascript"></script>
</head>
<body>
    <form id="frmForm">
        <div id="TableContainer"></div>

        <input type="hidden" id="CommID" name="CommID" runat="server" />
        <input type="hidden" id="FilePath" name="FilePath" />
        <input type="hidden" id="TableName" name="TableName" value="Sheet1$" />
        <input type="hidden" id="ReturnValue" name="ReturnValue" />
        <input type="file" id="UpFile" name="UpFile" style="display: none" />
        <script language="javascript" type="text/javascript">

            function InitTableHeight() {
                var h = $(window).height();
                $("#TableContainer").css("height", h + "px");
            }
            $(function () {
                InitTableHeight();
                LoadList();
            });
            var column = [[
                { field: '点位编号', title: '点位编号', width: 80, align: 'left', sortable: true },
                { field: '点位名称', title: '点位名称', width: 150, align: 'left', sortable: true },
                { field: '点位地址', title: '点位地址', width: 150, align: 'left', sortable: true },
                { field: '通用点位', title: '通用点位', width: 150, align: 'left', sortable: true },
                //{ field: '任务类型', title: '任务类型', width: 100, align: 'left', sortable: true },
                { field: '报事公区', title: '报事公区', width: 150, align: 'left', sortable: true },
                { field: '设备空间', title: '设备空间', width: 150, align: 'left', sortable: true },
                { field: '备注', title: '备注', width: 150, align: 'left', sortable: true }
            ]];
            var toolbar = [
                {
                    text: '下载模版',
                    iconCls: 'icon-page_white_excel',
                    handler: function () {
                        window.open("../ComprehensivePatrols/Template/TemplatePoint.xls");
                    }
                }, '-',
                {
                    text: '上传模版',
                    iconCls: 'icon-page_white_excel',
                    handler: function () {
                        $("#UpFile").click();
                    }
                }, '-',
                {
                    text: '确定导入',
                    iconCls: 'icon-save',
                    handler: function () {
                        if (!isValueNull($("#FilePath").val())) {
                            $.messager.alert('温馨提示', "请上传模版文件!");
                            return;
                        }
                        StartImport();
                    }
                }
            ];
            function Close() {
                HDialog.Close();
            }

            function StartImport() {
                $.tool.DataPost('CpComPatrols', 'SavePointObjectImport', $.JQForm.GetStrParam(),
                    function Init() {
                        $.messager.progress({ title: "温馨提示", msg: "正在导入数据..." });
                    },
                    function callback(data) {
                        if (data == "true") {
                            HDialog.Close();
                        }
                        else {
                            $.messager.alert('错误', data, 'error');
                        }
                        $.messager.progress('close');
                    },
                    function completeCallback() {
                    },
                    function errorCallback() {
                        $.messager.alert('温馨提示', "导入数据错误!", 'error');
                        $.messager.progress('close');
                    });
            }

            function LoadList() {
                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataPostControl.aspx',
                    method: "post",
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    idField: "1",
                    columns: column,
                    rownumbers: true,
                    fitColumns: false,
                    checkbox: true,
                    singleSelect: true,
                    border: false,
                    pagination: true,
                    width: "100%",
                    toolbar: toolbar,
                    sortOrder: "desc",
                    remoteSort: false,
                    onBeforeLoad: function (param) {
                        param = $.JQForm.GetParam("CpComPatrols", "BindImportPointTemplate", "TableContainer", param);
                    },
                    onLoadSuccess: function (data) {
                        if (data.total == 50) {
                            $.messager.show({
                                title: '温馨提示',
                                msg: '防止因展示数据过多导致浏览器奔溃,所以只展示Excel表格中前50条数据,不影响全部数据批量新增!',
                                timeout: 10000,
                                showType: 'slide'
                            });
                        }
                    },
                    onLoadError: function (data) {
                        if (isValueNull($("#FilePath").val()) && data.status == 200) {
                            $.messager.alert('温馨提示', data.responseText, "error");
                        }

                    }
                });
            }
            function UpLoadFile() {
                var fd = new FormData();
                fd.append("UpFile", $("#UpFile").get(0).files[0]);
                fd.append("IsCompleteAddr", "true");
                $.tool.pageLoading("正在上传模板文件");
                $.ajax({
                    url: "../AjaxUpload.aspx",
                    type: "POST",
                    processData: false,
                    contentType: false,
                    data: fd,
                    success: function (addr) {
                        if (addr != "") {
                            $("#FilePath").val(addr);
                            //绑定上传的列表
                            LoadList();
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('温馨提示', "上传模板失败", "error");
                    },
                    complete: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.tool.pageUnLoading();
                    }
                });

                var jqObj = $("#UpFile");
                jqObj.val("");
                var domObj = jqObj[0];
                domObj.outerHTML = domObj.outerHTML;
                var newJqObj = jqObj.clone();
                jqObj.before(newJqObj);
                jqObj.remove();
                $("#UpFile").unbind().change(function (e) {
                    UpLoadFile();
                });
            }
            $("#UpFile").change(function (e) {
                UpLoadFile();
            });
        </script>
    </form>
</body>
</html>

