<%@ page language="C#" masterpagefile="AdminIndexMaster.master" autoeventwireup="true" inherits="HL_Admin_Admin_ShopClass, WebApp_deploy" title="商城栏目管理" enableviewstate="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" language="javascript">
function AddClass(id,action){
  switch (action){
      case "Add":
          window.location.href = 'Admin_ShopAddClass.aspx?Action=Add&MenuName=商城>>商品管理&FileName=添加商品分类&ParentID=' + id;
      break;
      case "Modify":
          window.location.href = 'Admin_ShopAddClass.aspx?Action=Modify&MenuName=商城>>商品管理&FileName=编辑商品分类&ClassID=' + id;
      break;
  }
   
}

function AddNewClass(){
     var arr=showModalDialog('Admin_ShopAddClass.aspx?ParentID=-1',window,'dialogWidth:650px; dialogHeight:500px; help: no; scroll: yes; status: no');
     if (arr != null){
       document.getElementById(ctlName).value=arr;
     }     
}

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]);
			    }
			}    	   
		}
	}
}
function showHide2(theHiddenMess,start) {
    var i
	var item;
    for(i=start;i<myClass.length;i++)
    {
	    item = myClass[i];
		if (!item)
		    continue;
		if(item[3]==theHiddenMess)
    		{
		    var view = document.getElementById("tr"+item[0]);
            view.style.display = "none";
			if(item[2]>0)
			    showHide2(item[0],i);
			}
    }
}
function showConfirm()
{
  return confirm('删除栏目操作将删除此栏目中的所有子栏目及商品,并且不能恢复!确定要删除此栏目吗?');
}
var c;
function cc(obj)
{
  c=obj.style.backgroundColor;
  obj.style.backgroundColor='#E7EDFE'
  
}
function cc1(obj)
{
  obj.style.backgroundColor=c;
}
//对应onclick事件
function MoveClass(objID,classname,e)
{
  var MoveClassObj=document.getElementById("MoveClass");
  document.getElementById("moveClassID").value=objID;
  MoveClassObj.style.display="";
  document.getElementById("className").innerHTML=classname;
  var showDiv=e.target||e.srcElement;
 
  var pos=getPosXY(showDiv,[-400,0]);  
  
  MoveClassObj.style.left=pos[0]+'px';
  MoveClassObj.style.top=pos[1]+'px';
  
}
  function getPosXY(a,offset)
  {
    var tn=null;
	var p=offset?offset.slice(0):[0,0];
	while(a)
	{
		tn=a.tagName.toUpperCase();
		
		p[0]+=a.offsetLeft-(tn=="DIV"&&a.scrollLeft?a.scrollLeft:0);
		p[1]+=a.offsetTop-(tn=="DIV"&&a.scrollTop?a.scrollTop:0);
		if(tn=="BODY")
		   break;
		a=a.offsetParent;
	}
	
	return p;
  }
  function SelectRootClass(classid){
     if(!isNaN(classid) && parseInt(classid)>0){
        window.location.href="Admin_ShopClass.aspx?ClassID="+classid;
     }
  }
</script>
<table class="" width="98%">                       
          <tr>
            <th class="msgconfig" align="left">
                商城分类管理</th>
            <td align="right">                
                <div style="width:300px">
                请选择要查看的分类：<asp:DropDownList ID="RootClassSelect" runat="server"  DataTextField="ClassName" DataValueField="RootID"  DataSourceID="ObjectDataSource2" onchange="SelectRootClass(this.value)" AppendDataBoundItems="true">
                   <asp:ListItem Value="0">请选择</asp:ListItem>
                </asp:DropDownList>
                <a href="#" id="AddNewClass" onclick="javascript:AddClass('0','Add')" >添加新分类</a></div>  
            </td>
          </tr>                        
       </table> 
 <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>

        <asp:GridView id="GridView1" runat="server" AllowSorting="True" EnableViewState="false" DataSourceID="ObjectDataSource1" OnRowDataBound="GridView1_RowDataBound" DataKeyNames="ClassID" 
        CssClass="adminlist" AutoGenerateColumns="False" OnDataBound="GridView1_DataBound" PageSize="40" ><Columns>
            <asp:BoundField DataField="ClassID" HeaderText="ID" HeaderStyle-Width="5%" /> 
            <asp:TemplateField HeaderText="分类名称及目录">            
               
                <ItemTemplate>
                   <%# 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>

              <asp:TemplateField HeaderText="类型">          
                <ItemTemplate>
                    <%#Eval("Attributes_Type").ToString() == "-1" ? "" : Eval("Attributes_Type").ToString()%>                                  
                </ItemTemplate>
                <HeaderStyle Width="10%" />
            </asp:TemplateField>

                <asp:TemplateField HeaderText="权限">          
                <ItemTemplate>
                    <asp:Literal ID="Access" runat="server" Text='<%# (Eval("ShowOnTop").ToString()=="True")?"开放":"关闭" %>'/>                                     
                </ItemTemplate>
                <HeaderStyle Width="10%" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="操作选项">           
                <ItemTemplate>
                           <a href="javascript:AddClass('<%# Eval("ClassID") %>','Add')">添加子分类</a>|
                           <a href="javascript:AddClass('<%# Eval("ClassID") %>','Modify')">修改设置</a>|
                           <a href="javascript:void(0)" onclick="MoveClass('<%# Eval("ClassID") %>','<%# Eval("ClassName") %>',event);">排序</a>|                       
                           <asp:LinkButton id="btnDelete" runat="server" OnClientClick ="return showConfirm();" CommandName="Delete" Text="删除"/>               
                       
                </ItemTemplate>
                <HeaderStyle Width="20%" />
            </asp:TemplateField>
            </Columns>

        </asp:GridView> 

  <asp:Literal ID="script_literal" runat="server" />
      <div style="margin-top:10px;">
     <asp:Button ID="RepairClassButton" runat="server" Text="修复分类" OnClick="RepairClassButton_Click" OnClientClick="if(confirm('修复分类将重新检索分类的属性，决定吗？')){this.value='正在修复分类,请稍候!';return true;}else{return false;}" />
     <asp:Button ID="UpdateClassSumButton" runat="server" Text="更新分类商品数" OnClick="UpdateClassSumButton_Click" OnClientClick="return confirm('更新分类上架商品数，决定吗？')" />
     <asp:Button ID="CreateClassJSButton" runat="server" Text="更新分类Js" OnClick="CreateClassJSButton_Click" OnClientClick="return confirm('将更新分类的JS文件，决定吗？')" />
      </div>
   <div class="help_intro" >
       <h1>帮助提示：</h1>
       
         <ul>
            <li>＂修复分类按钮＂用于修复分类的属性，当分类出现混乱或子分类不显示的问题可以使用．</li>
            <li>＂更新分类商品数按钮＂用于更新分类所属的商品的上架商品数，由于商品有下架时间，若商品较多建议一天更新一次</li>
            <li>＂更新分类Js按钮＂用于生成或更新前台分类所调用的ＪＳ，请新增，删除或修改分类名称时更新分类ＪＳ，以确保前台显示一致</li>
            
                     
         </ul>
       
      
    </div>
      <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetClassByRootID" TypeName="HoWave.Web.Shop_Class" DeleteMethod="DeleteClassByClassID" OnInserted="ObjectDataSource1_Inserted" OnDeleting="Class_OnDeleting" >
        <DeleteParameters>
            <asp:Parameter Name="ClassID" Type="Int32" />
        </DeleteParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="RootID" Type="Int32" DefaultValue="1" QueryStringField="ClassID" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetRootClass" TypeName="HoWave.Web.Shop_Class"  >        
    </asp:ObjectDataSource>
  <div id="MoveClass" style="display:none; width:300px; height:50px; position:absolute; top:200px; left:200px; background:white;border:solid 1px black;" >
     <div  class="pageTitle">移动目录:<span id="className"></span></div>  
       <asp:DropDownList ID="MoveAction" runat="server">
          <asp:ListItem Text="上移" Value="+" />
          <asp:ListItem Text="下移" Value="-" />
       </asp:DropDownList>
       <asp:TextBox ID="MoveNums" runat="server"  Text="1"/>
       <asp:Button ID="MoveClass_Button" Text="确定"  runat="server" OnClick="MoveClass_Click"/>&nbsp;<input type="button" value="取消"  onclick="javascript:document.getElementById('MoveClass').style.display='none'"/>
  </div>  
  <input type="hidden" value="" name="moveClassID" id="moveClassID" />
</asp:Content>

