Hi,
how to distribute the use of resources?
I tried:
static void Main(string[] args) { License license = new License(); license.SetLicense("Aspose.Tasks.lic"); Project project = new Project("Template.mpp"); //project.CalculationMode = CalculationMode.None; /*Begin Resource*/ Resource resource1 = project.Resources.Add("Resource 1 (Material)"); resource1.Set(Rsc.Name, "Resource 1 (Material)"); resource1.Set(Rsc.MaterialLabel, "Pct"); resource1.Set(Rsc.Type, ResourceType.Material); resource1.Set(Rsc.StandardRate, Convert.ToDecimal(30)); resource1.Set(Rsc.Code, "1"); Resource resource2 = project.Resources.Add("Resource 2 (Material)"); resource2.Set(Rsc.Name, "Resource 2 (Material)"); resource2.Set(Rsc.MaterialLabel, "Un"); resource2.Set(Rsc.Type, ResourceType.Material); resource2.Set(Rsc.StandardRate, Convert.ToDecimal(50)); resource2.Set(Rsc.Code, "2"); /*End Resource*/ /*Begin Tasks*/ Task tsk1 = project.RootTask.Children.Add("Task 1"); tsk1.Set(Tsk.IsManual, true); tsk1.Set(Tsk.Type, TaskType.FixedUnits); tsk1.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)); tsk1.Set(Tsk.Duration, project.GetDuration(10, TimeUnitType.Day)); tsk1.Set(Tsk.Work, tsk1.Get(Tsk.Duration)); /*End Tasks*/ /*Begin Assigment*/ ResourceAssignment assignment1 = project.ResourceAssignments.Add(tsk1, resource1); assignment1.Set(Asn.Units, 5); ResourceAssignment assignment2 = project.ResourceAssignments.Add(tsk1, resource2); assignment2.Set(Asn.Units, 5); assignment2.Set(Asn.WorkContour, WorkContourType.Contoured); ClearTimephasedData(assignment2); var td = new TimephasedData(); td.Start = new DateTime(2018, 1, 1, 8, 0, 0); td.Finish = td.Start.AddHours(8); td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork; td.Value = TimeSpanToTDString(TimeSpan.FromHours(1)); assignment2.TimephasedData.Add(td); td = new TimephasedData(); td.Start = new DateTime(2018, 1, 2, 8, 0, 0); td.Finish = td.Start.AddHours(8); td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork; td.Value = TimeSpanToTDString(TimeSpan.FromHours(1)); assignment2.TimephasedData.Add(td); td = new TimephasedData(); td.Start = new DateTime(2018, 1, 3, 8, 0, 0); td.Finish = td.Start.AddHours(8); td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork; td.Value = TimeSpanToTDString(TimeSpan.FromHours(1)); assignment2.TimephasedData.Add(td); td = new TimephasedData(); td.Start = new DateTime(2018, 1, 4, 8, 0, 0); td.Finish = td.Start.AddHours(8); td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork; td.Value = TimeSpanToTDString(TimeSpan.FromHours(1)); assignment2.TimephasedData.Add(td); td = new TimephasedData(); td.Start = new DateTime(2018, 1, 5, 8, 0, 0); td.Finish = td.Start.AddHours(8); td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork; td.Value = TimeSpanToTDString(TimeSpan.FromHours(1)); assignment2.TimephasedData.Add(td); project.CalcResourceFields(); project.CalcResourceStartFinish(); project.Recalculate(); project.Save(@"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML); project.Save(@"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP); } static private string TimeSpanToTDString(TimeSpan timeSpan) { return string.Format("PT{0}H{1}M{2}S", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); } static private void ClearTimephasedData(ResourceAssignment assignment) { foreach (TimephasedData tph in assignment.TimephasedData.ToList()) assignment.TimephasedData.Remove(tph); }
Result:
Print.png (112.8 KB)
Expected:
Print2.png (79.5 KB)