0

大家,早安,

有谁知道如何使用 MPXJ v5.1.5 有效地阅读 MPP。项目文件以获取链接到其分配的任务的大纲代码值。

我已经找到了一种获取任务和时间尺度数据的方法,但是我如何找出哪些大纲代码或自定义字段与任何任务相关联?这将有助于创建有关这些自定义字段的运行情况的报告。

这是我用于检索任务及其时间尺度数据的主要代码。这段代码在后台工作人员上运行并报告进度。

    void Work_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                Document_Details_To_Open Document_Selected_Details = e.Argument as Document_Details_To_Open;
                ProjectReader reader = ProjectReaderUtility.getProjectReader(Document_Selected_Details.FileName);

                MPXJ.ProjectFile mpx = reader.read(Document_Selected_Details.FileName);

                int count = mpx.AllTasks.Size();
                int stepsize = 100002 / count;
                int pos = 1;

                foreach (MPXJ.Task task in mpx.AllTasks.ToIEnumerable())
                {
                    Task_Type task_ = new Task_Type()
                    {
                        Name = task.Name,
                        Total_Days = task.Duration.toString(),
                        ID = task.ID.toString()
                    };

                    //Task.getFieldByAlias()

                    //can add task above to MVVM connection
                    foreach (MPXJ.ResourceAssignment Resource in task.ResourceAssignments.ToIEnumerable())//this will only run once per task , I use the ResourceAssignment variable to get the duration data
                    {

                        //use the selected document details given
                        Dictionary<string, java.util.List> worklist = new Dictionary<string, java.util.List>();
                        foreach (string Work_type in Document_Selected_Details.Data_To_Import)
                        {
                            worklist.Add(Work_type, Get_Some_work(Resource, Work_type));
                        }

                        int Length_of_data_to_retrieve = Get_Time_Scale_int(Document_Selected_Details.Time_Scale_Units, task.Duration.Duration);

                        TimescaleUtility TimeScale = new TimescaleUtility();
                        java.util.ArrayList datelist = TimeScale.CreateTimescale(task.Start, Get_Scale_Type(Document_Selected_Details.Time_Scale_Units), Length_of_data_to_retrieve);
                        MPXJ.ProjectCalendar calendar = Resource.Calendar;
                        TimephasedUtility utility = new TimephasedUtility();

                        Dictionary<string, java.util.ArrayList> durationlist = new Dictionary<string, java.util.ArrayList>();
                        foreach (KeyValuePair<string, java.util.List> item in worklist)
                        {
                            java.util.ArrayList duration = utility.SegmentWork(calendar, item.Value, Get_Scale_Type(Document_Selected_Details.Time_Scale_Units), datelist);
                            durationlist.Add(item.Key, duration);
                        }

                        Dictionary<string, List<string>> ssss = new Dictionary<string, List<string>>();
                        foreach (var s in durationlist)
                        {
                            string key = s.Key;
                            List<string> Hours = new List<string>();
                            foreach (var hours in s.Value.toArray().ToList())
                            {
                                Hours.Add(hours.ToString());
                            }
                            ssss.Add(key, Hours);
                        }

                        Task_With_All all = new Models.Task_With_All()
                        {
                            Task_Name = task.Name,
                            Time_Step_Type = Document_Selected_Details.Time_Scale_Units,
                            Duration_List = ssss,
                            StartDate = task.Start.ToDateTime().ToString(),
                            Total_duration = Length_of_data_to_retrieve.ToString()
                        };
                        Task_With_All_list.Add(all);
                        //I have now every task and their Time scale data but I still need to know if the tasks could have custom fields connected or not

                    }
                    pos += stepsize;
                    Work.ReportProgress(pos);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

任何帮助将不胜感激。

4

1 回答 1

0

感谢 Jon Iles,关于如何获取任务大纲代码的答案变得非常简单。在 MS Project 中,用户可以分配给任务的大纲代码限制为 10 个。要使用 MPXJ v5.1.5 获取已分配给任务的这些大纲代码,您可以使用它来获取它们:

//this code comes from my code block in the question.
...
foreach (MPXJ.Task task in mpx.AllTasks.ToIEnumerable())
{
    //if the string values retrieved from these has a valid value that's returned, that value is the Outline Code assigned to the task 
    string Outline_code_1  = task.GetOutlineCode(1);
    string Outline_code_2  = task.GetOutlineCode(2);
    string Outline_code_3  = task.GetOutlineCode(3);
    string Outline_code_4  = task.GetOutlineCode(4);
    string Outline_code_5  = task.GetOutlineCode(5);
    string Outline_code_6  = task.GetOutlineCode(6);
    string Outline_code_7  = task.GetOutlineCode(7);
    string Outline_code_8  = task.GetOutlineCode(8);
    string Outline_code_9  = task.GetOutlineCode(9);
    string Outline_code_10 = task.GetOutlineCode(10);
}
...
于 2015-09-07T10:16:57.443 回答