Sri Lanka .NET 
                Forum Member

Thursday, October 05, 2006

Generate Gantt Project 2.0.2 File

Gantt Project 2.0.2 is a open source project scheduling application written in Java and featuring gantt chart, resource management, calendaring, import/export (MS Project, HTML, PDF, spreadsheets).

Download Gantt Project

After creating a plan when you save it it saves the file as an XML file.There is a specific format to that file and we can generate that file through code using C#.NET.

Below is a sample code for the file generation.

XmlTextWriter tw = new XmlTextWriter("Plan.xml", System.Text.Encoding.UTF8);

tw.Formatting = Formatting.Indented;

tw.WriteStartDocument();

tw.WriteStartElement("project");
tw.WriteAttributeString("name","");
tw.WriteAttributeString("company","");
tw.WriteAttributeString("webLink","");
tw.WriteAttributeString("view-date","year-month-day");
tw.WriteAttributeString("view-index","0");
tw.WriteAttributeString("gantt-divider-location","316");
tw.WriteAttributeString("resource-divider-location","301");
tw.WriteAttributeString("version","2.0");

tw.WriteStartElement("view");
tw.WriteAttributeString("zooming-state","default:2");
tw.WriteEndElement();

tw.WriteStartElement("calendars");
tw.WriteStartElement("day-types");
tw.WriteStartElement("day-type");
tw.WriteAttributeString("id","0");
tw.WriteEndElement();

tw.WriteStartElement("day-type");
tw.WriteAttributeString("id","1");
tw.WriteEndElement();

tw.WriteStartElement("calendar");
tw.WriteAttributeString("id","1");
tw.WriteAttributeString("name","default");

tw.WriteStartElement("default-week");
tw.WriteAttributeString("sun","1");
tw.WriteAttributeString("mon","0");
tw.WriteAttributeString("tue","0");
tw.WriteAttributeString("wed","0");
tw.WriteAttributeString("thu","0");
tw.WriteAttributeString("fri","0");
tw.WriteAttributeString("sat","1");
tw.WriteEndElement();

tw.WriteStartElement("overriden-day-types");
tw.WriteEndElement();

tw.WriteStartElement("days");
tw.WriteEndElement();

tw.WriteEndElement(); // end calendar
tw.WriteEndElement(); // end day types
tw.WriteEndElement(); // end calendars

tw.WriteStartElement("description");
tw.WriteEndElement();

tw.WriteStartElement("tasks");
tw.WriteAttributeString("color","#8cb6ce");

tw.WriteStartElement("taskproperties");

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd0");
tw.WriteAttributeString("name","type");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","icon");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd1");
tw.WriteAttributeString("name","priority");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","icon");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd2");
tw.WriteAttributeString("name","info");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","icon");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd3");
tw.WriteAttributeString("name","name");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","text");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd4");
tw.WriteAttributeString("name","begindate");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","date");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd5");
tw.WriteAttributeString("name","enddate");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","date");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd6");
tw.WriteAttributeString("name","duration");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","int");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd7");
tw.WriteAttributeString("name","completion");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","int");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd8");
tw.WriteAttributeString("name","coordinator");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","text");

tw.WriteEndElement();

tw.WriteStartElement("taskproperty");

tw.WriteAttributeString("id","tpd9");
tw.WriteAttributeString("name","predecessors");
tw.WriteAttributeString("type","default");
tw.WriteAttributeString("valuetype","text");

tw.WriteEndElement();

tw.WriteEndElement();

tw.WriteStartElement("task");
tw.WriteAttributeString("id","13");
tw.WriteAttributeString("name","creating xml file");
tw.WriteAttributeString("shape","0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
tw.WriteAttributeString("meeting","false");
tw.WriteAttributeString("start","2005-11-04");
tw.WriteAttributeString("duration","1");
tw.WriteAttributeString("complete","50");
tw.WriteAttributeString("fixed-start","false");
tw.WriteAttributeString("priority","1");
tw.WriteAttributeString("expand","true");

tw.WriteStartElement("notes");
tw.WriteEndElement();

tw.WriteStartElement("depend");
tw.WriteAttributeString("id","");
tw.WriteAttributeString("type","2");
tw.WriteEndElement();

tw.WriteEndElement(); // end task
tw.WriteEndElement(); // end tasks

tw.WriteStartElement("resources");

tw.WriteStartElement("resource");
tw.WriteAttributeString("id","1");
tw.WriteAttributeString("name","Pasan");
tw.WriteAttributeString("function","SoftwareDevelopment");
tw.WriteAttributeString("contacts","pasan_yasantha@yahoo.co.uk");
tw.WriteAttributeString("phone","0722 133 702");
tw.WriteEndElement();

tw.WriteEndElement(); //end resources

tw.WriteStartElement("allocations");

tw.WriteStartElement("allocation");
tw.WriteAttributeString("task-id","13");
tw.WriteAttributeString("resource-id","1");
tw.WriteAttributeString("load","100.0");
tw.WriteEndElement();

tw.WriteEndElement(); //end allocations

tw.WriteStartElement("vacations");
tw.WriteEndElement();

tw.WriteStartElement("taskdisplaycolumns");

tw.WriteStartElement("displaycolumn");
tw.WriteAttributeString("property-id","tpd3");
tw.WriteAttributeString("order","0");
tw.WriteAttributeString("width","75");
tw.WriteEndElement();

tw.WriteStartElement("displaycolumn");
tw.WriteAttributeString("property-id","tpd4");
tw.WriteAttributeString("order","1");
tw.WriteAttributeString("width","75");
tw.WriteEndElement();

tw.WriteStartElement("displaycolumn");
tw.WriteAttributeString("property-id","tpd5");
tw.WriteAttributeString("order","2");
tw.WriteAttributeString("width","75");
tw.WriteEndElement();

tw.WriteEndElement();

tw.WriteStartElement("previous");
tw.WriteEndElement();

tw.WriteStartElement("roles");
tw.WriteAttributeString("roleset-name","Default");
tw.WriteEndElement();

tw.WriteStartElement("roles");
tw.WriteAttributeString("roleset-name","SoftwareDevelopment");
tw.WriteEndElement();

tw.WriteStartElement("roles");
tw.WriteAttributeString("roleset-name","Operator");
tw.WriteEndElement();

tw.WriteEndElement(); //end project
tw.WriteEndDocument();

tw.Flush();
tw.Close();

No comments: