Comment ajouter des attributs étendus aux affectations de ressources
Contents
[
Hide
Show
]Comme les tâches et les ressources, des attributs étendus peuvent également être ajoutés aux affectations de ressources. Aspose.Tasks pour l’API .NET vous permet d’ajouter des attributs étendus aux affectations de ressources. Des attributs étendus peuvent être ajoutés aux affectations de ressources en tant qu’attributs simples et de recherche.
Ajout d’attributs étendus à l’attribution des ressources
1// Create new project
2Project project = new Project("New Project.mpp");
3
4// Add new task and resource
5Task task = project.RootTask.Children.Add("Task");
6Resource resource = project.Resources.Add("Rsc");
7
8// Assign the resource to the desired task
9ResourceAssignment assignment = project.ResourceAssignments.Add(task, resource);
10
11// Custom attributes which is visible in "Resource Usage" view can be created with ExtendedAttributeDefinition.CreateResourceDefinition method.
12{
13 ExtendedAttributeDefinition resCostAttributeDefinition = ExtendedAttributeDefinition.CreateResourceDefinition(
14 CustomFieldType.Cost,
15 ExtendedAttributeResource.Cost5,
16 "My cost");
17
18 project.ExtendedAttributes.Add(resCostAttributeDefinition);
19
20 var value = resCostAttributeDefinition.CreateExtendedAttribute();
21
22 // The type of the attribute is "Cost", so we need to use "NumericValue" property.
23 value.NumericValue = 1500;
24
25 assignment.ExtendedAttributes.Add(value);
26}
27
28// Custom attributes which is visible in "Task Usage" view can be created with ExtendedAttributeDefinition.CreateTaskDefinition method
29{
30 ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(
31 CustomFieldType.Cost,
32 ExtendedAttributeTask.Cost5,
33 "My cost for task");
34
35 project.ExtendedAttributes.Add(taskCostAttributeDefinition);
36
37 var value = taskCostAttributeDefinition.CreateExtendedAttribute();
38
39 // The type of the attribute is "Cost", so we need to use "NumericValue" property.
40 value.NumericValue = 2300;
41
42 assignment.ExtendedAttributes.Add(value);
43}
44
45project.Save("AddExtendedAttributesToResourceAssignment_out.mpp", SaveFileFormat.MPP);
Adding Lookup Extended Attributes to Resource Assignment
1// Create new project
2Project project = new Project("New Project.mpp");
3
4// Assign resource "1 TRG: Trade Group" to the "TASK 1" by creating a ResourceAssignment object.
5Resource resource = project.Resources.GetById(1);
6Task task = project.RootTask.Children.GetById(1);
7
8ResourceAssignment assignment = project.ResourceAssignments.Add(task, resource);
9
10// Create custom attribute definition with lookup.
11ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition.CreateLookupResourceDefinition(
12 CustomFieldType.Cost,
13 ExtendedAttributeResource.Cost5,
14 "My lookup resource cost");
15project.ExtendedAttributes.Add(resCostAttr);
16
17var value1 = new Value { NumberValue = 1500, Description = "Val 1", Id = 1, Val = "1500" };
18
19resCostAttr.AddLookupValue(value1);
20
21resCostAttr.AddLookupValue(new Value { NumberValue = 2500, Description = "Val 2", Id = 2 });
22
23// This value can be seen in "Resource usage" view of MS Project.
24var attributeValue = resCostAttr.CreateExtendedAttribute(value1);
25assignment.ExtendedAttributes.Add(attributeValue);
26
27// Create custom attribute definition with lookup.
28ExtendedAttributeDefinition taskCostAttr = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
29 ExtendedAttributeTask.Cost4,
30 "My lookup task cost");
31
32project.ExtendedAttributes.Add(taskCostAttr);
33
34var taskLookupValue1 = new Value { NumberValue = 18, Description = "Task val 1", Id = 3, Val = "18" };
35taskCostAttr.AddLookupValue(taskLookupValue1);
36
37resCostAttr.AddLookupValue(new Value { NumberValue = 30, Description = "Task val 2", Id = 4 });
38
39// This value can be seen in "Task usage" view of MS Project.
40assignment.ExtendedAttributes.Add(taskCostAttr.CreateExtendedAttribute(taskLookupValue1));
41
42project.Save("AddExtendedAttributesToRAWithLookUp_out.mpp", SaveFileFormat.MPP);