Version

Managing Project Resources

Topic Overview

Purpose

This topic explains how you create resources available for a project and assign them to the project’s tasks using the xamGantt™ control.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic describes how to add the xamGantt control to a page.

Resources Configuration Summary

Resources configuration summary chart

The following table lists the configurable aspects relating to the resources in the xamGantt control. Additional details follow later in the topic.

Configurable aspect Details Property

Creating a resource and adding it to the project

Initialize a ProjectResource object and Add it to the Project ResourceItems collection.

Assigning a resource to a task

Initialize a ProjectTaskResource object with a resource unique ID as a mandatory parameter and Add it to the ProjectTask Resources collection.

In the Add method, you specify the resource units needed.

Configuring if adding a resource through the xamGantt control user interface automatically create a new resource in the project

Returns or sets a Boolean value indicating the addition of a new ProjectResource to the Project ResourceItems collection when entering an unrecognized resource name into the ProjectTask ResourcesText.

Enabled is the default setting for this operation.

Creating Project’s Resources Collection

Overview

You can create resources and add them to a project’s resource collection in the xamGantt control. After that, you can assign resources to the tasks from the available project’s resources or create new ones via the user interface.

Property settings

The following table maps the example configuration to property settings.

In order to: Use this property/event: And set it to:

Enable/disable adding new resources via the xamGantt UI

bool

Set a resource display name

string

Set a resource unique ID

string

Create a project’s resource collection

Example

The example code below demonstrates how to create a resource, add it the project’s available resources collection and disabling the addition of new resources via the xamGantt UI.

The screenshot illustrates the error tooltip that appears when a user attempts to assign a new unrecognized resource to a task:

Creating Project Resources 1.png

In C#:

ProjectSettings settings = new ProjectSettings();
// Disable adding resources through the xamGantt UI
// and via the ProjectTask ResourcesText property
settings.AutoAddNewResources = false;
this.gantt.Project.Settings = settings;
// Create ProjectResource with display name and unique ID
ProjectResource projectResource = new ProjectResource();
projectResource.DisplayName = "John Smith";
projectResource.UniqueId = "dev-jsmith-45673";
// Add created resource to the project ResourceItems collection
this.gantt.Project.ResourceItems.Add(projectResource);

In Visual Basic:

Dim settings As New ProjectSettings()
' Disable adding resources through the xamGantt UI and via the ProjectTask ResourcesText property
settings.AutoAddNewResources = False
Me.gantt.Project.Settings = settings
' Create ProjectResource with display name and unique ID
Dim projectResource As New ProjectResource()
projectResource.DisplayName = "John Smith"
projectResource.UniqueId = "dev-jsmith-45673"
' Add created resource to the project ResourceItems collection
Me.gantt.Project.ResourceItems.Add(projectResource)

Assigning Project’s Resources to Tasks

Overview

You can create resources and assign them to tasks using the xamGantt control. You may add as many resources to a task as required, but you may not add the same resource more than once to the same tasks.

Property settings

The following table maps the desired configuration to property settings.

In order to: Use this property: And set it to:

Assign a ProjectTaskResource to a task

Example

The example code demonstrates how to assign a resource to the currently active task on a Button Click event. Additionally, it depicts the error dialog box resulting from attempting to assign a resource to a task more than once:

Creating Project Resources 2.png

In C#:

private void Btn_AddResource_Click(object sender, RoutedEventArgs e)
{
  // Create a ProjectTaskResource for the available project resource with specified unique ID
    ProjectTaskResource taskResource = new ProjectTaskResource("dev-jsmith-45673");
    try
    {
        // Assign the resource to the task
        this.gantt.ActiveRow.Value.Task.Resources.Add(taskResource);
    }
    catch (Exception exc)
    {
        // Show a message if an exception occurs
        MessageBox.Show(exc.Message);
    }
}

In Visual Basic:

Private Sub Btn_AddResource_Click(sender As Object, e As RoutedEventArgs)
      ' Create a ProjectTaskResource for the available project resource with specified unique ID
      Dim taskResource As New ProjectTaskResource("dev-jsmith-45673")
      Try
            ' Assign the resource to the task
            Me.gantt.ActiveRow.Value.Task.Resources.Add(taskResource)
      Catch exc As Exception
            ' Show a message if an exception occurs
            MessageBox.Show(exc.Message)
      End Try
End Sub

Handling Missing Resource Event

Overview

This example demonstrates error handling in the event that a user attempts to enter an unrecognized resource that is not included as part of the project’s available resources.

Use the Project MissingResourceWarning event and handle it to process this error.

Event settings

In order to: Use this event:

Handle the entering of an unrecognized resource string in the xamGantt UI

when forbidden by its configuration (AutoAddNewResources property is set to False).

Example

The example below demonstrates how to handle the addition of an unrecognized resource error event:

In C#:

…
this.gantt.Project.MissingResourceWarning +=
new EventHandler<MissingResourceWarningEventArgs>(Project_MissingResourceWarning);
…

In C#:

private void Project_MissingResourceWarning(object sender, MissingResourceWarningEventArgs e)
{
    // Show a message if an exception occurs
    MessageBox.Show(string.Format("The {0} resource is an unrecognized resource.", e.ResourceName));
}

In Visual Basic:

…
Me.gantt.Project.MissingResourceWarning = New EventHandler(Of MissingResourceWarningEventArgs)(Project_MissingResourceWarning)
…

In Visual Basic:

Private Sub Project_MissingResourceWarning(sender As Object, e As MissingResourceWarningEventArgs)
      ' Show a message if an exception occurs
      MessageBox.Show(String.Format("The {0} resource is an unrecognized resource.", e.ResourceName))
End Sub

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic describes how to create a custom resource class and use it with xamGantt .