Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Tree Chart Generator

, 18 Nov 2007 CPOL
An article on the development of a Tree Chart Generator
TreeGenerator.zip
TreeGenerator
TestTreeGenerator
bin
Debug
TestTreeGenerator.exe
TestTreeGenerator.vshost.exe
TreeGenerator.dll
Properties
Settings.settings
TreeGenerator
bin
Debug
TreeGenerator.dll
TreeGenerator.vshost.exe
ClassDiagram1.cd
Properties
TreeData.xsc
TreeData.xss
TreeGenerator.suo
treegeneratoraspnet.zip
App_Data
Bin
TreeGenerator.dll
TreeGenerator.dll.refresh
TreeGenerator.pdb
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TreeGenerator;
using System.Drawing;
using System.Web.Caching;
using System.Xml;

public partial class ShowTree : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
     
    }
    /// <summary>
    /// Generates tree data randomely on the fly.
    /// In real life this function would be used to get the data from the DB.
    /// </summary>
    /// <param name="topID"></param>
    /// <returns></returns>
    private TreeGenerator.TreeData.TreeDataTableDataTable GetDT(string topID)
    {
        TreeGenerator.TreeData.TreeDataTableDataTable Result = new TreeData.TreeDataTableDataTable();
        //add the parent
        Result.AddTreeDataTableRow(topID, "", topID, "");
       
        Random r = new Random();
        int childCount = r.Next(4);
        string childName;
        for(int i=0;i<=childCount;i++)
        {
            //randomely add some children
            childName = topID + "-" + i.ToString();
            Result.AddTreeDataTableRow(childName, topID, childName, "");
        }
        return Result;
    }
    
    /// <summary>
    /// Show the Tree based on what the user clicked
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnShowBOM_Click(object sender, EventArgs e)
    {
        if (txtItem.Text.Trim().Length > 0)
        {
            GenerateChart(txtItem.Text);
        }
    }
    /// <summary>
    /// This is called based on where the user clicked on the imagemap
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void impBOM_Click(object sender, ImageMapEventArgs e)
    {
        GenerateChart(e.PostBackValue);
    }
    /// <summary>
    /// Generate the chart image and save it in the cache, to be used by the image.aspx
    /// </summary>
    private void GenerateChart(string mItem)
    {
        //crate the chart object
         TreeGenerator.TreeBuilder currentBOM = new TreeGenerator.TreeBuilder(GetDT(mItem));
        
        //specify visual properties
        currentBOM.HorizontalSpace = 15;
        currentBOM.VerticalSpace = 15;
        currentBOM.FontSize = 7;
        currentBOM.BoxHeight = 80;
        currentBOM.BoxWidth = 80;
        currentBOM.LineColor = System.Drawing.ColorTranslator.FromHtml("#BFBFC9");
        currentBOM.FontColor = System.Drawing.ColorTranslator.FromHtml("#3B4164");
        System.Drawing.Image OC =
           System.Drawing.Image.FromStream(currentBOM.GenerateTree(mItem,
              System.Drawing.Imaging.ImageFormat.Bmp));

        string nameOfImage = Session.SessionID + "CurrentImage";
        //save in the cache, to be used by the page creating the image
        Cache.Insert(nameOfImage, OC, null, DateTime.MaxValue, TimeSpan.FromMinutes(1), CacheItemPriority.NotRemovable, null);
        //update the item image map
        //supply the image name by querystring
        impBOM.ImageUrl = "~/OrgChartImage.aspx?ID=" + nameOfImage;
        //remove all hotspots
        impBOM.HotSpots.Clear();
        //regenerate the hotspots.
        foreach (XmlNode oNode in currentBOM.xmlTree.SelectNodes("//Node"))
        {
            RectangleHotSpot RectHS = new RectangleHotSpot();
            RectHS.HotSpotMode = HotSpotMode.PostBack;
            Rectangle currentRect = currentBOM.getRectangleFromNode(oNode);
            RectHS.Top = currentRect.Top;
            RectHS.Bottom = currentRect.Bottom;
            RectHS.Left = currentRect.Left;
            RectHS.Right = currentRect.Right;
            RectHS.PostBackValue = oNode.Attributes["nodeID"].InnerText;
            RectHS.AlternateText = oNode.Attributes["nodeDescription"].InnerText;
            impBOM.HotSpots.Add(RectHS);
            //SelectedEmployee = EmpRec.EmployeeData.EmployeeName;

        }
    }

    
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rotem Sapir
Web Developer
Israel Israel
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 18 Nov 2007
Article Copyright 2007 by Rotem Sapir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid