public static List <Exhibition> SelectByParentID(int parentID) { List <Exhibition> channelData = new List <Exhibition>(); List <int> idList = new List <int>(); //查询数据 Exhibition value = new Exhibition(); Exhibition conditon = new Exhibition(); if (parentID > 0) { conditon.Path = "%~" + parentID + "~%"; conditon.AddAttach("Path", "like"); } List <Exhibition> oldTypeData = TableOperate <Exhibition> .Select(value, conditon, 0, " order by ParentID, Depth, ID DESC "); for (int i = 0; i < oldTypeData.Count; i++) { Exhibition 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); }
private static int UpdateChild(Exhibition channel, Exhibition oldChannel) { //int depthSpan = channel.Depth - oldChannel.Depth; Exhibition value = new Exhibition(); Exhibition condition = new Exhibition(); 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 <Exhibition> .Update(value, condition)); }
/// <summary> /// 获取所有子类id序列,例如 1,3,4,5,6 /// </summary> /// <param name="id">要查询频道的id</param> /// <returns></returns> public static string GetChildID(int id) { Exhibition value = new Exhibition(); value.ID = 0; Exhibition conditon = new Exhibition(); conditon.Path = "%~" + id + "~%"; conditon.AddAttach("Path", "like"); List <Exhibition> childChannelList = TableOperate <Exhibition> .Select(value, conditon); string idStr = ""; for (int i = 0; i < childChannelList.Count; i++) { idStr += childChannelList[i].ID + ","; } idStr = idStr.Trim(','); return(idStr); }