/// <summary> /// 删除整棵树中所有需要删除的节点。 /// </summary> /// <param name="tree">The tree.</param> /// <param name="markSaved">if set to <c>true</c> [mark saved].</param> private void SubmitTreeDeletedItems(ITreeComponent tree, bool markSaved) { //整合所有要删除的节点。 var mergedDeletedList = new List <Entity>(); #region 加入列表的待删除节点。 var list = tree as EntityList; if (list != null) { var toDeletedList = list.DeletedListField; if (toDeletedList != null) { var isTreeRootList = list.IsTreeRootList; for (int i = 0, c = toDeletedList.Count; i < c; i++) { var child = toDeletedList[i]; //如果在删除之后,又变换了 TreePId,那么可能是该节点已经加入到别的子树中, //却无法修改根列表的 DeletedList 而导致该节点还在其中。 //所以需要把这些节点过滤掉,根列表只处理根节点的删除。 if (!isTreeRootList || child.TreePId == null) { //由于自关联外键没有级联删除,所以节点必须完整加载后,再全部加入到列表中。 TreeHelper.FullAddIntoList(child, mergedDeletedList); } } } } #endregion #region 加入所有节点的待删除列表节点。 tree.EachNode(node => { var tc = node.TreeChildrenField; if (tc != null) { var tcDeleted = tc.DeletedListField; if (tcDeleted != null) { for (int i = 0, c = tcDeleted.Count; i < c; i++) { var deleted = tcDeleted[i]; //与列表一样,必须检测删除的节点,当前是不是还属于 node。 if (node.Id.Equals(deleted.TreePId)) { TreeHelper.FullAddIntoList(deleted, mergedDeletedList); } } } } return(false); }); #endregion //反转顺序后再保存。 mergedDeletedList.Reverse(); for (int i = 0, c = mergedDeletedList.Count; i < c; i++) { var item = mergedDeletedList[i]; item.PersistenceStatus = PersistenceStatus.Deleted; this.SubmitItem(item, false, false); } if (markSaved) { tree.MarkSaved(); } }
/// <summary> /// 删除整棵树中所有需要删除的节点。 /// </summary> /// <param name="tree">The tree.</param> /// <param name="markSaved">if set to <c>true</c> [mark saved].</param> private void SubmitTreeDeletedItems(ITreeComponent tree, bool markSaved) { //整合所有要删除的节点。 var mergedDeletedList = new List<Entity>(); #region 加入列表的待删除节点。 var list = tree as EntityList; if (list != null) { var toDeletedList = list.DeletedListField; if (toDeletedList != null) { var isTreeRootList = list.IsTreeRootList; for (int i = 0, c = toDeletedList.Count; i < c; i++) { var child = toDeletedList[i]; //如果在删除之后,又变换了 TreePId,那么可能是该节点已经加入到别的子树中, //却无法修改根列表的 DeletedList 而导致该节点还在其中。 //所以需要把这些节点过滤掉,根列表只处理根节点的删除。 if (!isTreeRootList || child.TreePId == null) { //由于自关联外键没有级联删除,所以节点必须完整加载后,再全部加入到列表中。 TreeHelper.FullAddIntoList(child, mergedDeletedList); } } } } #endregion #region 加入所有节点的待删除列表节点。 tree.EachNode(node => { var tc = node.TreeChildrenField; if (tc != null) { var tcDeleted = tc.DeletedListField; if (tcDeleted != null) { for (int i = 0, c = tcDeleted.Count; i < c; i++) { var deleted = tcDeleted[i]; //与列表一样,必须检测删除的节点,当前是不是还属于 node。 if (node.Id.Equals(deleted.TreePId)) { TreeHelper.FullAddIntoList(deleted, mergedDeletedList); } } } } return false; }); #endregion //反转顺序后再保存。 mergedDeletedList.Reverse(); for (int i = 0, c = mergedDeletedList.Count; i < c; i++) { var item = mergedDeletedList[i]; item.PersistenceStatus = PersistenceStatus.Deleted; this.SubmitItem(item, false, false); } if (markSaved) { tree.MarkSaved(); } }