Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to insert shape node into mysql database im using visual basic 2010 (Read 3810 times)
Ivan Gamo
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 30
Joined: Nov 10th, 2012
How to insert shape node into mysql database im using visual basic 2010
Nov 10th, 2012 at 8:25am
Print Post  
please help. I am newbie in mindfusion diagramming. Embarrassed
anyone please help me. atleast give a sample code for it.
Thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to insert shape node into mysql database im using visual basic 2010
Reply #1 - Nov 10th, 2012 at 6:15pm
Print Post  
Assuming you have node and link tables in MySQL that contain following fields:

node: node_id, label, shape
link: link_id, origin_id, destination_id

and you are using the .NET entity framework, you can read diagrams from the database and save to the database with code like this:

Code
Select All
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MindFusion.Diagramming;
using MindFusion.Diagramming.Layout;

namespace MySqlTest
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
			diagramView1.AllowInplaceEdit = true;
			var nodeBounds = new RectangleF(0, 0, 30, 20);

			var diagDB = new DiagramEntities();

			// create diagram nodes corresponding to database records
			foreach (Node nodeData in diagDB.Nodes)
			{
				var node = diagram.Factory.CreateShapeNode(nodeBounds);
				node.Text = nodeData.label;
				node.Shape = Shape.FromId(nodeData.shape);
				node.Id = nodeData.node_id;
			}

			// create diagram links corresponding to database records
			foreach (Link linkData in diagDB.Links)
			{
				var origin = diagram.FindNodeById(linkData.origin_id);
				var dest = diagram.FindNodeById(linkData.destination_id);
				var link = diagram.Factory.CreateDiagramLink(origin, dest);
				link.Text = linkData.label;
				link.Id = linkData.link_id;
			}

			// arrange the diagram
			new LayeredLayout().Arrange(diagram);
		}

		private void btnSave_Click(object sender, EventArgs e)
		{
			var diagDB = new DiagramEntities();

			// create or update node records
			foreach (ShapeNode node in diagram.Nodes)
			{
				if (node.Id == null)
				{
					// create new record
					var nodeData = new Node();
					nodeData.label = node.Text;
					nodeData.shape = node.Shape.Id;
					diagDB.Nodes.AddObject(nodeData);
					diagDB.SaveChanges();
					node.Id = nodeData.node_id;
				}
				else
				{
					// update existing record
					var nodeData = (from row in diagDB.Nodes
						where row.node_id == (int)node.Id
						select row).FirstOrDefault();
					nodeData.label = node.Text;
					nodeData.shape = node.Shape.Id;
					diagDB.SaveChanges();
				}
			}

			// create or update link records
			foreach (DiagramLink link in diagram.Links)
			{
				if (link.Id == null)
				{
					// create new record
					var linkData = new Link();
					linkData.label = link.Text;
					linkData.origin_id = (int)link.Origin.Id;
					linkData.destination_id = (int)link.Destination.Id;
					diagDB.Links.AddObject(linkData);
					diagDB.SaveChanges();
					link.Id = linkData.link_id;
				}
				else
				{
					// update existing record
					var linkData = (from row in diagDB.Links
						where row.link_id == (int)link.Id
						select row).FirstOrDefault();
					linkData.label = link.Text;
					linkData.origin_id = (int)link.Origin.Id;
					linkData.destination_id = (int)link.Destination.Id;
					diagDB.SaveChanges();
				}
			}
		}
	}
} 



The Id property of diagram items is set to the id of their respective database record, and is later used to determine if the item is a new or updated one. You could also handle events such as NodeDeleted and LinkDeleted to delete database records when items are removed.

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


I Love MindFusion!

Posts: 30
Joined: Nov 10th, 2012
Re: How to insert shape node into mysql database im using visual basic 2010
Reply #2 - Nov 23rd, 2012 at 6:09am
Print Post  
thank you sir, but this code doesn't work in visual basic.
thank you for the reply. Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to insert shape node into mysql database im using visual basic 2010
Reply #3 - Nov 23rd, 2012 at 7:32am
Print Post  
  
Back to top
 
IP Logged
 
Ivan Gamo
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 30
Joined: Nov 10th, 2012
Re: How to insert shape node into mysql database im using visual basic 2010
Reply #4 - Dec 1st, 2012 at 1:15pm
Print Post  
Thank you so much ! I've got solution for my problem. Wink
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint