最近又重操舊業了。又是 Project Server 2003.
原本的目的,是要讀取 Project Server 上某一專案的實際完成百分比。
下面的方法,原意是使用 Office DOM 來取得專案資訊。
這樣的方法,可以找到許多資料,但怎麼找也找不到實際完成百分比。
static void Main(string[] args)
{
ApplicationClass application = new ApplicationClass();
application.Visible = true;
bool opened = application.FileOpen(@"<>\伺服器上的專案.已發佈",
true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
PjPoolOpen.pjPoolReadOnly, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Project p = application.ActiveProject;
short i = (short) p.PercentComplete; //完成百分比
short i2 = (short)p.PercentWorkComplete; //工時完成百分比
foreach (OutlineCode item in p.OutlineCodes)
Console.WriteLine(item.Name + item.FieldID.ToString()); //大綱
}
注意到上面這一段程式,必須先執行 Project 2003 上連線到 Project Server 後再執行該程式。否則會有錯誤發生。
另外,Project Server 上的專案,必須以 <>\ 開頭來載入,這是比較奇怪的地方
更新!
可以讀取實際完成百分比了。而且也可以指定 status date 哦!程式片斷如下
private static short GetPhysicalPercentComplete(ApplicationClass application, string webProjName,
DateTime statusDate)
{
bool opened = application.FileOpen(webProjName,
true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
PjPoolOpen.pjPoolReadOnly, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Project p = application.ActiveProject;
p.StatusDate = statusDate;
application.CalculateProject();
Thread.Sleep(500);
short physicalPercentComplete = (short)p.Tasks.get_UniqueID(0).PhysicalPercentComplete;
application.FileClose(PjSaveType.pjDoNotSave, true);
return physicalPercentComplete;
}