基本信息
源码名称:GDI树状图 例子源码下载
源码大小:0.04M
文件格式:.rar
开发语言:C#
更新时间:2015-05-23
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍


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

        }
    }