Nevron Forum

Diagram From Database

https://www.nevron.com/Forum/Topic7225.aspx

By Ron Lucas - Friday, December 14, 2012

I'm trying to figure out how to write an ASP.NET Web Application using Visual Studio 2010 and C#.  I found a knowledgebase article about doing this in WinForms, but I'm new to Visual Studio and need some help making this work in a web application.

http://support.nevron.com/KB/a27/automatically-create-a-diagram-from-a-database.aspx

Here are my files so far which give me an error stating "The name 'DrawingView' does not exist in the current context".

 

*** Default.aspx.cs ***

using System;

using System.Drawing;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Nevron.Diagram;

using Nevron.Diagram.DataImport;

using Nevron.Diagram.Layout;

using Nevron.Diagram.Shapes;

using Nevron.Diagram.ThinWeb;

using Nevron.Dom;

using Nevron.GraphicsCore;

using Nevron.ThinWeb;

namespace DiagramFromDatabase

{

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

// 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

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);

// configure the 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";

// use 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);

// import

GraphImporter.Import();

// end view init

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));

}

}

}

 

 


 

*** Default.aspx ***

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"

CodeBehind="Default.aspx.cs" Inherits="DiagramFromDatabase._Default" %>

<%@ Register assembly="Nevron.Diagram.WebForm, Version=12.11.15.12, Culture=neutral, PublicKeyToken=95bcc3d41b0512e9" namespace="Nevron.Diagram.WebForm" tagprefix="ndwc" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">

</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

<p>

<ndwc:NDrawingView ID="NDrawingView1" runat="server">

</ndwc:NDrawingView>

</p>

</asp:Content>

 

 

*** Web.config ***

<?xml version="1.0"?>

<!--

For more information on how to configure your ASP.NET application, please visit

http://go.microsoft.com/fwlink/?LinkId=169433

-->

<configuration>

<connectionStrings>

<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>

</connectionStrings>

<system.web>

<httpHandlers>

<add path="NevronDiagram.axd" verb="*" type="Nevron.Diagram.WebForm.NDiagramImageResourceHandler"

validate="false" />

<add path="NevronScriptManager.axd" verb="*" type="Nevron.UI.WebForm.Controls.NevronScriptManager"

validate="false" />

</httpHandlers>

<compilation debug="true" targetFramework="4.0">

<assemblies>

<add assembly="Nevron.Diagram.WebForm, Version=12.11.15.12, Culture=neutral, PublicKeyToken=95BCC3D41B0512E9"/>

<add assembly="Nevron.UI.WebForm.Controls, Version=12.11.15.12, Culture=neutral, PublicKeyToken=B5BB1156A58C1618"/>

<add assembly="Nevron.Diagram, Version=12.11.15.12, Culture=neutral, PublicKeyToken=58D0C39AEDB7CB73"/>

<add assembly="Nevron.Presentation, Version=12.11.15.12, Culture=neutral, PublicKeyToken=6656C5D1103E75CC"/>

<add assembly="Nevron.System, Version=12.11.15.12, Culture=neutral, PublicKeyToken=6A987FEAE5E496FD"/>

<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

</assemblies>

</compilation>

<authentication mode="Forms">

<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>

</authentication>

<membership>

<providers>

<clear/>

<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>

</providers>

</membership>

<profile>

<providers>

<clear/>

<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>

</providers>

</profile>

<roleManager enabled="false">

<providers>

<clear/>

<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>

<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>

</providers>

</roleManager>

</system.web>

<system.webServer>

<modules runAllManagedModulesForAllRequests="true"/>

</system.webServer>

</configuration>

 

 

Any help would be much appreciated.

Thanks,

Ron

By Nevron Support - Friday, December 14, 2012

Take a look at the Online Documentation
By Ron Lucas - Friday, December 14, 2012

Are there any example C# projects using to obtain data via the SqlDataAdapter?  I can't find any in the help file, user forum, or knowledgebase.

Thanks,

Ron