示例#1
0
    public static List <TagTree> SelectByParentID(int parentID)
    {
        List <TagTree> channelData = new List <TagTree>();
        List <int>     idList      = new List <int>();

        //查询数据
        TagTree value    = new TagTree();
        TagTree conditon = new TagTree();

        if (parentID > 0)
        {
            conditon.Path = "%~" + parentID + "~%";
            conditon.AddAttach("Path", "like");
        }
        List <TagTree> oldTypeData = TableOperate <TagTree> .Select(value, conditon, 0, " order by ParentID, Depth, ID DESC ");

        for (int i = 0; i < oldTypeData.Count; i++)
        {
            TagTree typeObj = oldTypeData[i];
            if (typeObj.Depth == 0) //深度为0,直接添加
            {
                channelData.Insert(0, typeObj);
                idList.Insert(0, typeObj.ID);
            }
            else
            {
                int parentIndex = idList.IndexOf(typeObj.ParentID); //查找上及目录所在位置!
                channelData.Insert(parentIndex + 1, typeObj);
                idList.Insert(parentIndex + 1, typeObj.ID);         //将数据插入上级目录之后
            }
        }
        return(channelData);
    }
示例#2
0
    private static int UpdateChild(TagTree channel, TagTree oldChannel)
    {
        //int depthSpan = channel.Depth - oldChannel.Depth;
        TagTree value     = new TagTree();
        TagTree condition = new TagTree();

        condition.Path = "%~" + channel.ID + "~%";
        condition.AddAttach("Path", "like");

        value.RootID = channel.RootID;
        value.Depth  = channel.Depth - oldChannel.Depth;
        value.AddParameter("OldPath", oldChannel.Path + "" + channel.ID + "~");
        value.AddParameter("OldNamePath", oldChannel.NamePath + "" + oldChannel.Name + "~");
        value.Path     = channel.Path + "" + channel.ID + "~";
        value.NamePath = channel.NamePath + "" + channel.Name + "~";

        value.SetUpdate(" RootID=@RootID, Depth = Depth + @Depth, [Path]=REPLACE([Path], @OldPath, @Path) , [NamePath]=REPLACE([NamePath], @OldNamePath, @NamePath)");
        return(TableOperate <TagTree> .Update(value, condition));
    }
示例#3
0
    /// <summary>
    /// 获取所有子类id序列,例如 1,3,4,5,6
    /// </summary>
    /// <param name="id">要查询频道的id</param>
    /// <returns></returns>
    public static string GetChildID(int id)
    {
        TagTree value = new TagTree();

        value.ID = 0;
        TagTree conditon = new TagTree();

        conditon.Path = "%~" + id + "~%";
        conditon.AddAttach("Path", "like");

        List <TagTree> childChannelList = TableOperate <TagTree> .Select(value, conditon);

        string idStr = "";

        for (int i = 0; i < childChannelList.Count; i++)
        {
            idStr += childChannelList[i].ID + ",";
        }

        idStr = idStr.Trim(',');
        return(idStr);
    }