<%@ page language="C#" autoeventwireup="true" inherits="Member_JXC_StockOrderSaleSelect, WebApp_deploy" title="销售订单选择" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <base target="_self" />
    <link href="../../Skin/Default/Member/Red.css" rel="stylesheet" type="text/css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <script type="text/javascript">
        //添加
        function add(obj, objID) {
            if (obj == '') { return false; }
            var productform = document.forms[0];
            if (productform.hfProductList.value == '') {
                //商品名称值
                productform.ProductList.value = obj;
                window.returnValue = productform.ProductList.value;
                //商品ID值
                productform.hfProductList.value = objID;
                window.returnValue = productform.hfProductList.value;

                SelectedCheckbox();
                return false;
            }
            var singleUser = objID.split(',');
            var singleName = obj.split(',');
            var ignoreUser = '';
            for (i = 0; i < singleUser.length; i++) {
                if (checkInfo(productform.hfProductList.value, singleUser[i])) {
                    ignoreUser = ignoreUser + singleName[i] + " ";
                }
                else {
                    productform.ProductList.value = singleName[i]; //productform.ProductList.value + ',' + singleName[i];
                    productform.hfProductList.value = singleUser[i]; // productform.hfProductList.value + ',' + singleUser[i]; //ID
                }
            }
            if (ignoreUser != '') {
                alert(ignoreUser + '订单已经存在，此操作已经忽略！');
            }

            SelectedCheckbox();
            window.returnValue = productform.ProductList.value;
        }
        //删除（0：全部、1：最后一个）
        function del(num) {
            var productform = document.forms[0];
            if (num == 0 || productform.hfProductList.value == '' || productform.hfProductList.value == ',') {
                productform.ProductList.value = '';
                productform.hfProductList.value = '';

                SelectedCheckbox();
                return false;
            }

            var strDel = productform.ProductList.value;
            var strDelID = productform.hfProductList.value; //ID
            var s = strDel.split(',');
            var sID = strDelID.split(','); //ID
            productform.ProductList.value = strDel.substring(0, strDel.length - s[s.length - 1].length - 1);
            window.returnValue = productform.ProductList.value;

            productform.hfProductList.value = strDelID.substring(0, strDelID.length - sID[sID.length - 1].length - 1);
            window.returnValue = productform.hfProductList.value;
            SelectedCheckbox();
        }
        //检查当前选择的值是否存在已选择的列表值
        function checkInfo(ProductList, thisUser) {
            if (ProductList == thisUser) {
                return true;
            }
            else {
                var s = ProductList.split(',');
                for (j = 0; j < s.length; j++) {
                    if (s[j] == thisUser)
                        return true;
                }
                return false;
            }
        }    
    </script>
    <script type="text/javascript">
        //判断选择的项
        function SelectedCheckbox() {
            var productform = document.forms[0];
            var hf = productform.hfProductList;
            var oItem = document.getElementsByName("chk_select");
            var itemname = "";
            var itemvalue = "";
            for (var i = 0; i < oItem.length; i++) {
                if (oItem[i].type == "radio") {
                    oItem[i].checked = false;
                }
            }

            if (hf != null) {
                if (hf.value != "") {
                    var s = hf.value.split(',');
                    for (j = 0; j < s.length; j++) {
                        for (var i = 0; i < oItem.length; i++) {
                            if (oItem[i].type == "radio") {
                                if (oItem[i].value == s[j]) {
                                    oItem[i].checked = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        window.onload = SelectedCheckbox;

        //判断选择的项
        function SelectCheckboxesNO() {
            var oItem = document.getElementsByName("chk_select");
            var oItemN = document.getElementsByName("hidproductname");
            var itemname = "";
            var itemvalue = "";
            for (var i = 0; i < oItem.length; i++) {
                if (oItem[i].type == "radio") {
                    if (oItem[i].checked == true) {
                        itemvalue += oItem[i].value + ","
                        itemname += oItemN[i].value + ",";
                    }
                }
            }


            var productform = document.forms[0];
            if (itemvalue == "") {
                productform.ProductList.value = "";
                productform.hfProductList.value = ""; //ID
                alert("没有选中订单信息！");
            } else {
                itemname = itemname.substring(0, itemname.length - 1);
                itemvalue = itemvalue.substring(0, itemvalue.length - 1);

                if (itemname == '') { return false; }

                var s = itemvalue.split(',');
                for (j = 0; j < s.length; j++) {
                    for (var i = 0; i < oItem.length; i++) {
                        if (oItem[i].type == "radio") {
                            if (oItem[i].value == s[j]) {
                                oItem[i].checked = true;
                                break;
                            }
                        }
                    }
                }

                productform.ProductList.value = itemname;
                productform.hfProductList.value = itemvalue; //ID
                window.returnValue = productform.ProductList.value;
            }
        }
    </script>
</head>
<body>
    <form id="productform" runat="server">
    <asp:ScriptManager ID="sm" runat="server">
    </asp:ScriptManager>
    <div id="MainMenu">
        <div class="TabText">
            <div style="line-height: 2px;">
                &nbsp;</div>
            <div>
                &nbsp;&nbsp;<asp:Literal ID="ltrProType" runat="server">选择订单</asp:Literal>
            </div>
            <div>
                <table width='100%' border='0' align='center' cellpadding='2' cellspacing='0' style="margin-left: 10px">
                    <tr class='title'>
                        <td valign='top'>
                            <b>已经选定的订单：
                                <asp:TextBox ID="ProductList" Width="200px" runat="server" ReadOnly="true" />
                                <asp:HiddenField ID="hfProductList" runat="server" />
                            </b>
                        </td>
                    </tr>
                    <tr>
                        <td style="margin-left: 20px;">
                            <input name="ok" value="确 定" type="button" onclick="javascript:window.returnValue=productform.hfProductList.value;window.close();" />
                            <input type='button' name='del1' onclick='del(1)' value='删除' />
                            <%-- <input type='button' name='del2' onclick='del(0)' value='删除全部' />--%>
                        </td>
                    </tr>
                </table>
            </div>
            <asp:UpdatePanel ID="upGv" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ForeColor="Black"
                        AllowPaging="True" PageSize="10" DataKeyNames="OrderFormID" CssClass="tableHead"
                        OnPageIndexChanging="GridView1_PageIndexChanging">
                        <Columns>
                            <asp:TemplateField HeaderText="选择">
                                <ItemTemplate>
                                    <input type="radio" id="chk_select" name="chk_select" value='<%# Eval("OrderFormID")%>'
                                        onclick="return SelectCheckboxesNO()" />
                                    <input type="hidden" id="hidproductname" name="hidproductname" value='<%#Eval("OrderFormNum")%>' />
                                </ItemTemplate>
                                <ItemStyle Width="6%" HorizontalAlign="Center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="订单编号">
                                <ItemTemplate>
                                    <a style="cursor: pointer;" onclick="add('<%# Eval("OrderFormNum")%>','<%# Eval("OrderFormID")%>')">
                                        <asp:Label ID="lblOrderFormNum" runat="server" Text='<%#Eval("OrderFormNum")%>'></asp:Label>
                                    </a>
                                </ItemTemplate>
                                <HeaderStyle Width="20%" />
                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                            </asp:TemplateField>
                            <asp:BoundField DataField="BuyerName" HeaderText="客户">
                                <ItemStyle HorizontalAlign="Center" />
                                <HeaderStyle Width="10%" />
                            </asp:BoundField>
                            <asp:TemplateField HeaderText="商品名称">
                                <ItemTemplate>
                                    <div style="width: 100%; overflow: hidden;">
                                        <asp:HyperLink ID="ProductName" ToolTip='<%# Eval("ProductName") %>' Text='<%# Eval("ProductName") %>'
                                            runat="server" /></div>
                                </ItemTemplate>
                                <HeaderStyle Width="30%" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="类型">
                                <ItemTemplate>
                                    <asp:Literal ID="TradeType" Text='<%# HoWave.Web.Shop.TextFormat.GetProductType(Eval("TradeType").ToString()) %>'
                                        runat="server" />
                                </ItemTemplate>
                                <HeaderStyle Width="7%" />
                            </asp:TemplateField>
                            <asp:BoundField DataField="InputTime" DataFormatString="{0:yy-MM-dd}" HeaderText="时间">
                                <HeaderStyle Width="10%" />
                            </asp:BoundField>
                            <asp:BoundField DataField="MoneyTotal" HeaderText="金额">
                                <ItemStyle ForeColor="Green" />
                                <HeaderStyle Width="7%" />
                            </asp:BoundField>
                            <asp:BoundField DataField="MoneyReceipt" HeaderText="已收金额">
                                <ItemStyle ForeColor="Green" />
                                <HeaderStyle Width="10%" />
                            </asp:BoundField>
                        </Columns>
                        <EmptyDataTemplate>
                            <table class="tableHeader" style="width: 98%">
                                <tr>
                                    <th>
                                        编号
                                    </th>
                                    <th>
                                        客户
                                    </th>
                                    <th>
                                        购买产品
                                    </th>
                                    <th>
                                        类型
                                    </th>
                                    <th>
                                        时间
                                    </th>
                                    <th>
                                        金额
                                    </th>
                                    <th>
                                        已收金额
                                    </th>
                                    <tr>
                                        <td colspan="7">
                                            没有符合查询条件的记录！
                                        </td>
                                    </tr>
                            </table>
                        </EmptyDataTemplate>
                        <PagerStyle CssClass="productPageStyle" />
                    </asp:GridView>
                    <div style="text-align: center;">
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:Literal ID="ltrPagePanel" runat="server"></asp:Literal>&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                    <div style="line-height: 2px;">
                        &nbsp;</div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </div>
    </form>
</body>
</html>
