<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InventoryForm.aspx.cs" Inherits="Medical.MBusiness.SysInventory.InventoryForm" %>

<%@ Register Src="../../Controls/Pager.ascx" TagName="Pager" TagPrefix="ucPager" %>
<%@ Register Src="../../Controls/Grid.ascx" TagName="Grid" TagPrefix="ucGrid" %>
<!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/Pager.js" type="text/javascript"></script>
    <script src="../../js/myLib/Grid.js" type="text/javascript"></script>
</head>
<body>
    <div style="padding:20px" >
        <%--<div class="pt-panel pt-below">--%>
            <div class="pt-grid_frame">
                <ucGrid:Grid ID="grid" runat="server" />
            </div>
            <ucPager:Pager ID="gridPager" runat="server" />
      <%--  </div>--%>
        <div class="pt-line"></div>
        <div class="pt-padding" style="text-align:center">
            <input type="button" id="btnClear" class="pt-button active" value="清理" />
            <input type="button" class="pt-button active" onclick="top.OpenClose('Inventory_Form')" value="关闭" />
        </div>
    </div>
    <script>
        (function() {
            var url = "InventoryForm.aspx",
                grid = new Grid({ id: "grid", url: url, pager: new Pager("gridPager"), bindFun: bindData });
            function init() {
                setPage();
                grid.search();
                bindEvents();
            }
            function bindEvents() {
                $("#btnClear").click(function() {
                    clear();
                });
                $("#grid thead").find("input").click(function() {
                    var isChecked = $(this).is(":checked");
                    $("#grid tbody").find(":checkbox").attr("checked", isChecked);
                });
            }
            function setPage() {
                $("#grid").find("th:eq(0)").append('<input type="checkbox" >全选/反选');
            }
            function clear() {
                var checks = $("#grid tbody").find("input:checked");
                if (checks.length == 0) {
                    top.showTipsMsg("请选择要清理的项目!", 1, 3000);
                } else {
                    var ids = [];
                    checks.each(function() {
                        ids.push($(this).parent().parent().data("data").ID);
                    });
                    $.get(url, { action: "clear", id: ids.join(",") }, function(data) {
                        if (data == "success") {
                            location.reload();
                            top.showTipsMsg("清理成功!", 0, 3000);
                        } else {
                            top.showTipsMsg("清理失败!", 1, 3000);
                        }
                    });
                }
            }
            function bindData(tr, data) {
                tr.append($("<td>").html('<input type="checkbox" />'))
                .append($("<td>").html(data.Code))
                .append($("<td>").html(data.Barcode))
                .append($("<td>").html(data.Name))
                .append($("<td>").html(data.Spec))
                .append($("<td>").html(data.Unit))
                .append($("<td>").html(data.Type))
                .append($("<td>").html(data.Material))
                .append($("<td>").html(data.Factory))
                .append($("<td>").html(data.Batch))
                .append($("<td>").html(data.Valid))
                .append($("<td>").html(data.PurchasePrice))
                .append($("<td>").html(data.Amount));
            }
            init();
        })();
    </script>
</body>
</html>