public void DeleteNode(TreeNode node) { if (node.Tag is Conference) { DBHelper.DeleteConferences(new int[] { (node.Tag as Conference).ConferenceID }); } else if (node.Tag is Participant) { DBHelper.DeleteParticipants(new int[] { (node.Tag as Participant).ParticipantID }); } else if (node.Tag is Stream) { DBHelper.DeleteStreams(new int[] { (node.Tag as Stream).StreamID }); } else // it's a year, month, or day, so do search for conferences { // We'll do this with a really simple recursive-style approach. // Iterate over a shallow copy since we'll be deleting from the main Nodes collection. TreeNode[] tmp = new TreeNode[node.Nodes.Count]; node.Nodes.CopyTo(tmp, 0); foreach (TreeNode child in tmp) { DeleteNode(child); } } this.RemoveNodes(new TreeNode[] { node }); }
public void DeleteNode(TreeNode node) { if (node.Tag is Conference) { DBHelper.DeleteConferences(new int[] { (node.Tag as Conference).ConferenceID }); } else if (node.Tag is Participant) { DBHelper.DeleteParticipants(new int[] { (node.Tag as Participant).ParticipantID }); } else if (node.Tag is Stream) { DBHelper.DeleteStreams(new int[] { (node.Tag as Stream).StreamID }); } else // it's a year, month, or day, so do search for conferences { // We'll do this with a really simple recursive-style approach... foreach (TreeNode child in node.Nodes) { DeleteNode(child); } } this.RemoveNodes(new TreeNode[] { node }); }
public void DeleteConferences(TreeNode[] nodes) { int[] confIDs = new int[nodes.Length]; for (int cnt = 0; cnt < confIDs.Length; ++cnt) { confIDs[cnt] = ((nodes[cnt] as TreeNode).Tag as Conference).ConferenceID; } DBHelper.DeleteConferences(confIDs); RemoveNodes(nodes); }
/// <summary> /// Deletes the data in the database that a node corresponds to, if any. /// </summary> private void DeleteNodeContents(TreeNode emptyNode) { if (emptyNode.Tag is Conference) { DBHelper.DeleteConferences(new int[] { (emptyNode.Tag as Conference).ConferenceID }); } else if (emptyNode.Tag is Participant) { DBHelper.DeleteParticipants(new int[] { (emptyNode.Tag as Participant).ParticipantID }); } else if (emptyNode.Tag is Stream) { DBHelper.DeleteStreams(new int[] { (emptyNode.Tag as Stream).StreamID }); } }
public void CleanUpDatabase() { // Find: // - conferences w/o participants // - participants w/o streams // - streams w/o bytes ArrayList confs = new ArrayList(), parts = new ArrayList(), streams = new ArrayList(); #region Depth-first-search of tree // By collecting a full list of the conferences, participants, and streams to be deleted // we can more effeciently delete the objects by doing quick bulk deletes from the database, // rather than transacting for each individual delete. foreach (TreeNode yearNode in Nodes) { foreach (TreeNode monthNode in yearNode.Nodes) { foreach (TreeNode dateNode in monthNode.Nodes) { foreach (TreeNode confNode in dateNode.Nodes) { if (!confNode.Nodes.GetEnumerator().MoveNext()) // check for emptiness { confs.Add(confNode); } else { foreach (TreeNode partNode in confNode.Nodes) { if (!partNode.Nodes.GetEnumerator().MoveNext()) { parts.Add(partNode); } else { foreach (TreeNode streamNode in partNode.Nodes) { if ((streamNode.Tag as Stream).Bytes <= 1) { streams.Add(streamNode); } } } } } } } } } #endregion #region Transact on DB for Delete: // - conferences int[] confIDs = new int[confs.Count]; for (int cnt = 0; cnt < confIDs.Length; ++cnt) { confIDs[cnt] = ((confs[cnt] as TreeNode).Tag as Conference).ConferenceID; } DBHelper.DeleteConferences(confIDs); // - participants int[] partIDs = new int[parts.Count]; for (int cnt = 0; cnt < partIDs.Length; ++cnt) { partIDs[cnt] = ((parts[cnt] as TreeNode).Tag as Participant).ParticipantID; } DBHelper.DeleteParticipants(partIDs); // - streams int[] streamIDs = new int[streams.Count]; for (int cnt = 0; cnt < streamIDs.Length; ++cnt) { streamIDs[cnt] = ((streams[cnt] as TreeNode).Tag as Stream).StreamID; } DBHelper.DeleteStreams(streamIDs); #endregion // Delete from UI RemoveNodes(confs); RemoveNodes(parts); RemoveNodes(streams); // Find Conferences w/o end times // (for simplicity, just get them from the DB again) Conference[] allConfs = DBHelper.GetConferences(); foreach (Conference conf in allConfs) { if (conf.End == DateTime.MinValue) { DBHelper.CreateConferenceEndTime(conf.ConferenceID); } } }