Hi
I’m using aspose task 6.3.0 & I want to add some resource assignment programmatically(actually i read data from database), so use the following sample code here, but result wasn’t what I want (a simple file with 2 task & 2 resource ), if you use the code the final file doesn’t assign resource properly so I modify it & new source was what i want
Project prj = new Project();<span style="color:#2b91af;">Task</span> tskRoot = <span style="color:blue;">new</span> <span style="color:#2b91af;">Task</span>(); <span style="color:#2b91af;">Task</span> tsk1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">Task</span>(<span style="color:#a31515;">"Task1"</span>); <span style="color:#2b91af;">Task</span> tsk2 = <span style="color:blue;">new</span> <span style="color:#2b91af;">Task</span>(<span style="color:#a31515;">"Task2"</span>); tsk1.DurationFormat = <span style="color:#2b91af;">TimeUnitType</span>.Day; tsk1.Duration = <span style="color:blue;">new</span> <span style="color:#2b91af;">TimeSpan</span>(0, 0, 480, 0); tsk1.ManualDuration = tsk1.Duration; tsk1.Start = <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"18-Aug-2009 8:00 AM"</span>); tsk2.DurationFormat = <span style="color:#2b91af;">TimeUnitType</span>.Day; tsk2.Duration = <span style="color:blue;">new</span> <span style="color:#2b91af;">TimeSpan</span>(0, 0, 480, 0); tsk2.ManualDuration = tsk2.Duration; tsk2.Start = <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"18-Aug-2009 8:00 AM"</span>); <span style="color:#2b91af;">Resource</span> res = <span style="color:blue;">new</span> <span style="color:#2b91af;">Resource</span>(); <span style="color:#2b91af;">Resource</span> res1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">Resource</span>(<span style="color:#a31515;">"Resource1"</span>); <span style="color:#2b91af;">Resource</span> res2 = <span style="color:blue;">new</span> <span style="color:#2b91af;">Resource</span>(<span style="color:#a31515;">"Resource2"</span>); <span style="color:#2b91af;">ResourceAssignment</span> ra1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">ResourceAssignment</span>(tsk1, res1); ra1.Start = <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"18-Aug-2009 8:00 AM"</span>); ra1.Finish = <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"18-Aug-2009 5:00 PM"</span>); ra1.Uid = 1; <span style="color:#2b91af;">ResourceAssignment</span> ra2 = <span style="color:blue;">new</span> <span style="color:#2b91af;">ResourceAssignment</span>(tsk2, res2); ra2.Start = <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"19-Aug-2009 8:00 AM"</span>); ra2.Finish = <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"19-Aug-2009 5:00 PM"</span>); ra2.Uid = 2; prj.RootTask = tskRoot; prj.RootTask.Children.Add(tsk1); prj.RootTask.Children.Add(tsk2); <span style="background-color: rgb(255, 255, 0);">prj.Resources.Add(res);</span><span style="color:green;">//1</span> prj.Resources.Add(res1); prj.Resources.Add(res2); <span style="background-color: rgb(255, 255, 0);">prj.AddResourceAssignment(tsk1, res1)</span>;<span style="color:green;">//2</span> <span style="color:green;">//prj.ResourceAssignments.Add(ra1); //3</span> prj.ResourceAssignments.Add(ra2); prj.CalcResourceUids(); prj.CalcTaskIds(); prj.CalcTaskUids(); prj.CalcResourceUids(); prj.CalcResourceStartFinish(); prj.CalcResourceIds(); prj.CalcResourceFields(); prj.CalcResourceAssignmentUids(); prj.CalcResourceAssignmentIds(); prj.UpdateReferences(); <span style="color:green;">//Save the Project</span> prj.Save(<span style="color:#a31515;">"C:\\testres.xml"</span>, Aspose.Tasks.Saving.<span style="color:#2b91af;">SaveFileFormat</span>.XML);<br><br>if comment the line that add empty resource "res" to prj final file is buggy(\\1)<br>if use <span style="background-color: rgb(255, 255, 0);">ResourceAssignments.Add</span> for both resource "res1" & "res2" final file is buggy<br>for desired file you must add first assignment with <span style="background-color: rgb(255, 255, 0);">AddResourceAssignment</span> and the others with <br><span style="background-color: rgb(255, 255, 0);">ResourceAssignments.Add</span> in other case task's duration is 0 or assignment didn't work<br>Thank for your help<br><br></pre><br><a href="http://docs.aspose.com:8082/docs/display/tasksnet/General+Resource+Assignment+Properties"></a>