<%@ page language="C#" autoeventwireup="true" inherits="Admin_Admin_SelectClassify, 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="/Admin/Css/admin_style.css" rel="stylesheet" type="text/css" />
    <link href="/Admin/Css/Css/tabpane.css" type="text/css" rel="stylesheet" />
    <style type="text/css">
        Table.adminlist td
        {
            height: 15px;
        }
        Table.adminlist td b
        {
            color: red;
            font-style: normal;
        }
        Table.adminlist td em
        {
            color: blue;
            font-style: normal;
        }
        Table.adminlist td
        {
            white-space: normal;
            word-spacing: normal;
        }
    </style>
    <script type="text/javascript">
        function SelectRootClass(classid) {
            if (!isNaN(classid) && parseInt(classid) > 0) {
                window.location.href = "Admin_SelectClassify.aspx?ClassID=" + classid;
            }
        }
        //节点显示隐藏
        function showHide(theHiddenMess) {
            var i;
            var item;
            for (i = 0; i < myClass.length; ++i) {
                item = myClass[i];
                if (!item)
                    continue;
                if (item[3] == theHiddenMess) {
                    var view = document.getElementById("tr" + item[0]);
                    if (view != null) {
                        if (view.style.display == "none")
                        { view.style.display = ""; }
                        else {
                            view.style.display = "none";
                            if (item[2] > 0)
                                showHide(item[0]);
                        }
                    }
                }
            }
        }
    </script>
    <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;
                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 = productform.ProductList.value + ',' + singleName[i];
                    productform.hfProductList.value = productform.hfProductList.value + ',' + singleUser[i]; //ID
                }
            }
            if (ignoreUser != '') {
                alert(ignoreUser + '商品分类已经存在，此操作已经忽略！');
            }
            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 = '';
                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;
        }
        //检查当前选择的值是否存在已选择的列表值
        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>
</head>
<body>
    <form id="productform" runat="server">
    <div>
        <table width='100%' border='0' align='center' cellpadding='2' cellspacing='0' style="margin-left: 10px">
            <tr class='title'>
                <td valign='top'>
                    <b>已经选定的商品分类：</b>
                </td>
                <td align='right'>
                </td>
            </tr>
            <tr class='tdbg'>
                <td>
                    <asp:TextBox ID="ProductList" Rows="6" Columns="50" TextMode="MultiLine" runat="server"
                        ReadOnly="true" Height="86px" />
                    <asp:HiddenField ID="hfProductList" runat="server" />
                </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>
    <div style="margin-left: 10px;">
        <%--请选择要查看的分类：<asp:DropDownList ID="RootClassSelect" runat="server" DataTextField="ClassName"
            DataValueField="RootID" onchange="SelectRootClass(this.value)" AppendDataBoundItems="true">
            <asp:ListItem Value="0">请选择</asp:ListItem>
        </asp:DropDownList>--%>
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetRootClass"
            TypeName="HoWave.Web.Shop_Class"></asp:ObjectDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" EnableViewState="false"
            OnRowDataBound="GridView1_RowDataBound" OnDataBound="GridView1_DataBound" DataKeyNames="ClassID"
            CssClass="adminlist" AutoGenerateColumns="False" PageSize="40">
            <Columns>
                <asp:BoundField DataField="ClassID" HeaderText="ID" HeaderStyle-Width="5%" />
                <asp:TemplateField HeaderText="分类名称及目录">
                    <ItemTemplate>
                        <%-- <a style='cursor: pointer;' onclick="add('<%# Eval("ClassName")%>','<%# Eval("ClassID")%>')"><%# Eval("ClassName")%></a>--%>
                        <%# DisplayClassName(((System.Data.DataRowView)Container.DataItem).Row)%>
                        <asp:Literal ID="ClassName" runat="server" Text='<%#Eval("Depth")+"--"+Eval("ClassName") %>' />
                    </ItemTemplate>
                    <HeaderStyle Width="45%" />
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
            </Columns>
            <EmptyDataTemplate>
                <table>
                    <tr>
                        <td colspan="2">
                            没有数据！
                        </td>
                    </tr>
                </table>
            </EmptyDataTemplate>
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetClassByRootID"
            TypeName="HoWave.Web.Shop_Class" DeleteMethod="DeleteClassByClassID">
            <SelectParameters>
                <asp:QueryStringParameter Name="RootID" Type="Int32" DefaultValue="1" QueryStringField="ClassID" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:Literal ID="script_literal" runat="server" />
    </div>
    </form>
</body>
</html>
