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 17214 times)
SE
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Jun 5th, 2015
Create a Flowchart Diagram dynamically by reading the values/dependency from Oracle Database
Jun 5th, 2015 at 2:00pm
Print Post  
For example, Lets say table looks like this. I would need to read these values from DB and draw a diagram in .NET applciatrion (C# code). Can you please help me with sample code.

JobID JobName Dependancyjobs
0023      Job1 JobX
6736      Job2 JobX
6736      Job3 JobY
  
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 #1 - Jun 5th, 2015 at 2:11pm
Print Post  
Does Dependancyjobs always contain a single value from JobName column, or it's a list of some kind?
  
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 #2 - Jun 5th, 2015 at 2:20pm
Print Post  
One Job can have multiple dependency jobs. For example,

Job A has dependency with Job B, Job C, Job D and Job D which has dependency inside it.

Job A (Parent - BOX JOB)
     Job B
     Job C
     jOd D
           Job D.1
           Job.D.2
           
  
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 #3 - Jun 5th, 2015 at 2:56pm
Print Post  
You will be building a tree if each job has a single parent job. I don't have Oracle DB to try this, but it should look like this:

Code
Select All
var rect = new RectangleF(0, 0, 30, 20);
var parentLinks = new StringDictionary();

OracleCommand command = connection.CreateCommand();
command.CommandText = "select * from Jobs";

OracleDataReader reader = command.ExecuteReader();
while (reader.Read())
{
	var node = diagram.Factory.CreateShapeNode(rect);
	node.Id = (string)reader["JobID"];
	node.Text = (string)reader["JobName"];
	var parentId = (string) reader["Dependancyjobs"];
	parentLinks[(string)node.Id] = parentId;
}

foreach (var id in parentLinks.Keys)
{
	var node1 = diagram.FindNodeById(parentLinks[id]);
	var node2 = diagram.FindNodeById(id);
	diagram.Factory.CreateDiagramLink(node1, node2);
}

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



The first loop creates all nodes and stores parent identifiers. It cannot create links immediately because the parent node might have not been created yet. Links are created in second loop from nodes identified by parentLinks values.

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 #4 - Jun 5th, 2015 at 3:05pm
Print Post  
Thank you for the sample code. I will take a look at it.. Each job can have multiple parent job.. It will be more of network diagram than tree diagram. does this code specific to Tree structure?
  
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 #5 - Jun 5th, 2015 at 4:23pm
Print Post  
I don't think you can represent many-to-many relationships if you keep a single parentID field in the table. Instead you will need a separate table just for the dependencies, with parentID and childID fields in each record. The code should look similar to this then:

Code
Select All
// ....
while (reader.Read())
{
	var node = diagram.Factory.CreateShapeNode(rect);
	node.Id = (string)reader["JobID"];
	node.Text = (string)reader["JobName"];
}

OracleCommand dependenciesCmd = connection.CreateCommand();
dependenciesCmd.CommandText = "select * from Dependencies";

OracleDataReader depReader = dependenciesCmd.ExecuteReader();
while (depReader.Read())
{
	string parentId = (string)depReader["ParentID"];
	string childId = (string)depReader["ChildID"];
	var parent = diagram.FindNodeById(parentId);
	var child = diagram.FindNodeById(childId);
	diagram.Factory.CreateDiagramLink(parent, child);
}

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



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 #6 - Jun 8th, 2015 at 2:10pm
Print Post  
Thank you. This is really helps.
I know you mentioned this in your reply:
The first loop creates all nodes and stores parent identifiers. It cannot create links immediately because the parent node might have not been created yet. Links are created in second loop from nodes identified by parentLinks values.

It means, the links should form in the last stage right?
But i dont see the link at all.
I am able to fetch data and build the nodes. But links are not forming in the flow chart. What am i missing?


Thanks
  
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 #7 - Jun 8th, 2015 at 2:34pm
Print Post  
Are you using a separate table for many-to-many relationships as in second example? In such case check if the names from sample code match the names you've given to your table and fields: Dependencies table, ParentID and ChildID columns. Make sure ParentID/ChildID values point to existing JobID (and not JobName) in the primary table.

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 #8 - Jun 8th, 2015 at 5:49pm
Print Post  
I verified and corrected few values in DB table. Output and DB values are sent in the email. Can you please review the DB values. I just wanna make sure I understood the relationship and linked the jobs correctly as you said.
  
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 #9 - Jun 8th, 2015 at 6:01pm
Print Post  
I can see some links created in the screenshot, but the graph hasn't been arranged. That probably means there was an exception thrown before the code reached layout.Arrange call. Try adding breakpoint inside your catch clause to see the exact exception type and message. If the Id columns contain integer values, try replacing the (string) cast with reader.GetInt32(...) call.

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 #10 - Jun 9th, 2015 at 1:20am
Print Post  
You are correct. I put the breakpoint in catch clause and found this error:
Error:            $exception      {"Unable to find specified column in result set"}      System.Exception {System.IndexOutOfRangeException}


Changed the Job_id values as below in the code:

int parentId = reader.GetInt32(reader.GetOrdinal("PARENT_JID"));
int childId = reader.GetInt32(reader.GetOrdinal("DEP_JID"));


I modified my code in several ways such as checking DBNULL values, and iterated through column index instead of column name, etc. But no luck.. I cant figure out why am i getting this error.

Column names and table names are correct as well.

Can you please tell me what am i missing? thanks in adavnce for your help.
  
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 #11 - Jun 9th, 2015 at 5:16am
Print Post  
I suppose you have followed my "replace the (string) cast with reader.GetInt32(...)" suggestion too literally. You should call depReader.GetInt32(...) while iterating over AUTOSYS_DEPENDENCY result set.

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 #12 - Jun 9th, 2015 at 3:55pm
Print Post  
Thanks again for your help. It was my bad.. However, I received this error after correcting the reader object call
Error: Operation is not valid due to the current state of object. To correct this error, I added this code after the line- command.commandText... and the graph is forming correctly now.

command.Connection = connection;

  
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 #13 - Jun 9th, 2015 at 8:53pm
Print Post  
Hello,

We were almost close to finishing the POC to create a flowchart (many-many relation) by fetching the values form DB. This product really works for our requirement.

The last thing, i would like to know is,
Lets say my table has all the jobs and its dependency.. But i dont want the entire graph to shown in the page. It might be huge data.

So I just need a graph starting from Job C to 5 stages below.


DEP_NAME      DEP_JID      PARENT_JID      JOB_TYPE
Job A            5677      6767      (null)
Job B            5677      6777      (null)
Job C            3454      5677      (null)
JOB D            7789      3454      (null)
JOB E            7789      2123      (null)
JOB F            3444      7789      (null


Is it possible for me to do that using MindFusion?
  
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 #14 - Jun 10th, 2015 at 7:42am
Print Post  
Hi,

From what I can find it should be possible to limit the result set using Oracle hierarchical queries with "connect by" clause:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm

The example here shows how to limit the hierarchy depth.

If you manage to get OracleReaders for such hierarchical subsets, the code-behind that creates diagram elements from query results shouldn't have to change.

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