Hi, could you help me?
I have this situation:
- A task with two resources, when finish first resource, should start the next one.
- Task 1 - Start - 2018/01/01 - Finish - 2018/03/23 - Duration - 60 days
- Resource 1 - Start - 2018/01/01 - Finish 2018/01/31
- Resource 2 - Start - 2018/02/01 - Finish 2018/03/23
Example of expected .mpp and .xml:
expect.zip (32.7 KB)
How could I code this?
I’ve tried this:
License license = new License();
license.SetLicense("Aspose.Tasks.lic");
Project project = new Project("Template.mpp");
project.CalculationMode = CalculationMode.None;
project.Set(Prj.StartDate, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
Resource rsc1 = project.Resources.Add("Resource 1 (Work)");
rsc1.Set(Rsc.Type, ResourceType.Work);
rsc1.Set(Rsc.StandardRate, Convert.ToDecimal(1));
rsc1.Set(Rsc.Code, "2158");
Resource rsc2 = project.Resources.Add("Resource 2 (Work)");
rsc2.Set(Rsc.Type, ResourceType.Work);
rsc2.Set(Rsc.StandardRate, Convert.ToDecimal(1));
rsc2.Set(Rsc.Code, "2159");
Task tsk1 = project.RootTask.Children.Add("Task - 01");
tsk1.Set(Tsk.IsManual, false);
tsk1.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
tsk1.Set(Tsk.Duration, project.GetDuration(30, TimeUnitType.Day));
tsk1.Set(Tsk.Type, TaskType.FixedDuration);
Task tsk2 = tsk1.Children.Add("Task - 01.01");
tsk2.Set(Tsk.IsManual, false);
tsk2.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
tsk2.Set(Tsk.Duration, project.GetDuration(30, TimeUnitType.Day));
tsk2.Set(Tsk.Type, TaskType.FixedDuration);
Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
tsk3.Set(Tsk.IsManual, false);
tsk3.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
tsk3.Set(Tsk.Duration, project.GetDuration(60, TimeUnitType.Day));
tsk3.Set(Tsk.Type, TaskType.FixedDuration);
project.Recalculate();
ResourceAssignment assignment1 = project.ResourceAssignments.Add(tsk3, rsc1);
assignment1.Set(Asn.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
assignment1.Set(Asn.Finish, DateTime.ParseExact("2018-01-31", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
ResourceAssignment assignment2 = project.ResourceAssignments.Add(tsk3, rsc2);
assignment2.Set(Asn.Start, DateTime.ParseExact("2018-02-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
assignment2.Set(Asn.Finish, DateTime.ParseExact("2018-03-23", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
project.CalcResourceFields();
project.CalcResourceStartFinish();
project.Save(@"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
project.Save(@"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
output.zip (62.1 KB)