<%@ 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("ServiceQuery")%>
</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" style="overflow: hidden; height: 30px;">
            <div class="toolbar">
                <%--<a href="javascript:void(0)" class="toolbar-button tb-icon-refresh" onclick="$('#dg').datagrid('reload')">
                    <%: Html.Language("Refresh") %></a>--%>
                <label>
                    <%: Html.Language("RoomNumber")%>：</label>
                <input id="txtRoomNumber" class="easyui-validatebox" style="width: 60px;" />
                <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" />
                <label>
                    <%: Html.Language("ServiceType")%>：</label>
                <select id="cbxServiceType" class="easyui-combogrid" style="width: 100px;" data-options="
                        panelWidth: 260,
						multiple: true,
                        idField: 'Code',
                        textField: 'Name',
						editable: false,
						fitColumns: true,
                        url: '/AlarmSetting/LoadServicesAndAbnormities/',
                        columns:[[
							{ field: 'ck',checkbox: true },
                            { field: 'Name', title: '<%: Html.Language("ServiceName")%>', width: 100 }
                        ]]    
                    ">
                </select>
                <a href="javascript:void(0)" class="toolbar-button tb-icon-search" onclick="query();">
                    <%: Html.Language("Query")%></a>
                <a href="/RoomService/ExportExcel/" class="toolbar-button tb-icon-export" target="_blank"><%: Html.Language("Export")%></a>
            </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: true,
						pageSize: 20,
						rownumbers: true,
						striped: true,
						sortName: 'ID',
						sortOrder: 'asc',
						fit: true,
						fitColumns: true,
						idField: 'ID',
						method: 'POST'
					">
                <thead>
                    <tr>
                        <th data-options="field:'RoomNumber',sortable:true,resizable:false">
                            <%: Html.Language("RoomNumber")%>
                        </th>
                        <th data-options="field:'Name',sortable:true,resizable:false">
                            <%: Html.Language("ServiceType")%>
                        </th>
                        <th data-options="field:'StartTime',sortable:true,resizable:false,formatter:$.tools.formatDateTime">
                            <%: Html.Language("StartDate")%>
                        </th>
                        <th data-options="field:'EndTime',resizable:false,formatter:$.tools.formatDateTime,sortable:true">
                            <%: Html.Language("Deadline")%>
                        </th>
                        <th data-options="field:'Time',sortable:true,resizable:false,formatter:timeFormatter">
                            <%: Html.Language("TotalTime")%>
                        </th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        function timeFormatter(val) {
            var hour = Math.floor(val / 60);
            var minute = Math.ceil(val % 60);
            return hour + lang.Hour + minute + lang.Minute;
        }

        function query() {

            var services = $('#cbxServiceType').combogrid('grid').datagrid('getChecked');
            if (services.length <= 0) {
                $.tools.alert(lang.PleaseSelectAtLeastOneService);
                return;
            }

            var codes = [];
            for (var i in services) {
                codes.push(services[i].Code);
            }

            var params = {
                RoomNumber: $('#txtRoomNumber').val(),
                StartTime: $('#txtStartTime').datetimespinner('getValue'),
                EndTime: $('#txtEndTime').datetimespinner('getValue'),
                AlarmCodes: codes.join(',')
            };

            $('#dg').datagrid({ url: '/RoomService/LoadServiceRecords/', queryParams: params });
        }
        $(function () {
            var curTime = new Date();
            var startTime = new Date(curTime.getTime() - 7 * 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>
