项目管理工具----普加项目管理中间件(PlusProject )入门教程(11):msProject项目的导入和导出(中)

58 阅读1分钟

普加项目管理中间件是用于跨浏览器和跨平台应用程序的功能齐全的 Gantt 图表,可满足项目管理应用程序的所有需求,是最完善的甘特图图表库。

.net下可以导入xml和.mpp,微软提供了Microsoft.Office.Interop.MSProject.dll,可以将mpp文件转换成xml格式,我们提供了Plusoft.dll对xml文件进行了解析处理,转换成可读的格式存入到数据库中。

private static HashMap getObjectFromXML(Element root) throws Exception {

NodeList lst = root.getChildNodes();

HashMap hs = new HashMap();

if (lst == null){

return null;

}

for (int it = 0; it <  lst.getLength(); it++){

Node nd = lst.item(it);

NodeList tmp = nd.getChildNodes();

String name = nd.getNodeName();

String value =  null;

if(tmp != null && tmp.item(0) != null){

value = tmp.item(0).getNodeValue();

}

//String

if( name.equals("UID")

|| name.equals("Name")

|| name.equals("CalendarUID")

|| name.equals("DefaultStartTime")

|| name.equals("DefaultFinishTime")

){

hs.put(name, value);

}

//Int

if( name.equals("MinutesPerDay")

|| name.equals("MinutesPerWeek")

|| name.equals("DaysPerMonth")

|| name.equals("WeekStartDay")

){

hs.put(name, toInt(value));

}

//Date

if( name.equals("CreationDate")

|| name.equals("LastSaved")

|| name.equals("StartDate")

|| name.equals("FinishDate")

){

hs.put(name, parseDate(value));

}

if( name.equals("Calendars")){

hs.put(name, getCalendars(nd));

}

if( name.equals("Assignments")){

hs.put(name, getAssignments(nd));

}

if( name.equals("Resources")){

hs.put(name, getResources(nd));

}

if( name.equals("Tasks")){

hs.put(name, getTasks(nd));

}

//ExtendedAttributes

if(name.equals("ExtendedAttributes")){

hs.put("ExtendedAttributes", getNodesList(nd));

}

//OutlineCodes

if(name.equals("OutlineCodes")){

ArrayList list = new ArrayList();

NodeList node_list = nd.getChildNodes();

for (int i = 0; i < node_list.getLength(); i++){

NodeList child = node_list.item(i).getChildNodes();

if (child.getLength() > 0){

//OutlineCode

HashMap o = new HashMap();

for (int j = 0; j < child.getLength(); j++){

Node _node = child.item(j);

String nodeName = _node.getNodeName();

putNodeValue(o, _node);

if(nodeName.equals("Masks")){

o.put("Masks", getNodesList(_node));

}

if(nodeName.equals("Values")){

o.put("Values", getNodesList(_node));

}

}

list.add(o);

}

}

hs.put("OutlineCodes", list);

}

}

        //Calendars

        ArrayList calendars = (ArrayList)hs.get("Calendars");

        for(int i=0,l=calendars.size(); i<l; i++)

        {

         HashMap calendar = (HashMap)calendars.get(i);                             

            ArrayList WeekDays = (ArrayList)calendar.get("WeekDays");            

            if(WeekDays == null) continue;

            ArrayList Exceptions = (ArrayList)calendar.get("Exceptions");          

            if(Exceptions == null){

             Exceptions = new ArrayList();

             calendar.put("Exceptions", Exceptions);

            }

            for (int j = WeekDays.size() - 1; j >= 0; j--)

            {

             HashMap weekday = (HashMap)WeekDays.get(j);

                if (weekday.get("DayType") == null || weekday.get("DayType").toString().equals("0"))

                {

                    //Exceptions.add(weekday);

                    WeekDays.remove(weekday);

                }

            }

        }        

        if (calendars != null && calendars.size() > 0 && (hs.get("CalendarUID") == null || hs.get("CalendarUID").toString().equals("null")))

        {

            hs.put("CalendarUID", ((Map)calendars.get(0)).get("UID"));

        }

        

return hs;

}