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