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

<%@ Register Src="../../Controls/Date.ascx" TagName="Date" TagPrefix="ucDate" %>
<%@ 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="../../Scripts/My97DatePicker/My97DatePicker/WdatePicker.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>
    <script src="../../js/myLib/jsHelper_Base.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="warehouse" /></dd>
            </dl>
            <dl>
                <dt>入库单号</dt>
                <dd><input type="text" name="num" /></dd>
            </dl>
            <dl>
                <dt>供应商</dt>
                <dd><input type="text" name="supplier" /></dd>
            </dl>
            <ucDate:Date ID="ucDate" runat="server" />
        </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:170px">操作</th>
                        <th>入库单号</th>
                        <th>入库仓库</th>
                        <th>入库日期</th>
                        <th>供应商</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 = "InStockList.aspx",
            dialogUrl = "/MBusiness/SysInStock/InStockForm.aspx",
            dialogFormName = "InStock_Form",
            listbutton = '<%=Medical.MCommon.PageHelper.GetListButton() %>',
            button = $("<div>").append(listbutton),
            grid = new Grid({ id: "grid", url: url, pager: new Pager("gridPager"), bindFun: bindData }),
            title = '<%=ModuleName %>';

            function init() {
                DateValidate(document.getElementById("startDate"), document.getElementById("endDate"));
                grid.search();
                bindEvents();
            }

            function bindEvents() {
                $("#btnAdd").click(function() {
                    top.openDialog(dialogUrl, dialogFormName, title + ' - 添加', 1200, 530, 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 + "?type=view&key=" + data.Num, dialogFormName, title + ' - 查看', 1200, 530, 50, 50);
                                break;
                            case "修改":
                                top.openDialog(dialogUrl + "?key=" + data.Num, dialogFormName, title + ' - 编辑', 1200, 530, 50, 50);
                                break;
                            case "删除":
                                remove(data);
                                break;
                        }
                    }
                });
            }
            function remove(data) {
                top.showConfirmMsg("确定要删除[入库单号]为[" + data.Num + "]的入库信息吗?", function(r) {
                    if (r) {
                        $.get(url, { action: "remove", id: data.Num }, function(data) {
                            if (data == "success") {
                                top.showTipsMsg('删除成功!', 0, 5000);
                                grid.search();
                            } else {
                                top.showTipsMsg('删除失败!', 1, 5000);
                            }
                        });
                    }
                });
            }
            function bindData(tr, data) {
                var confirm = data.Confirm == "已确认", buttonTemp = button.clone();
                if (confirm) {
                    buttonTemp.find('[value="修改"]').removeClass("pt-button active").addClass("pt-button-disabled").attr("disabled", true);
                    buttonTemp.find('[value="删除"]').removeClass("pt-button active").addClass("pt-button-disabled").attr("disabled", true);
                }
                tr.append($("<td>").html(buttonTemp.html()))
                .append($("<td>").html(data.Num))
                .append($("<td>").html(data.Warehouse))
                .append($("<td>").html(data.Date))
                .append($("<td>").html(data.Supplier))
                .append($("<td>").html(data.Man))
                .append($("<td>").html(data.Confirm))
                .append($("<td>").html(data.ConfirmDate))
                .append($("<td>").html(data.ConfirmMan));
            }
            init();
        })();
    </script>
</body>
</html>

