Solved

Sum of duration in parent & child folders in database

Posted on 2004-09-03
7
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11974669
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
ID: 11975416
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
ID: 11988936
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11989054
No objections.
0
 
LVL 9

Expert Comment

by:solution46
ID: 11990886
Me neither.
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 12030018
PAQd, 250 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 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