Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) Create a Flowchart Diagram dynamically by reading the values/dependency from Oracle Database (Read 17216 times)
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Create a Flowchart Diagram dynamically by reading the values/dependency from Oracle Database
Reply #15 - Jun 10th, 2015 at 7:42pm
Print Post  
I've installed Oracle DB Express and played with following tables:

JOBS { ID, NAME }
DEPENDENCIES { ID, PARENT_JID, DEP_JID }

This code seems to select graph subset correctly, though I'm not sure if it's the most efficient way to implement that:

Code
Select All
var connection = new OracleConnection(
	@"User Id=mindfusion;Password=password_min;Data Source=//localhost:1521/xe");
connection.Open();

var rect = new RectangleF(0, 0, 30, 20);
int parentID = 1;
int depth = 4;

// create node for the root job
OracleCommand parentCommand = connection.CreateCommand();
parentCommand.CommandText = string.Format(
	"select * from JOBS where ID={0}", parentID);

OracleDataReader parentReader = parentCommand.ExecuteReader();
while (parentReader.Read())
{
	var node = diagram.Factory.CreateShapeNode(rect);
	node.Id = parentReader.GetInt32(0);
	node.Text = parentReader.GetString(1);
}

// create nodes for dependencies found up to given depth in hierarchy
OracleCommand jobsCommand = connection.CreateCommand();
jobsCommand.CommandText = string.Format(
	"select JOBS.ID, JOBS.NAME, DEPENDENCIES.PARENT_JID, DEPENDENCIES.DEP_JID, LEVEL " +
	"from JOBS inner join DEPENDENCIES on JOBS.ID=DEPENDENCIES.DEP_JID " +
	"where LEVEL<{0} " +
	"start with DEPENDENCIES.PARENT_JID={1} " +
	"connect by prior DEPENDENCIES.DEP_JID=DEPENDENCIES.PARENT_JID",
	depth, parentID);

OracleDataReader jobsReader = jobsCommand.ExecuteReader();
while (jobsReader.Read())
{
	int parentId = jobsReader.GetInt32(2);
	int childId = jobsReader.GetInt32(3);
	var parent = diagram.FindNodeById(parentId);
	var child = diagram.FindNodeById(childId);
	if (child == null)
	{
		child = new ShapeNode(diagram)
		{
			Id = childId,
			Text = jobsReader.GetString(1),
			Bounds = rect
		};
		diagram.Nodes.Add(child);
	}
	diagram.Factory.CreateDiagramLink(parent, child);
}

var layout = new LayeredLayout();
layout.Arrange(diagram);

connection.Close(); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
SE
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Jun 5th, 2015
Re: Create a Flowchart Diagram dynamically by reading the values/dependency from Oracle Database
Reply #16 - Jun 15th, 2015 at 2:31pm
Print Post  
Good Morning!

Now I have a query that results with hierarchical subsets for a particular job. and I am able to form the graph depends on that.

But the nodes which are not present by the result set also shown in the flowchart as lonely nodes. please refer the attached image. Job B, A and C1 should not be in the graph as per the result set even though it exists in the dependency table.

Can you please help.
« Last Edit: Jun 15th, 2015 at 3:43pm by SE »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Create a Flowchart Diagram dynamically by reading the values/dependency from Oracle Database
Reply #17 - Jun 15th, 2015 at 2:46pm
Print Post  
Hi,

Do you still keep the loop from first code example that creates nodes from "select * from Jobs" results? You should remove that now, as the Dependencies loop from last example creates nodes when necessary (the diagram.Nodes.Add part)

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
SE
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Jun 5th, 2015
Re: Create a Flowchart Diagram dynamically by reading the values/dependency from Oracle Database
Reply #18 - Jun 15th, 2015 at 3:38pm
Print Post  
Hi, I dont think i got your point. How will the JobId be fetched if i remove this parent table query?

So, this is my parent table query

command.CommandText = "select JOB_ID,JOB_NAME from Jobs";

command.Connection = connection;

OracleDataReader reader = command.ExecuteReader();

int index_jobId = reader.GetOrdinal("JOB_ID");

---
« Last Edit: Jul 14th, 2015 at 7:40pm by SE »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Create a Flowchart Diagram dynamically by reading the values/dependency from Oracle Database
Reply #19 - Jun 15th, 2015 at 4:21pm
Print Post  
You will get the job's ID and Name from the JOIN operation if using same query as in my example:

Code
Select All
OracleCommand jobsCommand = connection.CreateCommand();
jobsCommand.CommandText = string.Format(
	"select JOBS.ID, JOBS.NAME, DEPENDENCIES.PARENT_JID, DEPENDENCIES.DEP_JID, LEVEL " +
	"from JOBS inner join DEPENDENCIES on JOBS.ID=DEPENDENCIES.DEP_JID " +
	"where LEVEL<{0} " +
	"start with DEPENDENCIES.PARENT_JID={1} " +
	"connect by prior DEPENDENCIES.DEP_JID=DEPENDENCIES.PARENT_JID",
	depth, parentID); 



Since you wanted to get results only for hierarchical subset from your huge data and the dependencies are stored in a separate table, you will have to use JOIN to query it. If you don't mind fetching all data, you might as well use the older example and just delete nodes that are at longer distance from the root than you want to show.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Create a Flowchart Diagram dynamically by reading the values/dependency from Oracle Database
Reply #20 - Oct 16th, 2015 at 8:42am
Print Post  
Hi,

If you aren't seeing any nodes in the diagram, Factory.CreateShapeNode has probably never been called, and so later FindNodeById will return null. Try tracing through node-creation part of your code to see why.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint