<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SimonMasterPage.Master"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%: Html.Language("LoopStateRecord")%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'north',border:false">
            <div class="toolbar" style="height: 65px;">
                <div>
                    <label><%: Html.Language("RoomNumber")%>：</label>
					<select id="cbxRoomNumber" class="easyui-combobox" style="width:70px;" 
						data-options="
							valueField: 'Value',
							textField: 'Name',
							editable: false,
							url: '/Overview/LoadRoomNumbers/',
							onSelect: cbxRoomNumberOnSelect
						">
					</select>
                    <label>
                        <%: Html.Language("StartDate")%>：</label>
                    <input id="txtStartTime" type="text" class="easyui-datetimebox" style="width: 130px;"
                        data-options="showSeconds:false" />
                    <label>
                        <%: Html.Language("Deadline")%>：</label>
                    <input id="txtEndTime" type="text" class="easyui-datetimebox" style="width: 130px;"
                        data-options="showSeconds:false" />
                    <a href="javascript:void(0)" class="toolbar-button tb-icon-search" onclick="query();">
                        <%: Html.Language("Query")%>
					</a>
                </div>
                <div>
                    <label>
                        <%: Html.Language("LoopType")%>：</label>
                    <select id="cbxDeviceType" class="easyui-combobox" style="width: 80px;" data-options="
                        panelWidth: 100,
						panelHeight: 'auto',
                        valueField: 'Value',
                        textField: 'Name',
						editable: false,
                        url: '/RoomType/LoadDeviceTypes/',
						onSelect: cbxDeviceTypeOnSelect
                    ">
                    </select>
                    <label>
                        <%: Html.Language("Circuit")%>：</label>
                    <select id="cbdRoomTypeModals" class="easyui-combogrid" style="width: 100px;" data-options="
						panelWidth: 270,
						multiple: true,
                        idField: 'ModalAddress',
                        textField: 'Outlet',
						editable: false,
						fitColumns: true,
                        columns:[[
							{ field: 'ck',checkbox: true },
							{ field: 'RoomType', title: '<%: Html.Language("RoomType")%>' },
							{ field: 'ModalAddress', title: '<%: Html.Language("ReturnAddress")%>' },
							{ field: 'Outlet', title: '<%: Html.Language("DeliveryOutlet")%>' },
                            { field: 'Name', title: '<%: Html.Language("LoopName")%>' }
                        ]]
                    ">
                    </select>
                </div>
            </div>
        </div>
        <div data-options="region:'center',border:false">
            <table id="dg" class="easyui-datagrid" style="width: 100%; height: auto;" 
					data-options="
						border: false,
						singleSelect: true,
						pagination: false,
						pageSize: 50,
						rownumbers: true,
						striped: true,
						sortName: 'RoomNumber',
						sortOrder: 'asc',
						fit: true,
						fitColumns: true,
						method: 'POST'
					">
                <thead>
                    <tr>
                        <th data-options="field:'RoomNumber',sortable:true,resizable:false">
                            <%: Html.Language("RoomNumber")%>
                        </th>
                        <th data-options="field:'ModalAddress',sortable:true,resizable:false">
                            <%: Html.Language("ReturnAddress")%>
                        </th>
                        <th data-options="field:'Name',sortable:true,resizable:false">
                            <%: Html.Language("Name")%>
                        </th>
                        <th data-options="field:'Type',sortable:true,resizable:false,formatter:formatType">
                            <%: Html.Language("Type")%>
                        </th>
                        <th data-options="field:'Value',sortable:true,resizable:false">
                            <%: Html.Language("Value")%>
                        </th>
                        <th data-options="field:'Date',sortable:true,resizable:false">
                            <%: Html.Language("Date")%>
                        </th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        function formatType(val) {
            switch (val) {
                case 1:
                    return "在线状态";
                case 2:
                    return "电量";
                case 3:
                    return "电流（10MA）";
                case 4:
                    return "1901故障检测次数";
            }
        }
        function query() {
            var roomNumber = $('#cbxRoomNumber').combobox('getValue');
            /*if (roomNumber == '') {
                $.tools.alert(lang.PleaseEnterRoomNumber);
                return;
            }*/
            var modalAddresses = $('#cbdRoomTypeModals').combogrid('getValues');
            var params = {
                RoomNumber: roomNumber,
                StartTime: $('#txtStartTime').datetimespinner('getValue'),
                EndTime: $('#txtEndTime').datetimespinner('getValue'),
                DeviceType: $('#cbxDeviceType').combobox('getValue'),
                ModalIds: modalAddresses.length > 0 ? "'" + modalAddresses.join("','") + "'" : ""
            };
            $('#dg').datagrid({ url: '/Overview/LoadHostFaultRecords/', queryParams: params });
        }
        function cbxDeviceTypeOnSelect(row) {
            var roomNumber = $('#cbxRoomNumber').combobox('getValue');
            if (roomNumber == '') {
                $.tools.alert(lang.PleaseEnterRoomNumber);
                return;
            }
            $('#cbdRoomTypeModals').combogrid({ url: '/RoomType/LoadRoomTypeModals', queryParams: { roomNumber: roomNumber, deviceType: row.Value} });
        }
        function cbxRoomNumberOnSelect(r) {
            //$('#cbdRoomTypeModals').combogrid({ url: '/HostModalRecord/LoadModals', queryParams: { roomNumber: r.Value} });
            $('#cbdRoomTypeModals').combogrid({ url: '/RoomType/LoadRoomTypeModals', queryParams: { roomNumber: r.Value, deviceType: $('#cbxDeviceType').combobox('getValue')} });
        }
        $(function () {
            var curTime = new Date();
            var startTime = new Date(curTime.getTime() - 1 * 24 * 60 * 60 * 1000);
            $("#txtStartTime").datetimebox("setValue", startTime.format('yyyy-MM-dd hh:mm:ss'));
            $("#txtEndTime").datetimebox("setValue", curTime.format('yyyy-MM-dd hh:mm:ss'));
        });
    </script>
</asp:Content>
