<%@ 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("AirConditioningRecord")%>
</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>
					<%--<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("AirConditionerSerialNumber")%>：</label>
					<select id="cbxAirNo" class="easyui-combobox" style="width:80px;" data-options="
							panelHeight: 'auto',
							valueField: 'Value',
							textField: 'Name',
							editable: false,
							url: '/AirConditionStatus/LoadAirNos/',
                            onLoadSuccess: function() {
                                var data = $('#cbxAirNo').combobox('getData');
                                $('#cbxAirNo').combobox('select',data[0].Value);
                            },
						">
					</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>
					<input type="radio" name="type" value="AirCircuit" checked="checked" onchange="typeOnChanged('AirCircuit')" />
					<label><%: Html.Language("AirConditioningCircuit")%>：</label>
					<select id="cbxAirCircuit" class="easyui-combogrid" style="width:130px;" 
						data-options="
							url: '/AirConditionStatus/LoadACDeviceSubtypes/',
							multiple: true,
							panelHeight: 'auto',
							idField: 'Value',
							valueField: 'Value',
							textField: 'Name',
							editable: false,
							columns:[[
								{ field: 'ck',checkbox: true },
								{ field: 'Name', title: '<%: Html.Language("AirConditioningCircuit")%>' }
							]]
						">
					</select>				
					<input type="radio" name="type" value="RoomTemp" onchange="typeOnChanged('RoomTemp')" />
					<label><%: Html.Language("RoomTemp")%>：</label>
					<select id="cbxRoomTemp" class="easyui-combogrid" style="width:130px;" disabled="disabled"
						data-options="
							url: '/AirConditionStatus/LoadTempTypes/',
							multiple: true,
							panelHeight: 'auto',
							idField: 'Value',
							valueField: 'Value',
							textField: 'Name',
							editable: false,
							columns:[[
								{ field: 'ck',checkbox: true },
								{ field: 'Name', title: '<%: Html.Language("RoomTemp")%>' }
							]]
						">
					</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: true,
						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:'SubtypeName',sortable:true,resizable:false">
							<%: Html.Language("AirConditioningFan")%>
						</th>
						<th data-options="field:'TempType',sortable:true,resizable:false,hidden:true,formatter:tempTypeFormatter">
							<%: Html.Language("RoomTemp")%>
						</th>
						<th data-options="field:'Temp',sortable:true,resizable:false,hidden:true,formatter:function(val){return val+'℃';}">
							<%: Html.Language("TemperatureValues")%>
						</th>
						<th data-options="field:'StartTime',sortable:true,resizable:false">
							<%: Html.Language("StartDate")%>
						</th>
						<th data-options="field:'EndTime',sortable:true,resizable:false">
							<%: Html.Language("Deadline")%>
						</th>
						<th data-options="field:'Time',sortable:true,resizable:false,formatter:timeFormatter">
							<%: Html.Language("Time")%>
						</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
	<script type="text/javascript">
		function tempTypeFormatter(val) {
			if (val == <%: (int)Domain.TempType.RoomTemp %>) { 
				return '<%: Html.Language(Domain.TempType.RoomTemp.ToString()) %>';
			} else if (val == <%: (int)Domain.TempType.SettingTemp %>) { 
				return '<%: Html.Language(Domain.TempType.SettingTemp.ToString()) %>';
			}
		}
		function timeFormatter(val) {
			var hour = Math.floor(val / 60);
			var minute = Math.ceil(val % 60);
			return hour + lang.Hour + minute + lang.Minute;
		}
		function typeOnChanged(type) {
			if (type === 'AirCircuit') {
				$('#cbxAirCircuit').combobox('enable');
				$('#cbxRoomTemp').combobox('disable');
				$('#dg').datagrid('loadData', { total: 0, rows: [] });
				$('#dg').datagrid('showColumn', 'SubtypeName');
				$('#dg').datagrid('hideColumn', 'TempType');
				$('#dg').datagrid('hideColumn', 'Temp');
			} else if(type === 'RoomTemp') {
				$('#cbxAirCircuit').combobox('disable');
				$('#cbxRoomTemp').combobox('enable');
				$('#dg').datagrid('loadData', { total: 0, rows: [] });
				$('#dg').datagrid('hideColumn', 'SubtypeName');
				$('#dg').datagrid('showColumn', 'TempType');
				$('#dg').datagrid('showColumn', 'Temp');
			}
		}
		function query() {

			var params = {
				RoomNumber: $('#txtRoomNumber').val(),
				AirNo: $('#cbxAirNo').combobox('getValue'),
				StartTime: $('#txtStartTime').datetimespinner('getValue'),
				EndTime: $('#txtEndTime').datetimespinner('getValue'),
				AirRecordType: $('input:radio[name="type"]:checked').val(),
				DeviceSubtypes: $('#cbxAirCircuit').combogrid('getValues').join(','),
				TempTypes:  $('#cbxRoomTemp').combobox('getValues').join(',')
			};

			if(params.RoomNumber == '') {
				$.tools.alert(lang.PleaseEnterRoomNumber);
				return;
			}

			if(params.AirNo == '') {
				$.tools.alert(lang.PleaseSelectAirNo);
				return;
			}

			$('#dg').datagrid({ url: '/AirConditionStatus/LoadHostAirRecords/', 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>
