Diagram Database importer 를 이용하면 Database 의 전체 Hirearchy를 import 하는 것이 가능하며, Database Entity 관계 다이어그램을 쉽게 생성할 수 있다.
Nevron Diagram 은 Table 형태의 데이터 Source 로부터 트리형태와 그래프 데이터 구조로 자동으로 가져오기 기능을 제공한다.
Data import 기능은 DataTable, DataView, OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, OleDbCommand, SqlCommand, OdbcCommand 등, 각 data Source 별로 지원한다.
data 가져오기 기능은 저장된 데이터 정보를 제어할 수 있도록 도와준다.
다음 예제는 NGraphDatasourceImporter 를 사용하는 방법을 보여주는데, 단순 Access 데이터베이스에서 데이터를 import 하여 자동으로 Graph 데이터구조로 자동 배열한다.

pages 테이블의 컬럼내용

Link 테이블의 컬럼 내용

자동으로 생성된 Diagram
C#
using Nevron.GraphicsCore;
using Nevron.Diagram;
using Nevron.Diagram.Shapes;
using Nevron.Diagram.WinForm;
using Nevron.Diagram.Layout;
using Nevron.Diagram.DataImport;
…
private void Form1_Load(object sender, System.EventArgs e)
{
// View 초기화 시작
DrawingView.BeginInit();
// View 에서 document 표시
DrawingView.Document = DrawingDocument;
// view 설정
DrawingView.ViewLayout = ViewLayout.Fit;
DrawingView.Grid.Visible = false;
DrawingView.GlobalVisibility.ShowPorts = false;
DrawingView.HorizontalRuler.Visible = false;
DrawingView.VerticalRuler.Visible = false;
// stylesheets 생성 - one for the vertices and one for the edges
NStyleSheet vertexStyleSheet = new NStyleSheet();
vertexStyleSheet.Name = "Vertices";
DrawingDocument.StyleSheets.AddChild(vertexStyleSheet);
NStyleSheet edgeStyleSheet = new NStyleSheet();
edgeStyleSheet.Name = "Edges";
edgeStyleSheet.Style.StartArrowheadStyle = new NArrowheadStyle(ArrowheadShape.Circle, "", new NSizeL(5, 5), new NColorFillStyle(Color.Gray), new NStrokeStyle(1, Color.Black));
edgeStyleSheet.Style.EndArrowheadStyle = new NArrowheadStyle(ArrowheadShape.Arrow, "", new NSizeL(5, 5), new NColorFillStyle(Color.Gray), new NStrokeStyle(1, Color.Black));
DrawingDocument.StyleSheets.AddChild(edgeStyleSheet);
// graph data source importer 설정
NGraphDataSourceImporter GraphImporter = new NGraphDataSourceImporter();
// set the document in the active layer of which the shapes will be imported
GraphImporter.Document = DrawingDocument;
// set the connection string, data sources and DataAdapters
// in this example we have created two OleDbDataAdapters:
// the PagesDataAdapter selects all records and columns from the Pages table of the SiteMap.mdb
// the LinksDataAdapter selects all records and columns from the Links table of the SiteMap.mdb
string connString = @"Data Source=""" + Application.StartupPath +
@"\SiteMap.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";";
OleDbDataAdapter PagesDataAdapter = new OleDbDataAdapter("SELECT * FROM Pages", connString);
OleDbDataAdapter LinksDataAdapter = new OleDbDataAdapter("SELECT * FROM Links", connString);
GraphImporter.VertexDataSource = PagesDataAdapter;
GraphImporter.EdgeDataSource = LinksDataAdapter;
// vertex records are uniquely identified by their Id (in the Pages table)
// edges link the vertices with the FromPageId and ToPageId (in the Links table)
GraphImporter.VertexIdColumnName = "Id";
GraphImporter.FromVertexIdColumnName = "FromPageId";
GraphImporter.ToVertexIdColumnName = "ToPageId";
// create vertices as rectangles shapes, with default size (60, 30)
NBasicShapesFactory shapesFactory = new NBasicShapesFactory();
shapesFactory.DefaultSize = new NSizeF(60, 30);
GraphImporter.VertexShapesFactory = shapesFactory;
GraphImporter.VertexShapesName = BasicShapes.Rectangle.ToString();
// set stylesheets to be applied to imported vertices and edges
GraphImporter.VertexStyleSheetName = "Vertices";
GraphImporter.EdgeStyleSheetName = "Edges";
// layered graph layout 사용
NLayeredGraphLayout layout = new NLayeredGraphLayout();
layout.Direction = LayoutDirection.TopToBottom;
layout.LayerAlignment = RelativeAlignment.Near;
GraphImporter.Layout = layout;
// subscribe for the vertex imported event,
// which is raised when a shape was created for a data source record
GraphImporter.VertexImported += new ShapeImportedDelegate(OnVertexImported);
// 가져오기
GraphImporter.Import();
// view 초기화 끝
DrawingView.EndInit();
}
private void OnVertexImported(NDataSourceImporter dataSourceImporter, NShape shape, INDataRecord record)
{
// display the page title in the shape
object text = record.GetColumnValue("Title");
if (text == null)
{
shape.Text = "Title not specified";
}
else
{
shape.Text = text.ToString();
}
shape.SizeToText(new NMarginsF(10));
}
VB.NET
Imports Nevron.GraphicsCore
Imports Nevron.Diagram
Imports Nevron.Diagram.Shapes
Imports Nevron.Diagram.WinForm
Imports Nevron.Diagram.Layout
Imports Nevron.Diagram.DataImport
...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
' begin view init
DrawingView.BeginInit()
' display the document in the view
DrawingView.Document = DrawingDocument
' configure the view
DrawingView.ViewLayout = ViewLayout.Fit
DrawingView.Grid.Visible = False
DrawingView.GlobalVisibility.ShowPorts = False
DrawingView.HorizontalRuler.Visible = False
DrawingView.VerticalRuler.Visible = False
' create two stylesheets - one for the vertices and one for the edges
Dim vertexStyleSheet As New NStyleSheet()
vertexStyleSheet.Name = "Vertices"
DrawingDocument.StyleSheets.AddChild(vertexStyleSheet)
Dim edgeStyleSheet As New NStyleSheet()
edgeStyleSheet.Name = "Edges"
edgeStyleSheet.Style.StartArrowheadStyle = New NArrowheadStyle(ArrowheadShape.Circle, "", New NSizeL(5, 5), New NColorFillStyle(Color.Gray), New NStrokeStyle(1, Color.Black))
edgeStyleSheet.Style.EndArrowheadStyle = New NArrowheadStyle(ArrowheadShape.Arrow, "", New NSizeL(5, 5), New NColorFillStyle(Color.Gray), New NStrokeStyle(1, Color.Black))
DrawingDocument.StyleSheets.AddChild(edgeStyleSheet)
' configure the graph data source importer
Dim GraphImporter As New NGraphDataSourceImporter()
' set the document in the active layer of which the shapes will be imported
GraphImporter.Document = DrawingDocument
' set the connection string, data sources and DataAdapters
' in this example we have created two OleDbDataAdapters:
' the PagesDataAdapter selects all records and columns from the Pages table of the SiteMap.mdb
' the LinksDataAdapter selects all records and columns from the Links table of the SiteMap.mdb
Dim connString As String = "Data Source=""" + Application.StartupPath + "\SiteMap.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";"
Dim PagesDataAdapter As New OleDbDataAdapter("SELECT * FROM Pages", connString)
Dim LinksDataAdapter As New OleDbDataAdapter("SELECT * FROM Links", connString)
GraphImporter.VertexDataSource = PagesDataAdapter
GraphImporter.EdgeDataSource = LinksDataAdapter
' vertex records are uniquely identified by their Id (in the Pages table)
' edges link the vertices with the FromPageId and ToPageId (in the Links table)
GraphImporter.VertexIdColumnName = "Id"
GraphImporter.FromVertexIdColumnName = "FromPageId"
GraphImporter.ToVertexIdColumnName = "ToPageId"
' create vertices as rectangles shapes, with default size (60, 30)
Dim shapesFactory As New NBasicShapesFactory()
shapesFactory.DefaultSize = New NSizeF(60, 30)
GraphImporter.VertexShapesFactory = shapesFactory
GraphImporter.VertexShapesName = BasicShapes.Rectangle.ToString()
' set stylesheets to be applied to imported vertices and edges
GraphImporter.VertexStyleSheetName = "Vertices"
GraphImporter.EdgeStyleSheetName = "Edges"
' use layered graph layout
Dim layout As New NLayeredGraphLayout()
layout.Direction = LayoutDirection.TopToBottom
layout.LayerAlignment = RelativeAlignment.Near
GraphImporter.Layout = layout
' subscribe for the vertex imported event,
' which is raised when a shape was created for a data source record
AddHandler GraphImporter.VertexImported, AddressOf OnVertexImported
' import
GraphImporter.Import()
' end view init
DrawingView.EndInit()
End Sub
Private Sub OnVertexImported(ByVal dataSourceImporter As NDataSourceImporter, ByVal shape As NShape, ByVal record As INDataRecord)
' display the page title in the shape
Dim text As Object = record.GetColumnValue("Title")
If text Is Nothing Then
shape.Text = "Title not specified"
Else
shape.Text = text.ToString()
End If
shape.SizeToText(New NMarginsF(10))
End Sub
Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
위 내용은 아래 페이지를 옮겼습니다.
How to automatically create a diagram from a database?
행복한 고수되십시요.
woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\