我在尝试使用库 MPXJ 将资源分配给任务和子任务时遇到问题。实际上,当我将资源分配给子任务时,所有任务持续时间都被修改了,我不明白为什么。如果我不分配资源,则持续时间设置得很好(每个子任务 4 天),但是当我这样做时,为 0。
谁能帮我理解为什么?这是VB.net中的代码,我用c#试过,同样的问题:
Dim xmlwriter As New MSPDIWriter
Dim projectfile As New ProjectFile
Dim personcount = 1
Dim pre As Task = Nothing
'Filling file file with some dummy data
For i As Integer = 1 To 10
Dim task As Task = projectfile.addTask
task.setName("Example Task" & i)
Dim presub As Task = Nothing
'Add some subtasks
For j As Integer = 1 To 10
Dim subtask As Task = task.addTask()
subtask.setName("Sub Task" & j)
'Set the subtasks duration = ' hours for every sub task
subtask.setDuration(Duration.getInstance(4, TimeUnit.DAYS))
'add Resources to the subtask = one resource for every task ^^
' 1) add resource to the general projectfile
Dim res As Resource = projectfile.addResource()
res.setName("person" & personcount)
personcount += 1
'Asociate the resource with the courent task
Dim assgmnt As ResourceAssignment = subtask.addResourceAssignment(res)
'Concatenate the subtasks, so that one subtask is performed after
'another in the timeline
'The first task has no predecessor
If j = 1 Then
presub = subtask
Else
subtask.addPredecessor(presub, RelationType.FINISH_START, Duration.getInstance(0, TimeUnit.DAYS))
presub = subtask
End If
'presub.setDuration(Duration.getInstance(4, TimeUnit.DAYS))
Next
'Concatenate the tasks, son that one main task is performed after
'another on the timeline
'The first task has no predecessor,
If i = 1 Then
'set the start date of the project
Dim rightnow As java.util.Calendar = java.util.Calendar.getInstance()
rightnow.set(2014, 11, 1)
task.setStart(rightnow.getTime())
pre = task
Else
task.addPredecessor(pre, RelationType.FINISH_START, Duration.getInstance(0, TimeUnit.DAYS))
pre = task
End If
Next
'Writng the project file
xmlwriter.write(projectfile, "C:\temp\exo.xml")
谢谢!