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


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script language="javascript" src="../jscript/jquery.tool.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.1/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.1/themes/icon.css" />
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
     <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.1/demo/demo.css" />
    <link href="../css/framedialog_twocol.css" type="text/css" rel="stylesheet" />
    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />
      <script src="../jscript/jquery-datagird-extended.js" type="text/javascript"></script>
    <script type="text/javascript" src="../jscript/Cache.js"></script>
     <script src="../jscript/DateFormat.js" type="text/javascript"></script>
</head>
<body style="padding: 0px">
    <form id="FrmForm" runat="server">
        <input type="hidden" id="SelAll" name="SelAll" runat="server"/>
         <input type="hidden" id="SelRoomID" name="SelRoomID"  value="" runat="server"/>
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 600px; height: 150px;">
            <table style="width: 100%; padding-top: 5px">
                <tr>
                    <td class="TdTitle">楼宇
                    </td>
                    <td class="TdContent" colspan="3">
                       <input type="text" class="easyui-validatebox" id="BuildName" name="BuildName"
                            runat="server" />
                    </td>
                   
                </tr>
                <tr>
                    <td align="center" colspan="4">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="LoadData(1,100);">确定筛选</a>
                    </td>
                </tr>
            </table>
        </div>
        <div style="width: 100%;" id="TableContainer">
        </div>

        <script src="../jscript/CloseAjaxCache.js" type="text/javascript"></script>
        <script type="text/javascript">
                var h = $(window).height();
            var w = $(window).width();
            function InitTableHeight() {
                $("#TableContainer").css("height", h + "px");
            }
            InitTableHeight();


            var Column;
            Column = [[
                     { field: 'id', title: '选择', align: 'left', checkbox: true },
                    {
                        field: 'text', title: '楼宇', width: 300, align: 'left', sortable: false, formatter: function (value, row, rowIndex)
                        {
                            var val = "";
                            try {
                                
                                    val = row.text;
                               
                            }
                            catch (e)
                            { val=''}
                            return val;
                        }
                    }
            ]];

            var toolbar = [

                 {
                     text: '确定选择',
                     iconCls: 'icon-save',
                     handler: function () {
                         
                         var row = $("#TableContainer").treegrid("getChecked");//getSelections
                         var value = JSON.stringify(row);

                         if (value == "" || value =="[]") {
                             HDialog.Info('请选择');
                         }
                         else {
                             HDialog.Close(value);
                         }
                     }
                 }, '-',
                 {
                     text: '筛选',
                     iconCls: 'icon-search',
                     handler: function () {
                         $('#SearchDlg').parent().appendTo($("form:first"));
                         $('#SearchDlg').dialog('open');
                     }
                 }

            ];
          

            function LoadData(page, rows) {
                var BuildName = $('#BuildName').val();
               

                $.tool.DataPost('Building', 'BuildingTreeGrid', "page=" + page + "&rows=" + rows + "&BuildName=" + BuildName + "&" + $("#frmForm").serialize(),
                function Init() {
                },
                function callback(_Data) {
                    var Data;
                    try
                    {
                        Data = eval("(" + _Data + ")"); //转换为json对象
                        LoadList(Data, rows);
                    }
                    catch(e)
                    {
                        LoadList(_Data, rows);
                    }
                },
                function completeCallback() {
                },
                function errorCallback() {
                });


            }

            function LoadList(Data,rows) {
             

                $("#TableContainer").treegrid({
                    method: "get",
                    data:Data,
                    title: '',
                    loadMsg: '加载中,请稍侯',
                    treeField: 'text',
                    idField: 'id',
                    nowrap: false,
                    singleSelect: false,
                    selectOnCheck: false,
                    checkOnSelect: false,
                    nowrap: false,
                    pageSize: rows,
                    cascadeCheck: true,
                    pageList: [100, 200,500, 1000],
                    columns: Column,
                    fitColumns: true,
                    remoteSort: false,
                    pagination: true,
                    width: "100%",
                    toolbar: toolbar,
                    sortOrder: "asc",
                    rownumbers: true,
                    border: false,
                    toolbar: toolbar,
                    sortOrder: "asc",                   
                    onLoadSuccess: function (data) {
                        var pg = $("#TableContainer").treegrid("getPager");
                        if (pg) {
                            $(pg).pagination({
                                onBeforeRefresh: function () {

                                },
                                onRefresh: function (pageNumber, pageSize) {

                                },
                                onChangePageSize: function () {
                                },
                                onSelectPage: function (Pn, Ps) {

                                    LoadData(Pn, Ps);
                                   
                                    $('#TableContainer').treegrid('options').pageNumber = Pn;
                                    $('#TableContainer').treegrid('options').pageSize = Ps;
                                }
                            });
                        }

                        $("#SearchDlg").dialog("close");
                    },
                    cascadeCheck: true,
                    onCheck: function (node, checked) {

                        var childNode = $("#TableContainer").treegrid('getChildren', node.id);

                        if (childNode.length > 0) {
                            for (var i = 0; i < childNode.length; i++) {
                                $("input[value='" + childNode[i].id + "']").prop("checked", true);
                                $("#TableContainer").treegrid("select", childNode[i].id);
                            }
                        }
                    },
                    onCheckAll: function (node, checked) {

                        var childNode = $("#TableContainer").treegrid('getChildren', node.id);

                        if (childNode.length > 0) {
                            for (var i = 0; i < childNode.length; i++) {
                                $("input[value='" + childNode[i].id + "']").prop("checked", true);
                                $("#TableContainer").treegrid("select", childNode[i].id);
                            }
                        }
                    },
                    onUncheck: function (node, checked) {
                        var childNode = $("#TableContainer").treegrid('getChildren', node.id);
                        if (childNode.length > 0) {
                            for (var i = 0; i < childNode.length; i++) {
                                $("input[value='" + childNode[i].id + "']").prop("checked", false);
                                $("#TableContainer").treegrid("unselect", childNode[i].id);
                            }
                        }
                    },
                    onUncheckAll: function (node, checked) {
                        var childNode = $("#TableContainer").treegrid('getChildren', node.id);
                        if (childNode.length > 0) {
                            for (var i = 0; i < childNode.length; i++) {
                                $("input[value='" + childNode[i].id + "']").prop("checked", false);
                                $("#TableContainer").treegrid("unselect", childNode[i].id);
                            }
                        }
                    }
                    
                });
            }
            LoadData(1, 100);
        </script>
    </form>
</body>
</html>
