Profile Picture

Fill tree with data from database table (NTreeDataSourceImporter)

Posted By ldhbflhd ljksfdbld 14 Years Ago

Fill tree with data from database table (NTreeDataSourceImporter)

Author
Message
ldhbflhd ljksfdbld
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 2, Visits: 1
Hello,

I am trying to fill some data from my table in DB where I have ID and ID_PARENT connection.
SAMPLE:
ID ID_PARENT NAME
1 -1 BOSS (I tried root id_parent also null, 0, some number...)
2 1 JOHN
3 2 MIKE
4 2 SUE
....
I can't get it working, can any help ? The problem is, because treeimport_ImportFailed is thrown and I don't know why.

Here is my code. THX

Any other working example ?


protected void ImportTree()
{
DataClassesDataContext db = new DataClassesDataContext();
var izbrani = from f in db.VrniStrukturo(847)
select f.id_sodelavec;

var sod = from s in db.sodelavecs
where izbrani.Contains(s.id_sodelavec)
select s;

// clear the document
NDrawingView1.Document.ActiveLayer.RemoveAllChildren();

NTreeDataSourceImporter treeimport = new NTreeDataSourceImporter();
treeimport.Document = NDrawingView1.Document;
treeimport.DataSource = sod;
treeimport.IdColumnName = "id_sodelavec";
treeimport.ParentIdColumnName = "id_mentor";

// create vertices as rectangles shapes
NBasicShapesFactory shapesFactory = new NBasicShapesFactory();
treeimport.VertexShapesFactory = shapesFactory;
treeimport.VertexShapesName = BasicShapes.Rectangle.ToString();

// use layered tree layout
NLayeredTreeLayout layout = new NLayeredTreeLayout();
layout.Direction = LayoutDirection.LeftToRight;
layout.OrthogonalEdgeRouting = true;
layout.LayerAlignment = RelativeAlignment.Near;
treeimport.Layout = layout;

// subscribe for the vertex imported event,
// which is raised when a shape was created for a data source record
treeimport.VertexImported += new ShapeImportedDelegate(OnVertexImported);
treeimport.ImportFailed += new EventHandler(treeimport_ImportFailed);
// import
treeimport.Import();
NDrawingView1.Document.SizeToContent();
}

void treeimport_ImportFailed(object sender, EventArgs e)
{

throw new NotImplementedException();
}
private void OnVertexImported(NDataSourceImporter importer, NShape shape, INDataRecord dataRecord)
{
// display the page title in the shape
object text = dataRecord.GetColumnValue("ime");
if (text == null)
{
shape.Text = "Title not specified";
}
else
{
shape.Text = text.ToString();
}
shape.SizeToText(new NMarginsF(10));
// make the URL a tooltip of the shape
object url = dataRecord.GetColumnValue("priimek");
if (url == null || url.ToString().Length == 0)
{
shape.Style.InteractivityStyle = new NInteractivityStyle("URL not specified");
}
else
{
shape.Style.InteractivityStyle = new NInteractivityStyle(url.ToString());
}
}


Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi,

We’ve tried the tree data importer with the same sample data you have specified in your post:

 

DataTable table = new DataTable();

table.Columns.Add("Id", typeof(int));

table.Columns.Add("ParentId", typeof(int));

table.Columns.Add("Name", typeof(string));

 

table.Rows.Add(1, null, "BOSS");

table.Rows.Add(2, 1, "JOHN");

table.Rows.Add(3, 2, "MIKE");

table.Rows.Add(4, 2, "SUE");

 

 

 

All you have to do next is to create a simple tree data importer:

 

// create the tree data source importer

m_TreeImporter = new NTreeDataSourceImporter();

 

// set the document in the active layer of which the shapes will be imported

m_TreeImporter.Document = document;

 

// set the data source

m_TreeImporter.DataSource = table;

 

// records are uniquely identified by their Id column

// records link to their parent record by their ParentId column

m_TreeImporter.IdColumnName = "Id";

m_TreeImporter.ParentIdColumnName = "ParentId";

 

// create vertices as rectangles shapes, with default size (60,30)

NBasicShapesFactory shapesFactory = new NBasicShapesFactory();

shapesFactory.DefaultSize = new NSizeF(60, 30);

m_TreeImporter.VertexShapesFactory = shapesFactory;

m_TreeImporter.VertexShapesName = BasicShapes.Rectangle.ToString();

 

// set stylesheets to be applied to imported vertices and edges

m_TreeImporter.VertexStyleSheetName = "Vertices";

m_TreeImporter.EdgeStyleSheetName = "Edges";

 

// use layered tree layout

NLayeredTreeLayout layout = new NLayeredTreeLayout();

layout.Direction = LayoutDirection.LeftToRight;

layout.OrthogonalEdgeRouting = true;

layout.LayerAlignment = RelativeAlignment.Near;

m_TreeImporter.Layout = layout;

 

// subscribe for the vertex imported event,

// which is raised when a shape was created for a data source record

m_TreeImporter.VertexImported += new ShapeImportedDelegate(OnVertexImported);

 

// import

m_TreeImporter.Import();

 

The result of the import will be the attached diagram.



Best Regards,
Nevron Support Team



Attachments
Diagram.jpg (94 views, 6.00 KB)
ldhbflhd ljksfdbld
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 2, Visits: 1
If I use your example code I get folowing error (attached).

System.Exception: New DataSourceType?

If I use data from linq and my DB, Nothing is drawn on document.

Thanks

Attachments
nothing.GIF (86 views, 56.00 KB)
tree.GIF (91 views, 131.00 KB)
Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi,

The currently supported DataSource types are: DataTable, DataView, OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, OleDbCommand, SqlCommand, OdbcCommand.



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic