Пример #1
0
        /// <summary>
        /// Delete a location from the tree
        /// </summary>
        protected void DeleteTreeLocation()
        {
            // Get the parent - as we don;t allow selection across levels we can be sure that the parent for all
            // selected items is the same
            UltraTreeNode parentNode = locationsTree.SelectedNodes[0].Parent;

            // first check that the user isn't trying to delete the root location
            if (parentNode == null)
            {
                MessageBox.Show("Unable to delete " + locationsTree.SelectedNodes[0].Text + " - the top-level location cannot be deleted", "AuditWizard", MessageBoxButtons.OK);
                return;
            }

            // Confirm the deletion as this is a pretty serious function
            if (MessageBox.Show("Are you sure that you want to delete the selected location(s)?  All child locations will also be deleted and any child assets moved to the parent location.", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
            {
                return;
            }

            // Delete these locations
            foreach (UltraTreeNode node in locationsTree.SelectedNodes)
            {
                // get the location and delete from the database
                AssetGroup location = node.Tag as AssetGroup;
                location.Delete();

                // ...and remove it from the tree
                parentNode.Nodes.Remove(node);
            }

            // Select the parent node as this will cause the list to be refreshed
            parentNode.BringIntoView();
            parentNode.Selected = true;
        }
Пример #2
0
        /// <summary>
        /// Called to delete locations from the ListView (and also the tree)
        /// </summary>
        protected void DeleteListLocation()
        {
            // Sanity check to ensure that at least one item is selected in the list
            if (locationsList.SelectedItems.Count == 0)
            {
                return;
            }

            foreach (UltraListViewItem item in locationsList.SelectedItems)
            {
                AssetGroup location = item.Tag as AssetGroup;

                // Now delete the location from the database
                if (location.Delete())
                {
                    // Successfully deleted so remove from the listview
                    locationsList.Items.Remove(item);

                    // ...and from the tree view also
                    UltraTreeNode parentNode = locationsTree.SelectedNodes[0];
                    UltraTreeNode childNode  = FindChildNode(parentNode, location.Name);
                    parentNode.Nodes.Remove(childNode);
                }
            }
        }