【问题标题】:MS Project - Disable resourceMS Project - 禁用资源
【发布时间】:2021-07-07 14:43:51
【问题描述】:

我正在创建一个 Microsoft Project 加载项。根据资源的自定义文本列的值(比如 Text30),我可以在尝试将资源分配给任务时禁止资源显示吗?

例如,如果一行的 Text30 值为 Inactive,则项目文件用户不应将其分配给任务,但仍应位于资源表中。下面,第 1 行将作为资源可用,而将资源分配给任务时,第 2 行不会显示。

【问题讨论】:

标签: c# vb.net vsto ms-project


【解决方案1】:

在 Rachel 的链接问题的帮助下,我设法找到了解决方法。我添加了一个名为“活动状态”的文本列(在我的情况下为Text30)。然后,使用Application.ProjectBeforeTaskChange 检查新值是否是具有列Text30 的值Active 的资源。 Here 是 MS Project 活动的链接。下面是代码:

Imports Microsoft.Office.Interop.MSProject

Private Sub Application_ProjectBeforeTaskChange(tsk As Task, Field As PjField, NewVal As Object, ByRef Cancel As Boolean) Handles Application.ProjectBeforeTaskChange

    CheckResourceValidity(NewVal, Cancel)

End Sub


Private Sub CheckResourceValidity(NewVal As Object, ByRef Cancel As Boolean)

    Dim res As Resource
    Dim newValList = NewVal.Split(",")

    If Not IsStartup(newValList) Then

        For Each splitNewVal In newValList
            ' currentProject is the currently active Project
            res = currentProject.Resources.Item(splitNewVal)

            If splitNewVal = res.Name Then

                If res.Text30 <> "Active" Then
                    MessageBox.Show("You are trying to assign an inactive resource to a task. Please choose an active resource.",
                                    "Assigning inactive resource", MessageBoxButtons.OK, MessageBoxIcon.Error)

                    Cancel = True
                End If

            End If
        Next

    End If

End Sub


' The event ProjectBeforeTaskChange is called when a .mpp file with data inside is opened
Private Function IsStartup(newValList As Object) As Boolean

    Dim res As Resource

    For Each x In newValList

        Try
            res = GlobalVariables.currentProject.ProjResources.Item(x)
        Catch ex As System.Runtime.InteropServices.COMException
            Return True
        End Try

    Next

    Return False

End Function

如果资源的 Text30 值不为“Active”,程序将不允许用户将资源添加到任务中。

注意: 仅当您通过甘特图分配资源时才会触发此事件。如果您通过资源选项卡 -> 分配资源进行分配,则不会触发该事件。事件ProjectBeforeAssignmentNew 将通过分配资源 和甘特图触发。唯一的缺点是我没有找到一种方法来访问通过ProjectBeforeAssignmentNew 事件更改的值。您可以找到活动here

【讨论】:

    猜你喜欢
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2014-11-11
    • 2014-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    相关资源
    最近更新 更多