Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic create diagram from database (Read 3790 times)
tacsecret
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 16th, 2007
create diagram from database
Nov 16th, 2007 at 11:37am
Print Post  
It's one week I try to create a diagram from a database.
I'm able to create nodes very well..
but I'm non able to create relationship between the records.
every record is a person and I'm need to add, for example, 3 record to only one like an genealogic tree (Father, Mother, son, son).
I saw your example in flowchart.net named "Genealogy"... it's perfect:
It has a table named Person and a table named Flowchart.
I don't understant how flowchart table works... how the relationship information are stored.

Please I'd like to to have an easy example in VB.NET 2005 ... because I'm not a good programmer in vb.net... I'm beginner.

I wrote this code to read data from database


Do While dr.Read()
Dim entita1 As ShapeNode = Diagram1.Factory.CreateShapeNode(a, b, 30, 30)
'Dim gruppo As Group = Diagram1.Factory.CreateGroup(entita1)

If dr.Item("Sesso") = "M" Then
entita1.Shape = Shapes.Actor
entita1.Pen.Color = Color.LightBlue
entita1.Text = dr.Item("Cognome") & " " & dr.Item("Nome") & vbCrLf & dr.Item("Data")
entita1.TextFormat.LineAlignment = StringAlignment.Far
entita1.TextColor = Color.Black
entita1.ToolTip = dr.Item("Cognome") & " " & dr.Item("Nome") & vbCrLf & dr.Item("Data")
entita1.Tag = dr.Item("Cognome") & " " & dr.Item("Nome")
a = a + 20
b = b

Else
entita1.Shape = Shapes.Actor
entita1.Pen.Color = Color.HotPink
entita1.Text = dr.Item("Cognome") & " " & dr.Item("Nome") & vbCrLf & dr.Item("Data")
entita1.TextFormat.LineAlignment = StringAlignment.Far
entita1.TextColor = Color.Black
entita1.ToolTip = dr.Item("Cognome") & " " & dr.Item("Nome") & vbCrLf & dr.Item("Data")
entita1.Tag = dr.Item("Cognome") & " " & dr.Item("Nome")
a = a + 20
b = b
End If

Loop





How  can I read the relationship informations?
Please help me!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: create diagram from database
Reply #1 - Nov 16th, 2007 at 12:15pm
Print Post  
Hi,

Suppose you have Parent1 and Parent2 fields, as in Genealogy.mdb.

You cannot create the relations before all nodes are created, so you will need to use two loops. In the first loop create the nodes and map their database identifiers to the node objects, e.g. using a hashtable:

dim idToNodeMap as new Hashtable()
Do While dr.Read()
     ...
     idToNodeMap(dr.Item("ID")) = entita1
     ...
Loop

In the second loop create the links:

' loop over the dataset again
Do While dr.Read()
     ' use the already created node
     node = idToNodeMap(dr.Item("ID"))
     Diagram1.Factory.CreateDiagramLink(node, idToNodeMap(dr.Item("Parent1")))
     Diagram1.Factory.CreateDiagramLink(node, idToNodeMap(dr.Item("Parent2")))
Loop

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


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 16th, 2007
Re: create diagram from database
Reply #2 - Nov 16th, 2007 at 12:58pm
Print Post  
thanks for your fast answer...
Now is more clean!!!!
I'm trying.... i will tell you if I resolve!!!
  
Back to top
 
IP Logged
 
tacsecret
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 16th, 2007
Re: create diagram from database
Reply #3 - Nov 16th, 2007 at 2:27pm
Print Post  
Sorry... but It's no easy for me...
it doesn't create the links...

this is my full code... please help...


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       'CONNESSIONE DATABASE
       'Percorso del DataBase (Biblio.mdb)
       Dim PercorsoDB As String = "C:\ANA\DB\DB_ANA.mdb"
       'Stringa di Connessione
       Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
       "Persist Security Info=False;" & _
       "Data Source=" & PercorsoDB & _
       ";" & _
       "User ID=Admin;" & _
       "Jet OLEDB:Database Password=PTCC75BN;"
       'Fine Stringa di Connessione
       '
       'APERTURA
       Dim Cn As New OleDb.OleDbConnection(ConnString)
       If Cn.State = ConnectionState.Open Then Cn.Close()
       Cn.Open()

       'RECUPERO DATI
       Dim testoTxt As String = VAL_GRUPPOComboBox.Text
       If Cn.State = ConnectionState.Open Then
           Dim sql As String = "select * from Person where Gruppo=?"
           Dim cmd As New OleDb.OleDbCommand(sql, Cn)

           cmd.Parameters.AddWithValue("Gruppo", testoTxt)

           Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader
           Dim a, b As Integer
           a = 20
           b = 20


           Dim idToNodeMap As New Hashtable()

           Do While dr.Read()
               Dim entita1 As ShapeNode = Diagram1.Factory.CreateShapeNode(a, b, 30, 30)

               'Dim gruppo As Group = Diagram1.Factory.CreateGroup(entita1)

               If dr.Item("Sesso") = "M" Then

                   entita1.Shape = Shapes.Actor
                   entita1.Pen.Color = Color.LightBlue
                   entita1.Text = dr.Item("Cognome") & " " & dr.Item("Nome") & vbCrLf & dr.Item("Data")
                   entita1.TextFormat.LineAlignment = StringAlignment.Far
                   entita1.TextColor = Color.Black
                   entita1.ToolTip = dr.Item("Cognome") & " " & dr.Item("Nome") & vbCrLf & dr.Item("Data")
                   entita1.Tag = dr.Item("Cognome")
                   a = a + 20
                   b = b
                   idToNodeMap(dr.Item("ID")) = entita1
               Else

                   entita1.Shape = Shapes.Actor
                   entita1.Pen.Color = Color.HotPink
                   entita1.Text = dr.Item("Cognome") & " " & dr.Item("Nome") & vbCrLf & dr.Item("Data")
                   entita1.TextFormat.LineAlignment = StringAlignment.Far
                   entita1.TextColor = Color.Black
                   entita1.ToolTip = dr.Item("Cognome") & " " & dr.Item("Nome") & vbCrLf & dr.Item("Data")
                   entita1.Tag = dr.Item("ID")
                   a = a + 20
                   b = b
                   idToNodeMap(dr.Item("ID")) = entita1
               End If



           Loop

           Do While dr.Read()
               ' use the already created node
               Dim entita1 As ShapeNode = Diagram1.Factory.CreateShapeNode(a, b, 30, 30)
               entita1 = idToNodeMap(dr.Item("ID"))
               Diagram1.Factory.CreateDiagramLink(entita1, idToNodeMap(dr.Item("Parent1")))
               Diagram1.Factory.CreateDiagramLink(entita1, idToNodeMap(dr.Item("Parent2")))
           Loop





       End If

       'FINE DATI DATABASE

       DiagramView1.ZoomFactor = 50
       TrackBar1.Value = 50


    End Sub
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: create diagram from database
Reply #4 - Nov 16th, 2007 at 8:11pm
Print Post  
After the first loop, the reader's current position is past the last record of the dataset. You should start reading again, e.g. insert a

dr = cmd.ExecuteReader

before the second while loop.

Stoyan
  
Back to top
 
IP Logged
 
tacsecret
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 16th, 2007
Re: create diagram from database
Reply #5 - Nov 17th, 2007 at 6:53am
Print Post  
I receive this error:


Nessun elemento 'CreateDiagramLink' pubblico è specifico per questi argomenti:
    'Public Function CreateDiagramLink(origin As System.Drawing.PointF, destination As System.Drawing.PointF) As MindFusion.Diagramming.DiagramLink':
       Non specifico.
    'Public Function CreateDiagramLink(origin As MindFusion.Diagramming.TableNode, destination As MindFusion.Diagramming.TableNode) As MindFusion.Diagramming.DiagramLink':
       Non specifico.


I suppose i must insert a function like this:

  Public Function CreateDiagramLink(ByVal origin As System.Drawing.PointF, ByVal destination As System.Drawing.PointF) As MindFusion.Diagramming.DiagramLink
 
    End Function

But what code I've to insert in this function?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: create diagram from database
Reply #6 - Nov 17th, 2007 at 12:28pm
Print Post  
Does that message mean that the compiler cannot resolve which of the overloaded CreateDiagramLink methods to use? Try to explicitly assign the objects from the hashtable to ShapeNode variables, or use CType to cast them, e.g.

dim node as ShapeNode = idToNodeMap(dr.Item("ID"))
dim parent1 as ShapeNode = idToNodeMap(dr.Item("Parent1"))
Diagram1.Factory.CreateDiagramLink(node, parent1)

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