Sri Lanka .NET 
                Forum Member

Tuesday, October 10, 2006

Create Graphs

UDraw(Graph) is a free software which we can use to generate graphs.After creating a graph it creates a file call fileName.udg with a specific format.

Example Image :



Download Software

We can use a XML file to create above graph through C# code.

Sample XML File :



FlooringSaw
Flooring
Saw
FlooringDry
1
1/1/1900 12:00:00 AM


FlooringDry
Flooring
Dry
FlooringPlane
2
1/1/1900 12:00:00 AM


FlooringPlane
Flooring
Plane
FlooringSize
3
1/1/1900 12:00:00 AM


FlooringSize
Flooring
Size
FlooringAssemble
4
1/1/1900 12:00:00 AM


FlooringAssemble
Flooring
Assemble
FlooringFinish
5
1/1/1900 12:00:00 AM


FlooringFinish
Flooring
Finish
ROOT
6
1/1/1900 12:00:00 AM



Code to display the graph :

DataSet dsUDG = new DataSet();
dsUDG.ReadXml("Services.xml");

DataRow []servOprs = dsUDG.Tables["ServiceOperation"].Select("ServiceName = 'Flooring'");

StreamWriter sw = new StreamWriter("servOprs.udg");

sw.WriteLine("[l");

for(int i = 0;i < servOprs.Length;i++)
{
if(servOprs[i]["ParentServOprsID"].ToString() != "ROOT")
{
DataRow []temp = dsUDG.Tables["ServiceOperation"].Select("ServOprsID = '"+servOprs[i]["ParentServOprsID"].ToString()+"'");

if(i != 0)
{
sw.WriteLine("l("+va+"_"+servOprs[i]["OperationName"].ToString()+va+",n("+va+"node"+va+",[a("+va+"_GO"+va+","+va+"ellipse"+va+"),a("+va+"OBJECT"+va+","+va+servOprs[i]["OperationName"].ToString()+va+"),a("+va+"COLOR"+va+","+va+"lightred"+va+"),a("+va+"INFO"+va+","+va+va+")],");
}
else
{
sw.WriteLine("("+va+"_"+servOprs[i]["OperationName"].ToString()+va+",n("+va+"node"+va+",[a("+va+"_GO"+va+","+va+"ellipse"+va+"),a("+va+"OBJECT"+va+","+va+servOprs[i]["OperationName"].ToString()+va+"),a("+va+"COLOR"+va+","+va+"lightred"+va+"),a("+va+"INFO"+va+","+va+va+")],");
}

if(temp.Length != 0)
{
sw.WriteLine("[l("+va+"@"+servOprs[i]["OperationName"].ToString()+va+",e("+va+"edge"+va+",[a("+va+"EDGEPATTERN"+va+","+va+"single;solid;1;0"+va+"),a("+va+"OBJECT"+va+","+va+va+"),a("+va+"FONTSTYLE"+va+","+va+"bold"+va+"),a("+va+"INFO"+va+","+va+va+")],");
}
}
else
{
sw.WriteLine("l("+va+"_"+servOprs[i]["OperationName"].ToString()+va+",n("+va+"node"+va+",[a("+va+"_GO"+va+","+va+"ellipse"+va+"),a("+va+"OBJECT"+va+","+va+servOprs[i]["OperationName"].ToString()+va+"),a("+va+"COLOR"+va+","+va+"lightblue"+va+"),a("+va+"INFO"+va+","+va+va+")],[]");
}
}

for(int k = 0;k < servOprs.Length-1;k++)
{
sw.WriteLine("))))]");
}

sw.WriteLine("))]");

sw.Close();

No comments: