示例#1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (ActiveNode.Sections.Count > 0)
            {
                ShowError(
                    "Không thể xóa nút khi có các vùng phân hệ trong nó. Hãy xóa hoặc tạm gỡ toàn bộ các vùng này trước.");
            }
            else if (ActiveNode.ChildNodes.Count > 0)
            {
                ShowError("Không thể xóa nút khi còn các nút con. Hãy xóa hết các nút con trước.");
            }
            else
            {
                try
                {
                    CoreRepository.ClearQueryCache("Nodes");

                    bool hasParentNode = (ActiveNode.ParentNode != null);
                    if (hasParentNode)
                    {
                        ActiveNode.ParentNode.ChildNodes.Remove(ActiveNode);
                    }
                    else
                    {
                        IList rootNodes = CoreRepository.GetRootNodes(ActiveNode.Site);
                        rootNodes.Remove(ActiveNode);
                    }
                    CoreRepository.DeleteNode(ActiveNode);
                    // Reset the position of the 'neighbour' nodes.
                    if (ActiveNode.Level == 0)
                    {
                        ActiveNode.ReOrderNodePositions(CoreRepository.GetRootNodes(ActiveNode.Site),
                                                        ActiveNode.Position);
                    }
                    else
                    {
                        ActiveNode.ReOrderNodePositions(ActiveNode.ParentNode.ChildNodes, ActiveNode.Position);
                    }
                    CoreRepository.FlushSession();
                    if (hasParentNode)
                    {
                        Context.Response.Redirect(String.Format("NodeEdit.aspx?NodeId={0}", ActiveNode.ParentNode.Id));
                    }
                    else
                    {
                        Context.Response.Redirect("Default.aspx");
                    }
                }
                catch (Exception ex)
                {
                    ShowError(ex.Message);
                    log.Error(String.Format("Có lỗi khi xóa nút: {0}.", ActiveNode.Id), ex);
                }
            }
        }