用代码管理资源
本节给出两个例子,用于学习如何用代码定义和分配资源。
定义资源
下面的代码给项目定义了三种资源,每天300元的人工费,每吨2000元的钢筋,以及600一次的咨询费:
Dim
gv
As
GanttView = e.Form.Controls("GanttView1").GanttView
Dim
rs
As
Gantt.Resource = gv.Resources.AddNew()
rs.ResourceType = Gantt.ResourceType.Work
rs.Cost = 300
rs.Name =
"工人"
rs.UnitOfMeasure =
"天"
rs = gv.Resources.AddNew()
rs.ResourceType = Gantt.ResourceType.Material
rs.Cost = 2000
rs.Name =
"钢筋"
rs.UnitOfMeasure =
"吨"
rs = gv.Resources.AddNew()
rs.ResourceType = Gantt.ResourceType.Cost
rs.Cost = 600
rs.Name =
"咨询"
分配资源
下面的代码给Task1分配了两个资源,分别是30个人工和2吨钢筋:
Dim
gv
As
GanttView = e.Form.Controls("GanttView1").GanttView
Dim
tk
As
Gantt.Task = gv.Tasks.Search("Task1")
Dim
rf
As
New
Gantt.ResourceRef()
rf.Resource = gv.Resources.Search("工人")
rf.Amount = 40
'需要30个人工
tk.ResourceRefs.Add(rf)
rf =
New
Gantt.ResourceRef()
rf.Resource = gv.Resources.Search("钢筋")
rf.Amount = 2
'需要两吨钢筋
tk.ResourceRefs.Add(rf)