Regarding Dataset Demo

Hi All,

Can you please guide me using Dataset demo using sql server 2005 database. can i add/delete nodes also.
can you please provide me the sample code to add new node and edge

Thanks in advance

Regards,
Mandeepinder Singh

Delete is already there in the sample.



What UI do you want for “add node”?



vb or c#?

i needed it for c#

i want an option to add new node on right click in context menu.
a parent can hav n number of child and a child can hav further option to add child under it n times.

sorry for the delay, I’ve been fighting off a cold the last 3 days.



ok… add these bits:



in FormDiagram.cs:



<br /> protoLink.Orthogonal = true; // existing line <br /> goView1.NewLinkPrototype = protoLink; // new <br />



and



<br /> public static PersonNode AddPerson(GoDocument doc, GoView view, PersonNode boss) { <br /> <br /> // if this sample has it's own GoDocument class, that would be a better place for this method. <br /> doc.StartTransaction(); <br /> PersonNode node = new PersonNode(); <br /> node.Name = "new employee"; <br /> doc.Add(node); <br /> if (boss != null) { <br /> view.CreateLink(boss.FromPort, node.ToPort); <br /> } <br /> AutoLayout(doc); <br /> doc.FinishTransaction("node added"); <br /> return node; <br /> } <br /> <br />



and, to PersonNode.cs:



<br />using System.Windows.Forms; <br />



and



<br /> public override GoContextMenu GetContextMenu(GoView view) { <br /> if (view is GoOverview) return null; <br /> GoContextMenu cm = new GoContextMenu(view); <br /> if (CanDelete()) { <br /> cm.MenuItems.Add(new MenuItem("Cut", new EventHandler(this.Cut_Command))); <br /> } <br /> cm.MenuItems.Add(new MenuItem("Add Direct Report", new EventHandler(this.Add_DirectReport))); <br /> return cm; <br /> } <br /> <br /> public void Cut_Command(Object sender, EventArgs e) { <br /> GoView v = GoContextMenu.FindView(sender as MenuItem); <br /> if (v != null) <br /> v.EditCut(); <br /> } <br /> <br /> public void Add_DirectReport(Object sender, EventArgs e) { <br /> GoView v = GoContextMenu.FindView(sender as MenuItem); <br /> if (v != null) { <br /> FormDiagram.AddPerson(v.Document, v, this); <br /> } <br /> } <br />



that should add a node, ready to edit for details.

Thanks for the reply

I forgot to tell you that i want to use this in web application.

sigh. yes, you did. Are you having a problem with this code in a web app?



Have you looked at GoXam for Silverlight? The data integration is much nicer in XAML apps. OrgChartEditor is the GoXam version of DataSetDemo.



GoXam samples here

hi

Yes im having problem with this line of code in personnode.cs

using System.Windows.Forms;

System.Windows.Forms not available here

public void Add_DirectReport(Object sender, EventArgs e)
{

    GoView v = GoContextMenu.FindView(sender as MenuItem);

    if (v != null)
    {
      
       FormDiagram.AddPerson(v.Document, v, this);
       
    }

}

so FormDiagram.AddPerson(v.Document, v, this);
is also not valid here

What should i do to replace this?
Thanks :)

OK, for ASP.NET, it was cleaner to create a GoDocument subclass and put some code in there.



DataSetDoc.cs

<br />using System; <br />using System.Collections.Generic; <br />using System.Linq; <br />using System.Web; <br /> <br />using Northwoods.GoWeb; <br />using Northwoods.GoWeb.Layout; <br /> <br />/// <summary> <br />/// Summary description for DataSetDemoDoc <br />/// </summary> <br />/// <br />namespace DataSetDemo { <br /> <br /> public class DataSetDemoDoc : GoDocument { <br /> public DataSetDemoDoc() { <br /> // <br /> // TODO: Add constructor logic here <br /> // <br /> <br /> } <br /> <br /> public PersonNode AddPerson(GoView view, PersonNode boss) { <br /> <br /> StartTransaction(); <br /> PersonNode node = new PersonNode(); <br /> node.ID = GetUniqueID(); <br /> node.Boss = boss.ID; <br /> node.Name = "new employee"; <br /> this.Add(node); <br /> <br /> if (boss != null) { <br /> view.CreateLink(boss.FromPort, node.ToPort); <br /> } <br /> <br /> AutoLayout(); <br /> FinishTransaction("node added"); <br /> <br /> return node; <br /> } <br /> <br /> public string GetUniqueID() { <br /> int max = -1; <br /> foreach (GoObject o in this) { <br /> PersonNode pn = o as PersonNode; <br /> if (pn != null) { <br /> try { <br /> int id = Convert.ToInt32(pn.ID); <br /> if (id > max) max = id; <br /> } <br /> catch { } // ignore IDs that don't convert to int <br /> } <br /> } <br /> max++; <br /> return max.ToString(); <br /> } <br /> <br /> public void AutoLayout() { <br /> GoLayoutTree layout = new GoLayoutTree(); <br /> layout.Document = this; <br /> GoLayoutTreeNetwork network = new GoLayoutTreeNetwork(this); <br /> foreach (GoObject obj in this) { <br /> PersonNode node = obj as PersonNode; <br /> if (node == null) continue; <br /> if (!node.CanView()) { <br /> network.DeleteNode(node); <br /> } <br /> else { <br /> node.UpdateHandle(); <br /> } <br /> } <br /> layout.Network = network; <br /> layout.Angle = 90; <br /> layout.LayerSpacing = 35; <br /> layout.Alignment = GoLayoutTreeAlignment.CenterSubtrees; <br /> layout.Style = GoLayoutTreeStyle.LastParents; <br /> layout.AlternateDefaults.Angle = 0; <br /> layout.AlternateDefaults.Alignment = GoLayoutTreeAlignment.Start; <br /> layout.AlternateDefaults.NodeIndent = 50; <br /> layout.AlternateDefaults.LayerSpacing = -30; <br /> layout.AlternateDefaults.NodeSpacing = 10; <br /> layout.AlternateDefaults.PortSpot = GoObject.MiddleBottom; <br /> layout.AlternateDefaults.ChildPortSpot = GoObject.MiddleLeft; <br /> layout.PerformLayout(); <br /> } <br /> } <br />} <br />



and this code goes in PersonNode:



<br /> public override GoContextMenu GetContextMenu(GoView view) { <br /> if (view is GoOverview) return null; <br /> GoContextMenu cm = new GoContextMenu(view); <br /> if (CanDelete()) { <br /> cm.MenuItems.Add(new GoMenuItem("Cut", "goAction('cut','GoView1')")); <br /> } <br /> cm.MenuItems.Add(new MenuItem("Add Direct Report", new EventHandler(this.Add_DirectReport))); <br /> return cm; <br /> } <br /> <br /> public void Add_DirectReport(Object sender, EventArgs e) { <br /> <br /> // "this" is the "boss" for the new node <br /> GoView view = GoContextMenu.FindView(sender as MenuItem); <br /> if (view != null) { <br /> <br /> DataSetDemoDoc doc = view.Document as DataSetDemoDoc; <br /> if (doc != null) { <br /> doc.AddPerson(view, this); <br /> } <br /> } <br /> } <br />



in WebForm1.aspx.cs



<br /> protected void GoView1_SessionStarted(object sender, System.EventArgs e) { <br /> // Initialize the session variables <br /> Session["myInitDone"] = false; <br /> Session["myHandlingDocumentEvents"] = false; <br /> <br /> // new 2 lines are new... <br /> DataSetDemoDoc doc = new DataSetDemoDoc(); <br /> GoView1.Document = doc; <br />



and the protolink assignment from earlier code.



forgot this:



in Page_Load:



GoView1.DataRenderer.ContextMenus = true;