static void InitDefault(Database db) { if (db == null) { throw new ArgumentNullException("Database"); } var catId = db.Create(Category.Create("Favorites")); if (catId >= 0) { var catItemId = db.Create(CategoryItem.Create(catId, "Github")); if (catItemId > 0) { db.Create(ValueItem.Create(catItemId, 0, SecValueType.Url, "https://github.com")); db.Create(ValueItem.Create(catItemId, 1, SecValueType.Username, "My Username")); db.Create(ValueItem.Create(catItemId, 2, SecValueType.Password, "My Password")); } catItemId = db.Create(CategoryItem.Create(catId, "Emailaccount")); if (catItemId > 0) { db.Create(ValueItem.Create(catItemId, 0, SecValueType.Url, "https://somewhere.com")); db.Create(ValueItem.Create(catItemId, 1, SecValueType.Username, "My Username")); db.Create(ValueItem.Create(catItemId, 2, SecValueType.Password, "My Password")); } } }
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(); }