The following code will allow booking of individual periods in the TimePhaseDetail of MSP.
I've used the following tools/languages for this demo.
- Aspose.Tasks version: 4.0.0.0
- Microsoft Visual Studio 2010 C#
- Microsoft Project 2007
In the example below, all resources are being assigned to each task and are given a 1 or 2 value depending on the flag variable.
foreach (Task task in _tasks.Values) {
foreach (Aspose.Tasks.Resource resource in _resources.Values) {
ResourceAssignment resourceAssignment = new
ResourceAssignment();
foreach (Aspose.Tasks.Resource resource in _resources.Values) {
ResourceAssignment resourceAssignment = new
ResourceAssignment();
resourceAssignment.Task = task;
resourceAssignment.Resource = resource;
resourceAssignment.Start = task.ActualStart;
resourceAssignment.Finish = task.ActualFinish;
resourceAssignment.Units = 1;
resourceAssignment.HasFixedRateUnits = true;
resourceAssignment.LevelingDelayFormat = TimeUnitType.ElapsedHour;
resourceAssignment.Uid = _project.NextResourceAssignmentUid;
resourceAssignment.WorkContour = WorkContourType.Contoured;
DateTime date = task.ActualStart;
if (flag) timephaseData.Value = "PT1H0M0S";
else timephaseData.Value = "PT2H0M0S";
I needed this requirement in the task I was working on and found that there were no existing examples on how to do it yet so this is just from my research.
bool flag = true;
while (date < task.ActualFinish) {
TimephasedData timephaseData = new TimephasedData();
while (date < task.ActualFinish) {
TimephasedData timephaseData = new TimephasedData();
timephaseData.Start = date;
timephaseData.Unit = TimeUnitType.Hour;
date = date.AddDays(1);
timephaseData.Finish = date;
timephaseData.Uid = _project.ResourceAssignments.Count ;
timephaseData.TimephasedDataType = TimephasedDataType.AssignmentActualWork ;
if (flag) timephaseData.Value = "PT1H0M0S";
else timephaseData.Value = "PT2H0M0S";
flag = !flag;
resourceAssignment.TimephasedData.Add(timephaseData);
}
_project.ResourceAssignments.Add(resourceAssignment);
}
}
This is the resource usage view in MSP 2007. Notice that the resource Alien 1 is assigned to all projects with an alternating value.
I needed this requirement in the task I was working on and found that there were no existing examples on how to do it yet so this is just from my research.
No comments:
Post a Comment