private void RemoveChildNodes(UltraTreeNode parentNode) { while (parentNode.Nodes.Count > 0) { var nodeTag = Convert.ToString(parentNode.Nodes[0].Tag); if (nodeTag == "group") { if (parentNode.Nodes[0].Nodes.Count > 0) { RemoveChildNodes(parentNode.Nodes[0]); } var data = new Category.Data(); data.CategoryId = Convert.ToInt32(GetKey(parentNode.Nodes[0].Key)); Category.Delete(data); parentNode.Nodes[0].Remove(); } else { var data = new CategoryItem.Data(); data.CategoryItemId = Convert.ToInt32(GetKey(parentNode.Nodes[0].Key)); CategoryItem.Delete(data); //nodeTag //parentNode.Nodes[i].Reposition( for (int j = 0; j < treeViewObjects.Nodes[0].Nodes.Count; j++) { var parentTag = Convert.ToString(treeViewObjects.Nodes[0].Nodes[j].Tag); if (parentTag == nodeTag + "s") { parentNode.Nodes[0].Reposition(treeViewObjects.Nodes[0].Nodes[j].Nodes); break; } } } } }
private void treeViewObjects_DragDrop(object sender, DragEventArgs e) { //A dummy node variable used for various things UltraTreeNode aNode; //The SelectedNodes which will be dropped SelectedNodesCollection SelectedNodes; //The Node to Drop On UltraTreeNode DropNode; //An integer used for loops int i; //Set the DropNode DropNode = UltraTree_DropHightLight_DrawFilter.DropHightLightNode; //Get the Data and put it into a SelectedNodes collection, //then clone it and work with the clone //These are the nodes that are being dragged and dropped SelectedNodes = (SelectedNodesCollection)e.Data.GetData(typeof(SelectedNodesCollection)); SelectedNodes = SelectedNodes.Clone() as SelectedNodesCollection; //Sort the selected nodes into their visible position. //This is done so that they stay in the same order when //they are repositioned. SelectedNodes.SortByPosition(); //Determine where we are dropping based on the current //DropLinePosition of the DrawFilter switch (UltraTree_DropHightLight_DrawFilter.DropLinePosition) { case DropLinePositionEnum.OnNode: //Drop ON the node { //Loop through the SelectedNodes and reposition //them to the node that was dropped on. //Note that the DrawFilter keeps track of what //node the mouse is over, so we can just use //DropHighLightNode as the drop target. for (i = 0; i <= (SelectedNodes.Count - 1); i++) { try { aNode = SelectedNodes[i]; var newParentTagName = Convert.ToString(DropNode.Tag); var oldParentTagName = Convert.ToString(aNode.Parent.Tag); var oldParentCategoryId = Convert.ToInt32(GetKey(aNode.Parent.Key)); var newParentCategoryId = Convert.ToInt32(GetKey(DropNode.Key)); var nodeTagName = Convert.ToString(aNode.Tag); if (string.IsNullOrEmpty(newParentTagName) || string.IsNullOrEmpty(oldParentTagName)) { continue; } if (nodeTagName == "group") { var data = new Category.Data(); data.CategoryId = Convert.ToInt32(GetKey(aNode.Key)); data.ParentCategoryId = newParentCategoryId; data.Name = aNode.Text.Split(new char[] { '(' })[0]; data.ConnectionId = ConnectionId; Category.Update(data); } else { if (newParentTagName == "root") { continue; } List <string> lstRootTags = new List <string>() { "tables", "procs", "views", "functions" }; var isUpdate = false; var isInsert = false; var isDelete = false; if (newParentTagName == "group" && oldParentTagName == "group") { isUpdate = true; } else if (newParentTagName == "group" && lstRootTags.Contains(oldParentTagName)) { if (nodeTagName + "s" != oldParentTagName) { isUpdate = true; } else { isInsert = true; } } else if (oldParentTagName == "group" && lstRootTags.Contains(newParentTagName)) { if (nodeTagName + "s" != newParentTagName) { isUpdate = true; } else { isDelete = true; } } else if (lstRootTags.Contains(newParentTagName) && lstRootTags.Contains(oldParentTagName)) { if (nodeTagName + "s" != newParentTagName && nodeTagName + "s" != oldParentTagName) { isUpdate = true; } else if (nodeTagName + "s" == oldParentTagName && nodeTagName + "s" != newParentTagName) { isInsert = true; } else if (nodeTagName + "s" == newParentTagName && nodeTagName + "s" != oldParentTagName) { isDelete = true; } } var data = new CategoryItem.Data(); data.CategoryId = newParentCategoryId; data.ItemType = nodeTagName; data.Name = aNode.Text.Split(new char[] { '(' })[0]; data.Status = "new"; if (isInsert) { data.CreatedDate = DateTime.Now; var categoryItemId = CategoryItem.Create(data, ApplicationConnectionString); aNode.Key = Convert.ToString(categoryItemId) + "$$" + aNode.Tag; } else if (isUpdate) { data.CategoryItemId = Convert.ToInt32(GetKey(aNode.Key)); CategoryItem.Update(data); } else if (isDelete) { data.CategoryItemId = Convert.ToInt32(GetKey(aNode.Key)); CategoryItem.Delete(data); } } //MessageBox.Show("aNode: " + aNode.Text); //MessageBox.Show("Drop Node: " + DropNode.Text); aNode.Reposition(DropNode.Nodes); } catch { } } break; } } //After the drop is complete, erase the current drop //highlight. UltraTree_DropHightLight_DrawFilter.ClearDropHighlight(); }