<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
Uv public class ImportTasks
{
ApplicationClass projectApp = new ApplicationClass();
private object oMissing = System.Reflection.Missing.Value;
private object objFalse = false;
private Hashtable taskArray = new Hashtable();
private Hashtable itemArray;
private Hashtable taskReturn = new Hashtable();
public bool ImportMppFile(string srcFile)
{
//判断文件是否存在
if (!File.Exists(srcFile))
{
MessageState.SetMessageBox(MSG._FILE_NOT_EXIST, MessageType.Alert);
return false;
}
//检查问价是否是MS Project 文件
string ext = Path.GetExtension(srcFile).ToLower();
if (ext.IndexOf("mpp") == -1)
{
MessageState.SetMessageBox(MSG._FILE_NOT_FIT, MessageType.Alert);
return false;
}
try
{
projectApp.FileOpen(srcFile, objFalse, PjMergeType.pjDoNotMerge, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, PjPoolOpen.pjDoNotOpenPool, oMissing, oMissing, oMissing, oMissing);
}
catch
{
MessageState.SetMessageBox(MSG._FILE_NOT_FIT, MessageType.Alert);
return false;
}
int j = 0;
foreach (Project pro in projectApp.Projects)
{
foreach (Task ts in pro.Tasks)
{
itemArray = new Hashtable();
itemArray.Add("Name", ts.Name);
itemArray.Add("ID", ts.ID);
itemArray.Add("OutlineLevel", ts.OutlineLevel);
itemArray.Add("Start", ts.Start);
itemArray.Add("Finish", ts.Finish);
itemArray.Add("WBS", ts.WBS);
itemArray.Add("PredecessorLink", ts.Predecessors);
itemArray.Add("PercentComplete", ts.PercentComplete);
itemArray.Add("ActualStart", ts.ActualStart);
itemArray.Add("ActualFinish", ts.ActualFinish);
itemArray.Add("Status", ts.Status);
itemArray.Add("Milestone", ts.Milestone);
itemArray.Add("Description", ts.Notes);
taskArray.Add(j, itemArray);
j++;
}
}
projectApp.FileCloseAll(PjSaveType.pjDoNotSave);
System.Runtime.InteropServices.Marshal.ReleaseComObject(projectApp);
return true;
}