Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) How to save and retrieve from database (Read 5308 times)
maxnetpromo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 21
Joined: Mar 5th, 2006
How to save and retrieve from database
Mar 5th, 2006 at 4:13pm
Print Post  
I am developing a schematic representation of an electricity grid using flowchart.NET. I need to be able to save the object essential properties and be able to retrieve them accordingly.

the items i want saved for BOXES are:
color
size
position on canvas
text value,
tag Value,

For ARROWS are:
thickness,
tag Value,
text Value,
Location,
Length
and incoming and out going connections

any help how to be able to save everything and reload from the database to restore the schematic diagram.
« Last Edit: Mar 5th, 2006 at 6:49pm by maxnetpromo »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to save and retrieve from database
Reply #1 - Mar 6th, 2006 at 7:22am
Print Post  
Flowchart.NET does not support data binding. You would have to use ADO.NET to create dataset objects that encapsulate your data. When saving a diagram, iterate the dataset rows and set their fields so they correspond to the diagram state. When loading, create Flowchart.NET objects and set their properties so they correspond to the database data.

The following properties contain the information you need:
Box.FillColor
Box.FrameColor
Box.BoundingRect
Box.Text
Box.Tag
Arrow.Pen.Width
Arrow.Tag
Arrow.Text
Arrow.ControlPoints
Arrow.Length

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


I love YaBB 1G - SP1!

Posts: 21
Joined: Mar 5th, 2006
Re: How to save and retrieve from database
Reply #2 - Mar 6th, 2006 at 8:09am
Print Post  
thanks... will the arrow connections be restored from the ControlPoints property.

by saving these properties alone, will the schematic be restored exactly?

thanks,

adrian
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to save and retrieve from database
Reply #3 - Mar 6th, 2006 at 8:44am
Print Post  
The connection won't be restored. Use the Origin and Destination properties to find out which nodes an arrow connects, and later set these properties or pass the nodes as arguments to CreateArrow. Before assigning any values to ControlPoints, you must also set the arrow Style and SegmentCount. 

Stoyan
  
Back to top
 
IP Logged
 
maxnetpromo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 21
Joined: Mar 5th, 2006
Re: How to save and retrieve from database
Reply #4 - Mar 14th, 2006 at 9:05pm
Print Post  
I need some help regarding storing in the database.
how am i going to store rectangle object to and collection points to  a mySQL database?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to save and retrieve from database
Reply #5 - Mar 15th, 2006 at 6:36am
Print Post  
Create x,y,width,height fields in the table that stores node information and use them to save the BoundingRect coordinates.

Regarding arrow control point coordinates - you could save them in a BLOB field or in a helper table related M:1 to the arrow table. Or if you use automatic routing - do not save the points but just call RouteAll after loading the diagram.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Adrian Hedley
Guest


Re: How to save and retrieve from database
Reply #6 - Mar 23rd, 2006 at 8:09pm
Print Post  
I have decided to use an object oriented database to stiore the properties of the box and arrow properties, however i cannot save the whole object as it is.

I am saving these properties as stoyan indicated ealier.

Box.FillColor
Box.FrameColor
Box.BoundingRect
Box.Text
Box.Tag
Arrow.Pen.Width
Arrow.Tag
Arrow.Text
Arrow.ControlPoints
Arrow.Length

To save the connections between objects i was trying to save the origin and destination nodes, however that is not possible.

I am giving each object i save in the database a unique Id. I am also saving the connections by creating a unique id for the connection and a in_id and out_id to represent the origin and destination nodes. Would that be enough to recreate the connections.

can you tell me how to do it. I was planning to iterate through a list of boxes and create the boxes first.
then how do i go about recreating the arrows?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to save and retrieve from database
Reply #7 - Mar 24th, 2006 at 5:19am
Print Post  
You could use a Hashtable that maps objects IDs to Box instances and populate it when loading the boxes. Next, load the connection IDs, get the related boxes from the hashtable, call CreateArrow and load the rest of the Arrow properties.

I hope that helps.
Stoyan
  
Back to top
 
IP Logged
 
maxnetpromo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 21
Joined: Mar 5th, 2006
Re: How to save and retrieve from database
Reply #8 - Mar 24th, 2006 at 6:51am
Print Post  
can you explain a bit more... i have never used a hash table before.

thanks,

Adrian
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to save and retrieve from database
Reply #9 - Mar 24th, 2006 at 10:31am
Print Post  
A Hashtable contains pairs of keys and objects and lookup by key is very fast. You could populate a hashtable while reading boxes and use it to find connections' source and destination while reading the arrows' table, e.g.

Hashtable boxes = new Hashtable();
for (int i = 0; i < dataSet.Tables["boxes"].Rows.Count; i++)
{
  Box box = fc.CreateBox(...);
  boxes.Add(dataSet.Tables["boxes"].Rows[i]["id"], box);
}

for (int j = 0; j < dataSet.Tables["links"].Rows.Count; j++)
{
  int inId = (int)dataSet.Tables["links"].Rows[j]["in_id"];
  int outId = (int)dataSet.Tables["links"].Rows[j]["out_id"];
  Box dest = (Box)boxes[inId];
  Box src = (Box)boxes[outId];
  fc.CreateArrow(src, dest);
}
  
Back to top
 
IP Logged
 
maxnetpromo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 21
Joined: Mar 5th, 2006
Re: How to save and retrieve from database
Reply #10 - Mar 24th, 2006 at 2:25pm
Print Post  
so here the hash table is use to contain a copy of the boxes in memory, for faster retrieval instead of getting everything from the database sequentially.

I will give it a try. thanks for the tip.

adrian
  
Back to top
 
IP Logged
 
maxnetpromo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 21
Joined: Mar 5th, 2006
Re: How to save and retrieve from database
Reply #11 - Apr 4th, 2006 at 8:54pm
Print Post  
I have tried hashtables to load the schematic and it worked perfectly.

Thank you for the great tip. hashtables are really cool datastructures.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint