<%@ 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("FailureRegistration")%>
</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('load',{});">
                    <%: Html.Language("Refresh")%></a> <a href="javascript:void(0)" class="toolbar-button tb-icon-register"
                        onclick="add()">
                        <%: Html.Language("New")%></a> <a href="javascript:void(0)" class="toolbar-button tb-icon-edit"
                            onclick="edit()">
                            <%: Html.Language("Edit")%></a> <a href="javascript:void(0)" class="toolbar-button tb-icon-cancel"
                                onclick="cancel()">
                                <%: Html.Language("Logout")%></a> <a href="javascript:void(0)" class="toolbar-button tb-icon-remove"
                                    onclick="del()">
                                    <%: Html.Language("Delete")%></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,
						pagination: true,
						pageSize: 20,
						rownumbers: true,
						striped: true,
						sortName: 'Number',
						sortOrder: 'asc',
						fit: true,
						fitColumns: true,
						idField: 'ID',
						frozenColumns: [[ { field: 'ID', checkbox: true } ]],
						method: 'post',
						url: '/FaultRecords/LoadAllByPage/',
						onDblClickRow: function(index, row) { edit(row); }
					">
                <thead>
                    <tr>
                        <th data-options="field:'Status',sortable:true,resizable:false,formatter: function(value){ return value == 0 ? lang.NoMaintenance : lang.HaveMaintenance; }">
                            <%: Html.Language("MaintenanceState")%>
                        </th>
                        <th data-options="field:'IsCancel',sortable:true,resizable:false,formatter: function(value){ return value ? lang.HasBeenCancelled : ''; }">
                            <%: Html.Language("Logout")%>
                        </th>
                        <th data-options="field:'Number',sortable:true,resizable:false">
                            <%: Html.Language("ID")%>
                        </th>
                        <th data-options="field:'RoomNumber',sortable:true,resizable:false">
                            <%: Html.Language("RoomNumber")%>
                        </th>
                        <th data-options="field:'FaultTypeCode',sortable:true,resizable:false">
                            <%: Html.Language("FaultCode")%>
                        </th>
                        <th data-options="field:'FaultType',sortable:true,resizable:false">
                            <%: Html.Language("FaultName")%>
                        </th>
                        <th data-options="field:'FaultTime',sortable:true,resizable:false">
                            <%: Html.Language("FaultDate")%>
                        </th>
                        <th data-options="field:'Description',sortable:true,resizable:false">
                            <%: Html.Language("Remark")%>
                        </th>
                        <th data-options="field:'RepairPerson',sortable:true,resizable:false">
                            <%: Html.Language("MaintenanceMan")%>
                        </th>
                        <th data-options="field:'RepairTime',sortable:true,resizable:false">
                            <%: Html.Language("MaintenanceTime")%>
                        </th>
                        <th data-options="field:'RepairContent',sortable:true,resizable:false">
                            <%: Html.Language("MaintenanceContent")%>
                        </th>
                        <th data-options="field:'CancelPerson',sortable:true,resizable:false">
                            <%: Html.Language("CancellationPersonnel")%>
                        </th>
                        <th data-options="field:'CancelTime',sortable:true,resizable:false">
                            <%: Html.Language("CancellationTime")%>
                        </th>
                        <th data-options="field:'CancelReason',sortable:true,resizable:false">
                            <%: Html.Language("CancellationReason")%>
                        </th>
                        <th data-options="field:'RegisteredPerson',sortable:true,resizable:false">
                            <%: Html.Language("Registrant")%>
                        </th>
                        <th data-options="field:'RegisteredTime',sortable:true,resizable:false,formatter:$.tools.formatDateTime">
                            <%: Html.Language("FaultBookDate")%>
                        </th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
    <div id="faultRecordDlg" class="easyui-window"   title='<%: Html.Language("FailureRegistration")%>' style="width: 430px;
        height: 400px; padding: 5px;" closed="true" modal="true" collapsible="false"
        minimizable="false" maximizable="false">
        <div class="easyui-layout" fit="true">
            <div data-options="region:'center'">
                <form id="faultRecordForm" class="easyui-form" method="post" data-options="novalidate:true">
                <input name="ID" type="hidden" value="0" />
                <table style="margin: 20px auto;" cellpadding="3">
                    <tr>
                        <td class="align-right">
                            <%: Html.Language("ID")%>：
                        </td>
                        <td>
                            <input id="txtNumber" name="Number" class="easyui-validatebox textbox text" readonly="readonly"
                                data-options="required:true,validType:'length[1,20]'" />
                        </td>
                    </tr>
                    <tr>
                        <td class="align-right">
                             <%: Html.Language("FaultTime")%>：
                        </td>
                        <td>
                            <input id="txtFaultTime" name="FaultTime" class="easyui-datetimebox textbox text"
                                data-options="required:true,editable:false" />
                        </td>
                    </tr>
                    <tr>
                        <td class="align-right">
                             <%: Html.Language("RoomNumber")%>：
                        </td>
                        <td>
                            <input id="cbxRoomNumber" name="RoomNumber" class="easyui-combobox textbox text"
                                data-options="
									required:true,
									editable:false,
									panelHeight: 150,
									valueField: 'RoomNumber',
									textField: 'RoomNumber',
									url:'/Host/LoadDataForRoomNumberCombobox/'" />
                        </td>
                    </tr>
                    <tr>
                        <td class="align-right">
                             <%: Html.Language("FaultType")%>：
                        </td>
                        <td>
                            <input id="cbxFaultType" name="FaultTypeID" class="easyui-combobox textbox text"
                                data-options="
									required:true,
									editable:false,
									panelHeight: 'auto',
									valueField: 'ID',
									textField: 'Code',
									formatter: function(row) { return row.Code + '（'+ row.Name + '）'; },
									url:'/FaultType/LoadAllForCombobox/'
									" />
                        </td>
                    </tr>
                    <tr>
                        <td class="align-right">
                            <%: Html.Language("FaultInstructions")%>：
                        </td>
                        <td>
                            <textarea id="txtDescription" name="Description" class="easyui-validatebox textbox text"
                                data-options="validType:length[0,200]" cols="30" rows="5"></textarea>
                        </td>
                    </tr>
                </table>
                </form>
            </div>
            <div data-options="region:'south',border:false" style="text-align: right; padding: 5px 0 0;">
                <a class="easyui-linkbutton" data-options="iconCls:'icon-save'" href="javascript:void(0)"
                    onclick="save();">
                    <%: Html.Language("Save")%></a> <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                        href="javascript:void(0)" onclick="$('#faultRecordDlg').window('close');">
                        <%: Html.Language("Cancel")%></a>
            </div>
        </div>
    </div>
    <div id="cancelFaultDlg" class="easyui-window"   title='<%: Html.Language("FaultCanceled") %>' style="width: 450px;
        height: 270px; padding: 5px;" closed="true" modal="true" collapsible="false"
        minimizable="false" maximizable="false">
        <div class="easyui-layout" fit="true">
            <div data-options="region:'center'">
                <form id="cancelFaultForm" class="easyui-form" method="post" data-options="novalidate:true">
                <input name="ID" type="hidden" value="0" />
                <table style="margin: 20px auto;" cellpadding="3">
                    <tr>
                        <td class="align-right">
                            <%: Html.Language("CancellationTime")%>：
                        </td>
                        <td>
                            <input id="txtCancelTime" name="CancelTime" class="easyui-datetimebox textbox text"
                                data-options="required:true" />
                        </td>
                    </tr>
                    <tr>
                        <td class="align-right">
                            <%: Html.Language("CancellationReason")%>：
                        </td>
                        <td>
                            <textarea id="txtCancelReason" name="CancelReason" class="easyui-validatebox textbox text"
                                data-options="validType:length[0,200]" cols="30" rows="5"></textarea>
                        </td>
                    </tr>
                </table>
                </form>
            </div>
            <div data-options="region:'south',border:false" style="text-align: right; padding: 5px 0 0;">
                <a class="easyui-linkbutton" data-options="iconCls:'icon-save'" href="javascript:void(0)"
                    onclick="cancelFault();">
                    <%: Html.Language("Save")%></a> <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                        href="javascript:void(0)" onclick="$('#cancelFaultDlg').window('close');">
                        <%: Html.Language("Cancel")%></a>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        function add() {
            $.tools.post(null, "/FaultRecords/GenerateFaultNumber/", function (r) {
                $("#faultRecordForm").form("reset").form("load", { ID: 0, Number: r.Data.Number });
                $("#faultRecordDlg").window("open");
            }, this, true);
        }
        function edit(row) {
            if (row == null) {
                row = $("#dg").datagrid("getSelected");
            }
            if (row) {
                $("#faultRecordForm").form("reset").form("load", row);
                $("#faultRecordDlg").window({ title: lang.EditTheNumbersFor + "【" + row.Number + "】" + lang.TheFailureOf }).window("open");
            } else {
                $.tools.alert(lang.PleaseSelectTheData);
            }
        }
        function cancel() {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $("#cancelFaultForm").form("reset").form("load", row);
                $("#cancelFaultDlg").window({ title: lang.TCNI+"【" + row.Number + "】" + lang.TheFailureOf }).window("open");
            } else {
                $.tools.alert(lang.PleaseSelectTheData);
            }
        }

        function del() {
            var rows = $('#dg').datagrid('getSelections');
            if (!rows || rows.length == 0) {
                $.tools.alert(lang.PleaseSelectTheData);
                return;
            }

            var param;
            $.each(rows, function (i, n) {
                if (i == 0) {
                    param = "idList=" + n.ID + "&numberList=" + n.Number;
                }
                else {
                    param += "&idList=" + n.ID + "&numberList=" + n.Number;
                }
            });

            $.tools.delPost(param, "/FaultRecords/Delete/", function () {
                $('#dg').datagrid("clearSelections");
                $('#dg').datagrid("reload");
            }, this);
        }
        function save() {

            if ($("#faultRecordForm").form("enableValidation").form("validate")) {

                var entity = $("#faultRecordForm").serializeJson();

                entity.FaultType = { ID: entity.FaultTypeID };

                $.tools.post({ jsonData: JSON.stringify(entity) }, "/FaultRecords/Save/", function (r) {
                    $("#dg").datagrid("reload");
                    $("#faultRecordDlg").window("close");
                });
            }
        }

        function cancelFault() {
            if ($("#cancelFaultForm").form("enableValidation").form("validate")) {
                var entity = $("#cancelFaultForm").serializeJson();
                $.tools.post(entity, "/FaultRecords/Cancel/", function (r) {
                    $("#dg").datagrid("reload");
                    $("#cancelFaultDlg").window("close");
                });
            }
        }
    </script>
</asp:Content>
