We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Split Task problem

Hi
What is best practice for create an split Task,because when I read task data from db , add them to Task,aspose Change Start & Finish Date

                Project prj = new Project();
prj.StartDate = DateTime.Parse(“30-APR-2014”);
Task task = prj.AddTask(“Task1”);
            task.DurationFormat = <span style="color:#2b91af;">TimeUnitType</span>.Day;
            task.Duration = <span style="color:blue;">new</span> <span style="color:#2b91af;">TimeSpan</span>(0, 2400, 0);
            task.Start = <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"30-APR-2014"</span>);
            task.Finish = <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"07-MAY-2014"</span>);
            task.IsManual = <span style="color:blue;">false</span>;


            <span style="color:blue;">var</span> splitResourceAssignment = prj.AddResourceAssignment(task, <span style="color:blue;">null</span>);
            splitResourceAssignment.Start = task.Start;
            splitResourceAssignment.Finish = task.Finish;
            splitResourceAssignment.WorkContour = <span style="color:#2b91af;">WorkContourType</span>.Contoured;
            <span style="color:green;">//Generate resource assignment timephased data</span>
            <span style="color:blue;">if</span> (task.Calendar != <span style="color:blue;">null</span> || prj.Calendar != <span style="color:blue;">null</span>)
            {
                <span style="color:blue;">var</span> calendar = prj.Calendar ?? (task.Calendar);
                <span style="color:blue;">if</span> (calendar != <span style="color:blue;">null</span>)
                {
                    splitResourceAssignment.TimephasedDataFromTaskDuration(calendar);
                    <span style="color:blue;">try</span>
                    {
                        splitResourceAssignment.SplitTask(<span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"30-APR-2014"</span>), <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"01-MAY-2014"</span>), calendar);
                        splitResourceAssignment.SplitTask(<span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"04-MAY-2014"</span>), <span style="color:#2b91af;">DateTime</span>.Parse(<span style="color:#a31515;">"07-MAY-2014"</span>), calendar);
                    }
                    <span style="color:blue;">catch</span>
                    {

                    }
                }
            }</pre><br>all data came from db (actually msp calculate them ) here I have a split task start from <pre style="font-family:Consolas;font-size:13;color:black;background:white;"><span style="color:#a31515;">"30-APR-2014" </span>& end at <span style="color:#a31515;">"07-MAY-2014" , </span>task duration is 5 days and 2 days between 2 part of task<br>one of day is nonworking , but final file wasn't what i want<br>thank for your help<span style="color:#a31515;"></span></pre><br>

Hi Pazoki,


We are sorry for the delayed response. We are working on this issue and will share our findings shortly. Thank you for your patience in this regard.

Hi Pazoki,


I have analyzed your code and would like to share that we just need to add one split interval that is May 01, 2014. The Saturday and Sunday are taken off by default. Also as resource assignments are modified, you may call CalcResourceAssignmentIds() and CalcResourceAssignmentUids() at the end.

Could you please give a try to the following sample code which generates the file as per your requirement and let us know your feedback?

//Create new project
Project splitTaskProject = new Project();
Aspose.Tasks.Calendar calendar = splitTaskProject.Calendar;
splitTaskProject.StartDate = new DateTime(2014, 4, 30, 8, 0, 0);

//Add a new task
Task taskToSplit = splitTaskProject.AddTask(“Task1”);
taskToSplit.Start = new DateTime(2014, 4, 30, 8, 0, 0);
taskToSplit.Duration = new TimeSpan(40, 0, 0);
taskToSplit.Finish = calendar.GetFinishDateByStartAndWork(taskToSplit.Start, taskToSplit.Duration);
taskToSplit.DurationFormat = TimeUnitType.Day;

//Set the parent project for calculation.
taskToSplit.ParentProject = splitTaskProject;

//Create a new resource assignment
ResourceAssignment splitResourceAssignment = new ResourceAssignment(taskToSplit, null);
splitTaskProject.ResourceAssignments.Add(splitResourceAssignment);
splitResourceAssignment.Start = taskToSplit.Start;
splitResourceAssignment.Finish = taskToSplit.Finish;

//Generate resource assignment timephased data
splitResourceAssignment.TimephasedDataFromTaskDuration(calendar);

//Split the task into 2 parts.
//Provide start date and finish date arguments to SplitTask method
//These dates will be used for split
splitResourceAssignment.SplitTask(new DateTime(2014, 5, 1, 8, 0, 0), new DateTime(2014, 5, 1, 17, 0, 0), calendar);

splitResourceAssignment.WorkContour = WorkContourType.Contoured;

//Calculate project IDs
splitTaskProject.CalcResourceAssignmentIds();
splitTaskProject.CalcResourceAssignmentUids();

//Save the Project
splitTaskProject.Save(“Project3.Xml”, Aspose.Tasks.Saving.SaveFileFormat.XML);

Hi Kashif Iqbal
Thank for your reply
As I said I’m writing a program that load some MSP related data from db and Create a msp file , so end user can manipulate generated file and then update db , your sample code somehow generate my file , but cause I read data form db so really I don’t need e.g call GetFinishDateByStartAndWork because finish date of task has been calculated by msp and insert to db.
If User Manually Split Tasks our code is fine either your code , but when user change actual data or change Resources or Level project then problem starts,am I miss something about split task ?
The attached file contain one of our generated files (a sample) , I write a tiny program that open this file and report task data , one of difference between Office automation & Aspose Task is that , last task is split but aspose said not .
Thank for your help

Hi Pazoki,


Thank you for providing more detail.

Earlier it was assumed that sample is required to create split task, therefore above mentioned sample code is suggested.

For investigating the SplitParts count issue, I have written a small piece of code to display the SplitParts count of each task in the sample file and observed that it does not display proper value of SplitParts count for last task. This issue is logged in our issue tracking system under id:TASKS-33622.

We will write back here as soon as some feedback is received for the above mentioned ticket. Please feel free to write us back if you have any other query related to Aspose.Tasks.

The issues you have found earlier (filed as TASKS-33622) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.