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

<%@ Register Src="../../Controls/Pager.ascx" TagName="Pager" TagPrefix="ucPager" %>
<%@ Register Src="../../Controls/LoadButton.ascx" TagName="LoadButton" TagPrefix="ucLoadButton" %>
<!DOCTYPE html>
<html>
<head>
    <title><%=ModuleName%></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="usage" /></dd>
            </dl>
            <dl>
                <dt>药品类别</dt>
                <dd>
                    <select name="category">
                        <option value="全部">全部</option>
                        <option value="西药">西药</option>
                        <option value="中药">中药</option>
                    </select>
                </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>
                        <th>是否注射</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
        <ucPager:Pager ID="gridPager" runat="server" />
    </div>
    <script>
        (function() {
            var url = "DrugUsageList.aspx",
            dialogUrl = "/MBase/SysDrugUsage/DrugUsageForm.aspx",
            dialogFormName = "DrugUsage_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() {
                $("#btnAdd").click(function() {
                    top.openDialog(dialogUrl, dialogFormName, title + ' - 添加', 700, 150, 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.ID, dialogFormName, title + ' - 编辑', 700, 150, 50, 50);
                                break;
                            case "删除":
                                remove(data);
                                break;
                        }
                    }
                });
            }
            function remove(data) {
                top.showConfirmMsg("确定要删除[用法]为[" + data.Usage + "]的药品用法信息吗?", function(r) {
                    if (r) {
                        $.get(url, { action: "remove", id: data.ID }, 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.Usage))
                .append($("<td>").html(data.Category))
                .append($("<td>").html(data.Simple))
                .append($("<td>").html(data.IsInjection));
            }
            init();
        })();
    </script>
</body>
</html>
