private void DeleteAllChildren(string parentKey) { // Get DMU Access Class DescriptionOfMapUnitsAccess DmuAccess = new DescriptionOfMapUnitsAccess(m_theWorkspace); // Get the children var sortedChildren = GetSortedChildren(parentKey); // Loop through them, delete each one foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> anEntry in sortedChildren) { // Get the DMU entry for this entry DmuAccess.AddDescriptionOfMapUnits("DescriptionOfMapUnits_ID = '" + anEntry.Value.DescriptionOfMapUnits_ID + "'"); DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDmuEntry = DmuAccess.DescriptionOfMapUnitsDictionary[anEntry.Value.DescriptionOfMapUnits_ID]; /// Delete related record in the Extended Attributes table deleteExtendedAtrributesRecord(thisDmuEntry.MapUnit); /// Delete related lithology records deleteLithologyRecord(thisDmuEntry.MapUnit); // Delete it DmuAccess.DeleteDescriptionOfMapUnits(thisDmuEntry); // Delete its children DeleteAllChildren(thisDmuEntry.HierarchyKey); } }
private void tlsbtnRemoveLegendItem_Click(object sender, EventArgs e) { // Get DMU Access Class DescriptionOfMapUnitsAccess dmuAccess = new DescriptionOfMapUnitsAccess(m_theWorkspace); // Find out if the selected node has children if (trvLegendItems.SelectedNode.Nodes.Count > 0) { // This node has children, ensure they want it all gone DialogResult result = MessageBox.Show("If you delete this entry, all of its children will be removed as well. Do you want to continue?", "NCGMP Tools", MessageBoxButtons.YesNo); if (result != DialogResult.Yes) { return; } // They want to continue. First delete this one dmuAccess.AddDescriptionOfMapUnits("DescriptionOfMapUnits_ID = '" + trvLegendItems.SelectedNode.Name + "'"); DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisEntry = dmuAccess.DescriptionOfMapUnitsDictionary[trvLegendItems.SelectedNode.Name]; /// Delete related record in the Extended Attributes table deleteExtendedAtrributesRecord(thisEntry.MapUnit); /// Delete related lithology records deleteLithologyRecord(thisEntry.MapUnit); dmuAccess.DeleteDescriptionOfMapUnits(thisEntry); // Now Delete all children DeleteAllChildren(thisEntry.HierarchyKey); // Adjust the Hierarchy RemoveItemFromHierarchy(thisEntry.HierarchyKey); } else { // This node has no children, simply delete it dmuAccess.AddDescriptionOfMapUnits("DescriptionOfMapUnits_ID = '" + trvLegendItems.SelectedNode.Name + "'"); DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisEntry = dmuAccess.DescriptionOfMapUnitsDictionary[trvLegendItems.SelectedNode.Name]; /// Delete related record in the Extended Attributes table deleteExtendedAtrributesRecord(thisEntry.MapUnit); /// Delete related lithology records deleteLithologyRecord(thisEntry.MapUnit); dmuAccess.DeleteDescriptionOfMapUnits(thisEntry); // Remove this item from the Hierarchy - Update its siblings and children RemoveItemFromHierarchy(thisEntry.HierarchyKey); } // Clear Inputs ClearMapUnitInput(); //Re-populate the Treeview PopulateMainLegendTree(); }