Solved

Sum of duration in parent & child folders in database

Posted on 2004-09-03
7
377 Views
Last Modified: 2006-11-17
Hi all,

I have a MS Access database with 2 tables.
Table1 is FileProperties and Table2 is TreeStructure.

FileProperties has
FileID,
FileName,
ParentValue,
Duration and
......

TreeStructure has
NodeID,
NodeName,
IsFolder and
ParentID.

The TreeStructure table is used to generate a tree where records with a 'IsFolder = Yes' will be a folder while records with a 'IsFolder = No' are nodes that will fall under its parent(folder).

When I insert a record into FileProperties, 'FileID' is auto-generated.
As I insert the a new record into FileProperties, I need to insert a record into TreeStructure where NodeID will be auto-generated,

The 'NodeName' will be same as the 'FileName' in FileProperties, IsFolder is No and ParentID will be a Node in TreeStructure which is a folder.

Each file in FileProperties has a duration in seconds.
Now, my question.
Let's say I have a tree like this, pls see picture.
http://www.geocities.com/coltan81/tree.gif

and I would like to get the sum of the duration of files and folders given a NodeID from TreeStructure which is a folder.
I know I can get the sum of duration for 1 folder using
SELECT SUM(Duration) FROM FilePropertiesDB WHERE ParentValueDB = the folder's NodeID

My problem is I need to get the sum(Duration) of the files under the given folder and the sum(Duration) of all the files under its child folders. There can be many child folders and child folders can have child folders... This goes on..

How do I do it like in Windows Explorer where when I open the properties of a folder, I can get the total size of the files inside the folder itself and its child folders (in my case duration)?

If this is not possible, please suggest alternative.

Thank you very much.      
0
Comment
Question by:coltan
7 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
Hmm....first of all, a comment on your table structure. Shouldn't you be using the FileID rather than a nodename to link the two tables? Files in different folders might have the same name - or are you using the full path of the file?

One way to do this is to iterate through the Nodes collection and check for any node where the FullPath property includes the target folder's FullPath property. If it does, that node is a child of your target folder. You can then retrieve the record that matches that node and then add the filesize to your running value.
0
 
LVL 9

Expert Comment

by:solution46
Comment Utility
Something else you could try (this will only work in code in the interface) is to build the Summing process into the function where you build the tree. Last time I wrote code to populate a tree-view, iended up with a function that called itself for each child id; thereby recursing through each branch. As you draw each node, make a note of the duration and write it back to the parent node. This isn't trivial to do, but if you're build a tree anyway, it wont add too much compexity.

Presumably you are using the front end to enter files, etc. If this is the case, each time you draw the tree (or each time you close it, or whatever) you could write the total duration of each folder back to the table. I know this seems 'wrong way round' but I can't think of an easier approach.

Incidentally, if you need a sample of tree view code I can probably dig some up from somewhere. You could also try getting hold of a book called 'VB COntrols in a Nutshell' - it's an excellent reference source for the controls of the various common control libraries.

s46.
0
 

Author Comment

by:coltan
Comment Utility
Hi all,

Thanks for trying to help. I have found a solution for my problem.

I added a 'Duration' column in my TreeStructure table. So, whenever I need to insert a record to the database, I insert the file duration to the TreeStructure table at the same time. Besides that, I update the parent folder and 'grandparent' folders' duration field. Hence, when I need the sum of duration of files and folders in a big folder, I just read the 'Duration' column from the TreeStructure database.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
No objections.
0
 
LVL 9

Expert Comment

by:solution46
Comment Utility
Me neither.
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
Comment Utility
PAQd, 250 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now