Import tasks into a .Net dataset - Finding Parent or Indent level

J

JdZ

Hello,

I am trying to read the project structure from a .mpp file and import it
into an ERP system for billing hours.

The project structure may be

Task 1
--Task 1.1
----Task 1.1.1
----Task 1.1.2
--Task 1.2
----Task 1.2.1
----Task 1.2.2
Task 2
Task 3
--Task 3.1
--Task 3.2


I loop through the tasks using the following code to add it to a dataset.

foreach (MSProject.Task task in proj.Tasks)
{
row = dtTable.NewRow();
row["TaskID"] = task.ID;
row["TaskName"] = task.Name;
row["StartDate"] = task.Start;
row["EndDate"] = task.Finish;
row["Duration"] = task.Duration;
row["Notes"] = task.Notes;

if (task.OutlineChildren.Count == 0)
row["Type"] = "Task";
else
row["Type"] = "Subtask";

row["ParentID"] = ???????????????????? OR
row["IndentLevel"] = xxxxxxxxxxxxxxxxxx

dtTable.Rows.Add(row);
}

Now here is my question....

I want either the level of indentation, or the parent task id so I can
display the same heirachy in my application.

I have looked through the SDK and the elements of the MSProject.Task
variable with out any luck.

Any help would be appreciated.

JdZ
 
J

JdZ

I'm repling to my own post here....

But while I was having coffee I came up with an idea. I'd still like a
cleaner solution if there is one.

ArrayList ParentID = new ArrayList();
ArrayList NumChildren = new ArrayList();

int iIndentLevel = 0;
int iTemp = 0;

foreach (MSProject.Task task in proj.Tasks)
{

row = dtTable.NewRow();
row["TaskID"] = task.ID;
row["TaskName"] = task.Name;
row["StartDate"] = task.Start;
row["EndDate"] = task.Finish;
row["Duration"] = task.Duration;
row["Notes"] = task.Notes;

if (iIndentLevel > 0)
{
// If this record is indented then
// reduce the count of children
// and set the parentid

row["ParentID"] = ParentID[iIndentLevel - 1];
iTemp = (int)NumChildren[iIndentLevel - 1];
iTemp = iTemp - 1;

NumChildren[iIndentLevel - 1] = iTemp;

// If there are no more children then reduce the
indent
// and remove the items from the array lists

if (iTemp == 0)
{
ParentID.RemoveAt(iIndentLevel - 1);
NumChildren.RemoveAt(iIndentLevel - 1);

iIndentLevel = iIndentLevel - 1;

}
}

if (task.OutlineChildren.Count == 0)
{
row["Type"] = "Task";
}
else
{
row["Type"] = "Subtask";

// As this item has children add the
// details to the array list

iIndentLevel = iIndentLevel + 1;
NumChildren.Add(task.OutlineChildren.Count);
ParentID.Add(task.ID);

}

dtTable.Rows.Add(row);
}
 
J

Jan De Messemaeker

Hi,

I do not use the language you use so I'm not sure but if you have the task
object what good is it to still refer to the row?
And taskobject.outlinelevel is what you seem to look for.
HTH
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
JdZ said:
I'm repling to my own post here....

But while I was having coffee I came up with an idea. I'd still like a
cleaner solution if there is one.

ArrayList ParentID = new ArrayList();
ArrayList NumChildren = new ArrayList();

int iIndentLevel = 0;
int iTemp = 0;

foreach (MSProject.Task task in proj.Tasks)
{

row = dtTable.NewRow();
row["TaskID"] = task.ID;
row["TaskName"] = task.Name;
row["StartDate"] = task.Start;
row["EndDate"] = task.Finish;
row["Duration"] = task.Duration;
row["Notes"] = task.Notes;

if (iIndentLevel > 0)
{
// If this record is indented then
// reduce the count of children
// and set the parentid

row["ParentID"] = ParentID[iIndentLevel - 1];
iTemp = (int)NumChildren[iIndentLevel - 1];
iTemp = iTemp - 1;

NumChildren[iIndentLevel - 1] = iTemp;

// If there are no more children then reduce the
indent
// and remove the items from the array lists

if (iTemp == 0)
{
ParentID.RemoveAt(iIndentLevel - 1);
NumChildren.RemoveAt(iIndentLevel - 1);

iIndentLevel = iIndentLevel - 1;

}
}

if (task.OutlineChildren.Count == 0)
{
row["Type"] = "Task";
}
else
{
row["Type"] = "Subtask";

// As this item has children add the
// details to the array list

iIndentLevel = iIndentLevel + 1;
NumChildren.Add(task.OutlineChildren.Count);
ParentID.Add(task.ID);

}

dtTable.Rows.Add(row);
}













JdZ said:
Hello,

I am trying to read the project structure from a .mpp file and import it
into an ERP system for billing hours.

The project structure may be

Task 1
--Task 1.1
----Task 1.1.1
----Task 1.1.2
--Task 1.2
----Task 1.2.1
----Task 1.2.2
Task 2
Task 3
--Task 3.1
--Task 3.2


I loop through the tasks using the following code to add it to a dataset.

foreach (MSProject.Task task in proj.Tasks)
{
row = dtTable.NewRow();
row["TaskID"] = task.ID;
row["TaskName"] = task.Name;
row["StartDate"] = task.Start;
row["EndDate"] = task.Finish;
row["Duration"] = task.Duration;
row["Notes"] = task.Notes;

if (task.OutlineChildren.Count == 0)
row["Type"] = "Task";
else
row["Type"] = "Subtask";

row["ParentID"] = ???????????????????? OR
row["IndentLevel"] = xxxxxxxxxxxxxxxxxx

dtTable.Rows.Add(row);
}

Now here is my question....

I want either the level of indentation, or the parent task id so I can
display the same heirachy in my application.

I have looked through the SDK and the elements of the MSProject.Task
variable with out any luck.

Any help would be appreciated.

JdZ
 
Top