<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DepartmentList.aspx.cs" Inherits="Medical.MBase.SysDepartment.DepartmentList" %>

<%@ Register Src="../../Controls/Pager.ascx" TagName="Pager" TagPrefix="ucPager" %>
<%@ Register Src="../../Controls/LoadButton.ascx" TagName="LoadButton" TagPrefix="ucLoadButton" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../js/myLib/jsHelper_Form.js" type="text/javascript"></script>
    <script src="../../js/myLib/Pager.js" type="text/javascript"></script>
    <script src="../../js/myLib/Grid.js" type="text/javascript"></script>
</head>
<body>
    <div class="pt-panel">
        <strong><%=ModuleName %></strong>
        <form name="fCondition" class="pt-padding">
            <ucLoadButton:LoadButton ID="LoadButton1" runat="server"/>
            <dl>
                <dt>科室名称</dt>
                <dd><input type="text" name="name" /></dd>
            </dl>
        </form>
    </div>
    <div class="pt-panel pt-below">
        <strong>查询一览</strong>
        <div class="pt-grid_frame">
            <table class="pt-grid" id="grid">
                <thead>
                    <tr>
                        <th style="width:130px">操作</th>
                        <th>科室名称</th>
                        <th>备注</th>
                        <th>科室名称拼音码</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
        <ucPager:Pager ID="gridPager" runat="server" />
    </div>
    <script>
    (function() {
        var url = "DepartmentList.aspx",
        dialogUrl = "/MBase/SysDepartment/DepartmentForm.aspx",
        dialogFormName = "Department_Form",
        listbutton = '<%=Medical.MCommon.PageHelper.GetListButton() %>',
        grid = new Grid({ id: "grid", url: url, pager: new Pager("gridPager"), bindFun: bindData }),
        title = '<%=ModuleName %>';

        function init() {
            grid.search();
            bindEvents();
        }
        function bindEvents() {
            $('input[type="text"]').keydown(function(e) {
                if (e.keyCode == 13) {
                    grid.search(true);
                }
            });
            $("#btnAdd").click(function() {
                top.openDialog(dialogUrl, dialogFormName, title + ' - 添加', 700, 100, 50, 50);
            });
            $("#btnQuery").click(function() {
                grid.search(true);
            });
            grid.control.click(function(e) {
                var target = $(e.target);
                if (target.is("input")&& !target.is(":disabled")) {
                    var data = target.parent().parent().data("data");
                    switch (target.val()) {
                        case "修改":
                            top.openDialog(dialogUrl + "?key=" + data.dID, dialogFormName, title + ' - 编辑', 700, 100, 50, 50);
                            break;
                        case "删除":
                            remove(data);
                            break;
                    }
                }
            });
        }
        function remove(data) {
            top.showConfirmMsg("确定要删除[科室名称]为[" + data.dName + "]的科室信息吗?", function(r) {
                if (r) {
                    $.get(url, { action: "remove", id: data.dID }, function(data) {
                        if (data == "success") {
                            top.showTipsMsg('删除成功!', 0, 5000);
                            grid.search();
                        } else {
                            top.showTipsMsg('删除失败!', 1, 5000);
                        }
                    });
                }
            });
        }
        function bindData(tr, data) {
            tr.append($("<td>").html(listbutton))
            .append($("<td>").html(data.dName))
            .append($("<td>").html(data.dRemark))
            .append($("<td>").html(data.dSimple));
        }
        init();
    })();
    </script>
</body>
</html>
