c# - MS Project - 禁用资源
问题描述
我正在创建一个 Microsoft Project 加载项。根据资源的自定义文本列的值(例如 Text30),我可以在尝试将资源分配给任务时禁用资源显示吗?
因此,例如,如果一行的 Text30 值为Inactive
,则项目文件用户不应将其分配给任务,但它仍应位于资源表中。下面,第 1 行可用作资源,而在将资源分配给任务时,第 2 行不会显示。
解决方案
在 Rachel 的链接问题的帮助下,我设法找到了解决方法。我添加了一个名为 Active Status 的 Text 列(Text30
在我的例子中)。然后,使用Application.ProjectBeforeTaskChange
我检查新值是否是具有Text30
value 列的资源Active
。这是 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”,程序将不允许用户将资源添加到任务。
注意:
仅当您通过甘特图分配资源时才会触发此事件。如果您通过Resource 选项卡 -> Assign Resource进行分配,则不会触发该事件。该事件ProjectBeforeAssignmentNew
将通过分配资源和甘特图触发。唯一的缺点是我没有找到一种方法来访问通过ProjectBeforeAssignmentNew
事件更改的值。你可以在这里找到活动。
推荐阅读
- python - 为什么内置函数在 python 中没有被归类为可调用函数,如何让它们在我的程序中显示为可调用函数?
- r - R:循环删除 NA 只删除一些 NA?
- kotlin - 在 Kotlin 中使用委托实现时传递此引用
- azure - Azure Bot 框架 AAD 身份验证问题
- typescript - Typescript - 推断函数是否被柯里化
- mysql - 仅在选择中更改用户电子邮件地址格式
- ios - 摇动手势后从 SKScene 中选择随机元素
- python-3.x - ModuleNotFound 导致 502 在 aws lambda 上使用 zappa 部署 django
- javascript - 分配给 window.location 的代码是否容易受到 XSS 攻击?
- python - Django - 与系统不同 - 如何更改按钮颜色以不喜欢?