<%@ page language="C#" masterpagefile="AdminIndexMaster.master" autoeventwireup="true" inherits="Admin_Admin_ShopClass, mallz" title="商城栏目管理" enableviewstate="false" enableEventValidation="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&ParentID='+id;
      break;
      case "Modify":
      window.location.href='Admin_ShopAddClass.aspx?Action=Modify&ClassID='+id;
      break;
  }
}
function SelectRootClass(objvalue)
{
    location.href = "?classid=" + objvalue;
}

var ParentID = 0;
var classid = 0;
var createOK = 0;
var Obj = "";
var DivObj=null;
var pX,pY

document.onmousemove = OnMouseMove;
document.onmouseup = OnMouseUp;

function OnMouseDown(SelectObj,_ParentID){
	Obj = SelectObj.id;
	ParentID = _ParentID;
}
function OnMouseMove(){
    if(Obj != "" && createOK == 0){
        document.getElementById("ctl00_ContentPlaceHolder1_GridView1").setCapture();
	    DivObj = document.createElement('div');
	    DivObj.id="div_"+Obj;
	    DivObj.style.position = "absolute";
	    DivObj.className = "drag_lablestyle";
	    var mousePos = mouseCoords(window.event);
	    DivObj.style.left = mousePos.x + 10;
	    DivObj.style.top = mousePos.y + 8;
	    DivObj.style.zIndex = 100;
	    DivObj.innerHTML = "<table class='adminlist'><tr>"+document.getElementById("tr"+Obj.replace('main_','')).innerHTML+"</tr></table>";
	    document.body.appendChild(DivObj);
	    createOK = 1;
	    classid  = Obj.replace('main_','');
    }
	if(DivObj!=null){
		document.getElementById("ctl00_ContentPlaceHolder1_GridView1").releaseCapture();
		var mousePos = mouseCoords(window.event);
		window.event.returnValue=false;
	    DivObj.style.left = mousePos.x + 10;
	    DivObj.style.top = mousePos.y + 8;
	}
}

function OnMouseUp(){
    createOK = 0;
    Obj="";
    classid = 0;
    ParentID = 0;
	if(DivObj!=null){
		document.body.removeChild(DivObj);
		window.event.returnValue=true;
		DivObj = null;
		document.getElementById("ctl00_ContentPlaceHolder1_GridView1").releaseCapture();
		pX=pY=0;
	}
}
function mouseCoords(ev) {
    if(ev.pageX || ev.pageY) {
      return {x:ev.pageX, y:ev.pageY};
    }
    return {
      //x:ev.clientX + document.documentElement.scrollLeft - document.body.clientLeft,
      x:document.documentElement.scrollLeft - document.body.clientLeft,
      y:ev.clientY + document.documentElement.scrollTop - document.body.clientTop
    };
}

function SetPosit(SelectObj)
{
    var tclassid = 0;
    if(classid != 0 && DivObj!=null)
    {
        tclassid = SelectObj.id.replace('main_','');
        if(classid!=tclassid)
            location.href="?action=move&classid="+classid+"&tclassid="+tclassid+"&comeurl="+location.href;
            
        SelectObj.className = "mouseout";
    }
}
function addOnTop(SelectObj,_ParentID)
{
    if(classid != 0 && DivObj!=null && _ParentID == ParentID && classid!=SelectObj.id.replace('main_',''))
    {
        SelectObj.className = "mouseon";
    }
}
function removeOnTop(SelectObj)
{
    if(classid != 0 && DivObj!=null)
    {
        SelectObj.className = "mouseout";
    }
}
</script>

<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;}
  .drag_lablestyle{filter:alpha(opacity=80);}
  .mouseon{border-top:1px solid red;}
  .mouseout{border:0;cursor:move;}
</style>
 
<table class="" width="98%" >                       
          <tr>
            <td align="left">
                跳转到：<asp:DropDownList ID="RootClassSelect" runat="server"  DataTextField="ClassName" DataValueField="ClassID"  DataSourceID="ObjectDataSource2" onchange="SelectRootClass(this.value)" AppendDataBoundItems="true" SelectedValue='<%# MallZ.Common.Fetch.GetID("ClassID") %>'>
                   <asp:ListItem Value="0">顶级分类</asp:ListItem>
                </asp:DropDownList> 
            </td>
          </tr>                        
</table> 


        <asp:GridView id="GridView1" runat="server" AllowSorting="True" EnableViewState="false" DataSourceID="ObjectDataSource1" OnRowDataBound="GridView1_RowDataBound" DataKeyNames="ClassID"  CssClass="adminlist" AutoGenerateColumns="False" PageSize="40" >
         <Columns>
            <asp:TemplateField HeaderText="ID" HeaderStyle-Width="4%">
                <ItemTemplate>
                    <asp:Literal ID="Literal3" runat="server" Text='<%# Eval("classid") %>'/>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="分类名称" ItemStyle-HorizontalAlign="Left">
                <ItemTemplate>
                   <div id="<%# "main_"+Eval("ClassID") %>" class="mouseout" onmousedown='return OnMouseDown(this,"<%# Eval("ParentID") %>")' onmouseup="return SetPosit(this);" onmouseover="return addOnTop(this,'<%# Eval("ParentID") %>')" onmouseout="return removeOnTop(this)">
                   <asp:Literal ID="Literal1" runat="server" Text='<%# GetClassPrefixStyle(Convert.ToInt32(Eval("ClassID"))) %>'/>
                   <asp:Literal ID="litClassName" runat="server" Text='<%# Eval("ClassName") %>'/></div>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Child" HeaderText="子分类数" HeaderStyle-Width="8%" />
            <asp:TemplateField HeaderText="上架商品数" HeaderStyle-Width="8%">
                <ItemTemplate>
                    <asp:Literal ID="Literal2" runat="server" Text='<%# Eval("ItemCount") %>'/>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="权限" HeaderStyle-Width="8%">
                <ItemTemplate>
                    <asp:LinkButton ID="butEnableAdd" runat="server" Text='<%# ((Eval("EnableAdd").ToString()=="True")?"开放":"<font color=red>关闭</font>") %>' CommandArgument='<%#Eval("ClassID") %>' OnCommand="butEnableAdd_OnClick" /> / 
                    <asp:LinkButton ID="butShowOnIndex" runat="server" Text='<%# ((Eval("ShowOnIndex").ToString()=="True")?"显示":"<font color=red>隐藏</font>") %>' CommandArgument='<%#Eval("ClassID") %>' OnCommand="butShowOnIndex_OnClick" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="操作" HeaderStyle-Width="13%">
                <ItemTemplate>
                   <a href="javascript:AddClass('<%# Eval("ClassID") %>','Add')">添加</a> | 
                   <a href="javascript:AddClass('<%# Eval("ClassID") %>','Modify')">修改</a> | 
                   <asp:LinkButton id="btnDelete" runat="server" OnClientClick ="return showConfirm();" CommandName="Delete" Text="删除"/>
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>
		<EmptyDataTemplate>
		<div>无分类！<a href='Admin_ShopAddClass.aspx'>添加</a></div>
		</EmptyDataTemplate>
        </asp:GridView> 

  <asp:Literal ID="script_literal" runat="server" />
      <div style="margin-top:10px;">
     <asp:Button ID="UpdateClassSumButton" runat="server" Text="更新统计" OnClick="UpdateClassSumButton_Click" OnClientClick="return confirm('更新分类上架商品数，确定执行操作吗？')" />
     <asp:Button ID="CreateClassJSButton" runat="server" Text="生成 JS" Visible="false" OnClick="CreateClassJSButton_Click" OnClientClick="return confirm('更新分类的JS文件，确定执行操作吗？')" />
     <asp:Button ID="Button1" runat="server" Text="修复排序" OnClick="Button1_OnClick" OnClientClick="return confirm('执行操作后分类将从新排序，只有排序出现混乱时使用，确定执行操作吗？')" />
     <input type="button" value=" 返  回 " onclick="history.back();" />
      </div>
   <div class="help_intro" >
       <h1>帮助提示：</h1>
         <ul>
            <li>＂修复排序＂用于修复分类的属性，当分类出现混乱或子分类不显示的问题时使用。</li>
            <li>＂更新统计＂用于更新分类下的上架商品数，由于商品有下架时间，若商品较多建议一天更新一次。</li>
            <li>＂生成 JS＂ 用于生成或更新前台分类所调用的ＪＳ文件，新增、删除或修改分类后更新，以确保和前台显示一致。</li>  
         </ul>
       
      
    </div>
      <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllChildClassByParnetID" TypeName="MallZ.Data.Shop_Class" DeleteMethod="DeleteClassByClassID" OnInserted="ObjectDataSource1_Inserted" OnDeleting="Class_OnDeleting" >
        <DeleteParameters>
            <asp:Parameter Name="ClassID" Type="Int32" />
        </DeleteParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="ParentID" Type="Int32" DefaultValue="0" QueryStringField="ClassID" />
        </SelectParameters>
    </asp:ObjectDataSource>
    
    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetRootClass" TypeName="MallZ.Data.Shop_Class"  ></asp:ObjectDataSource>



</asp:Content>

