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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	酒店客房控制系统
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="easyui-layout" data-options="fit:true" id="cc">

		<div region="north" border="false" class="l-topmenu">
			
			<div class="l-topmenu-logo">
				<img src="/images/logo.png" alt="酒店客房控制系统" height="24px" style="margin:16px 10px;" />
			</div>

			<div class="l-topmenu-welcome">
				<span class="space" style="font-weight: bold; color: rgb(42,100,166);">
					<%= ((dynamic)ViewData["Account"]) %></span>| <span class="space" onclick="$('#divChangePassword').window('open');">
						修改密码</span>| <span id='logOut' class="space">注销</span>| <span class="space" onclick="window.location.href='/Home/MenuMain/'">
							首页</span>| <span class="space" onclick="about();">关于</span>
				<br />
				<div id="divAlarm" style="margin-right: 6px;"></div>
			</div>
		</div>

		<div region="west" split="true" title="功能模块" collapsed="true" style="width: 180px;">
			<div class="easyui-accordion" fit="true" border="false" style="background-color: #E0ECFF;
				background-repeat: repeat-x;">
				<ul id="menuTree" data-options="animate:true"></ul>
			</div>
		</div>

		<div region="south" border="false" style="height: 20px; line-height: 20px; font-weight:bold;
			background-image: url(/Images/bg_bottom.gif);">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td style="text-align:center;">COPYRIGHT &copy; 2014-2015 ALL RIGHT RESERVED</td>
					<td id="tdDate" style="width:186px; text-align:right;"></td>
				</tr>
			</table>    
		</div>

		<div region="center" data-options="border:true">
			<div id="tab" class="easyui-tabs" fit="true" border="false">
				<iframe id="home" name="home" style="width: 100%; height: 100%; border: none;" scrolling="auto" frameborder="none"></iframe>
			</div>
		</div>

		<div id="divChangePassword" class="easyui-window" title="修改密码" style="width: 400px;
			height: 200px; padding: 5px;" closed="true" modal="true" collapsible="false"
			minimizable="false" maximizable="false">
			<div class="easyui-layout" fit="true">
				<div data-options="region:'center'">
					<table style="margin: 20px 60px;">
						<tr>
							<td>
								旧密码：
							</td>
							<td>
								<input type="password" id="iptOldPassword" />
							</td>
						</tr>
						<tr>
							<td>
								新密码：
							</td>
							<td>
								<input type="password" id="iptPassword" />
							</td>
						</tr>
						<tr>
							<td>
								确认密码：
							</td>
							<td>
								<input type="password" id="iptNewPassword" />
							</td>
						</tr>
					</table>
				</div>
				<div data-options="region:'south',border:false" style="text-align: right; margin: 5px 0 0;">
					<a class="easyui-linkbutton" iconcls="icon-ok" href="javascript:void(0)" onclick="changePassword()">
						确定</a> <a class="easyui-linkbutton" iconcls="icon-cancel" href="javascript:void(0)"
							onclick="$('#divChangePassword').window('close');">取消</a>
				</div>
			</div>
		</div>
    
		<div id="divAbout" class="easyui-window" title="关于" closed="true" modal="true" collapsible="false" minimizable="false" maximizable="false"
			style="width:400px;height:230px;">
			<table>
				<tr>
					<th colspan="2" style="text-align:center;height:40px;font-size:14px;">酒店客房控制系统</th>
				</tr>
				<tr>
					<th>软件版本：</th>
					<td><span class="Version"></span></td>
				</tr>
				<tr>
					<th>产品序号：</th>
					<td><span class="SerialNumber"></span></td>
				</tr>
				<tr>
					<th>授权数量：</th>
					<td><span class="Limit"></span></td>
				</tr>
				<tr>
					<th>使用时限：</th>
					<td><span class="Expires"></span></td>
				</tr>
				<tr>
					<th>主机授权：</th>
					<td>
						<input id="txtAuthorizationPassword" type="password" class="easyui-validatebox textbox text" style="width:100px;" />
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="accreditOk()">确定</a>
					</td>
				</tr>
			</table>
		</div>

		<div id="divAlarm2" class="easyui-window" title="服务提醒" style="width: 400px; height: 500px;" 
			data-options="
				closed: true,
				modal: true,
				collapsible: false,
				minimizable: false,
				maximizable: false,
				tools: [
					{ iconCls: 'icon-reload', handler: function(){ $('#dgAlarm').datagrid('reload'); } }
				]
			">
			<table id="dgAlarm" style="width:300px"></table>
		</div>
		<div id="dialog2" class="easyui-window"
			data-options="
				closed: true,
				modal: true,
				collapsible: false,
				minimizable: false,
				maximizable: false
			">
			<div class="easyui-panel dlg-content"></div>
		</div>
	</div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <style type="text/css">
        .space
        {
            padding: 5px;
            cursor: pointer;
        }
        .l-topmenu
        {
            margin: 0;
            padding: 0;
            height: 60px;
            line-height: 30px;
            position: relative;
            border-top: 1px solid #1D438B;
            background-color: #E0ECFF;
            overflow:hidden;
        }
        
        .l-topmenu-logo {
            font-size: 30px;
            width:500px;
            height: 59px;
            line-height: 59px;
        }
        .l-topmenu-welcome
        {
            top: 2px;
            right: 1px;
            position: absolute;
            height: 28px;
            line-height: 28px;
            text-align: right;
        }
        
        #divAbout table {
			margin:15px auto 0  auto;
        }
    </style>
    <script type="text/javascript" language="javascript">

        function groupFormatter(value, rows) {
            return value + "(" + rows.length + ")";
        }

        function operationFormatter(val, row) {
            if (row.Name != "SOS" &&
				row.Name != "客人在房门开" &&
				row.Name != "无人房门开" &&
				row.Name != "非客人在房门关") {

                var btn = "<a href='javascript:void(0)' onclick=clearMsg(" + row.ID + ",'" + row.RoomNumber + "','" + row.Name + "')>清除</a>";
                return btn;
            }

            return "";
        }

        function openCurrentMsg() {
            if (!$('#divAlarm2').is(":visible")) {

                $('#dgAlarm').propertygrid({
                    url: "/RoomService/LoadCurrentRoomServices/",
                    border: false,
                    fit: true,
                    method: 'post',
                    showGroup: true,
                    scrollbarSize: 0,
                    groupField: 'Name',
                    groupFormatter: groupFormatter,
                    columns: [[
						{ field: 'RoomNumber', title: '房号', width: 100, align: 'center', sortable: true },
						{ field: 'Time', title: '时间', width: 100, align: 'center', sortable: true, formatter: $.tools.formatDateTime },
						{ field: 'Operation', title: '操作', width: 100, align: 'center', sortable: true, formatter: operationFormatter }
					]]
                });

                $('#divAlarm2').window('open');
            }
        }

        //获取当前服务信息
        function loadCurrentMsg() {
            $.tools.post(null, "/RoomService/LoadCurrentMsg/", function (r) {
                if (r.IsSuccess) {
                    var html = "";
                    for (var i = 0; i < r.Data.length; i++) {
                        html += "<span class='space' onclick='openCurrentMsg();' title='点击查看详情'>" + r.Data[i].Name + "<font style='font-weight: bold;color: red;'>(" + r.Data[i].Count + ")</font></span>";
                        if (r.Data[i].Name == "SOS" &&
							r.Data[i].Count > 0) {
                            openCurrentMsg();
                        }
                    }
                    $("#divAlarm").html(html);
                }
            }, this, true);
        }

        function clearMsg(id, roomNumber, name) {
            var param = { id: id, roomNumber: roomNumber, name: name };
            $.tools.confrimPost("确认清除当前服务提醒吗？", param, "/RoomService/ClearRoomService/", function (r) {
                if (r.IsSuccess) {
                    $('#dgAlarm').datagrid("reload");
                }
            }, this);
        }

        //初始化
        $(function () {

            //装载日期时间
            setInterval(function () {
                today = new Date();
                $("#tdDate").html("今天：" + today.format("yyyy-MM-dd hh:mm:ss&nbsp;"));
            }, 1000);

            $('#menuTree').tree({
                url: "/Home/LoadMenu",
                attributes: ['text', 'url'],
                onSelect: function (node) {
                    node.url && $('#home').attr('src', node.url);
                }
            });
            //注销
            $("#logOut").click(function () {
                $.messager.confirm("提示", '确认注销登录吗？', function (r) {
                    if (r) window.location.href = '/Home/LogOut/';
                });
            });

            $("#home").attr("src", "/RoomStatus/Index/");

            loadCurrentMsg();
            setInterval(loadCurrentMsg, 5000);

            var myurl = GetQueryString("url");

            var Returnurl = GetQueryString();
            if (Returnurl != null && Returnurl.toString().length > 1) {
                //$('#cc').layout('collapse', 'west');
                $('#home').attr('src', Returnurl);
            }
        });

        //修改密码
        function changePassword() {
            var oldPassword = $("#iptOldPassword").val();
            if (oldPassword == "") {
                $("#iptOldPassword").focus();
                $.tools.alert('请输入旧密码！');
                return;
            }
            var password = $("#iptPassword").val();
            if (password == "") {
                $("#iptPassword").focus();
                $.tools.alert('请输入新密码！');
                return;
            }
            var newPassword = $("#iptNewPassword").val();
            if (newPassword == "") {
                $("#iptNewPassword").focus();
                $.tools.alert('请输入确认密码！');
                return;
            }
            if (newPassword != password) {
                $("#iptNewPassword").focus();
                $.tools.alert('两次密码不一致，请重新输入！');
                return;
            }
            var parm = { password: password, oldPassword: oldPassword };
            $.tools.post(parm, "/Home/ChangedPassword/", function () {
                $("#iptOldPassword").val("");
                $("#iptPassword").val("");
                $("#iptNewPassword").val("");
                $('#divChangePassword').window('close');
            }, this);
        }

        function about() {
            $.tools.post(null, "/Home/ProductInfo/", function (r) {

                $("#divAbout .Version").html(r.Data.Version);
                $("#divAbout .SerialNumber").html(r.Data.SerialNumber);
                $("#divAbout .Limit").html(r.Data.Limit);
                $("#divAbout .Expires").html(r.Data.Expires);

                $('#divAbout').window('open');
            }, this, true);

        }

        function GetQueryString() {
            var reg = new RegExp("(^|&)" + "url" + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        function accreditOk() {
            $('#dialog2')
				.find('.dlg-content').css({ height: '500px' })
				.panel({ border: false, fit: true, href: '/Host/HostAuthorization/', queryParams: { password: $('#txtAuthorizationPassword').val()} }).end()
				.dialog({ title: '主机授权', width: 600, height: 400 })
				.dialog('open');
            $('#divAbout').window('close').find('input[type=password]').val('');
        }
    </script>
</asp:Content>