博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Web功能之组织结构图
阅读量:6363 次
发布时间:2019-06-23

本文共 8184 字,大约阅读时间需要 27 分钟。

    前提:由于项目需要显示组织结构图的形式 

    工具:VS2010 

    项目:ASP.NET 自带的web项目 (带模板页)

    插件:OrgChart(依赖:OrgChart.dll)、JOrgChart

    不多说 先看效果

    1、OrgChart实现效果

    

 

    2、JOrgChart效果

    

    基础实体类代码:

public class SysUserModel : OrgNode    {        public int SysUserId { get; set; }        public string SysUserName { get; set; }        public int SysUserParentId { get; set; }        public override string OrgNodeHtml()        {            this.SysUserName = this.Text;            string str = "
"; //str += "
"; str += "
"; //str += "
"; str += "
";//" + this.SysUserGroupId + " str += "
"; // str += "
"; //str += "
"; str += "
 " + this.SysUserGroupId + "
 
 " + this.SysUserName + "
 
 
"; str += "
"; return str; } }
View Code

    1、OrgChart前台实现代码: 

<%@ Page Title="OrgChart" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %><%@ Register Assembly="OrgChart" Namespace="OrgCharDesigner" TagPrefix="cc1" %>
View Code

        OrgChart后台实现代码:

SysUserModel sysUserModel = new SysUserModel();        DataTable dt;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                ListBind();            }        }               protected void ListBind()        {            try            {                dt = dtList();                SysUserModel root = new SysUserModel();                root.SysUserId = 1;                root.Text = "CEO";                root.SysUserParentId = 0;                SetNodeChild(dt, root);                OrgChart1.Node = root;            }            catch (Exception ex)            {                throw ex;            }        }        private void SetNodeChild(DataTable dt, SysUserModel root)        {            DataRow[] rows = dt.Select(" SysUserParentId = '" + root.SysUserId + "'");// 选出所有子节点            foreach (DataRow drChild in rows)            {                SysUserModel node = new SysUserModel();                node.Text = drChild["SysUserName"].ToString();                node.SysUserId = int.Parse(drChild["SysUserId"].ToString());                node.SysUserParentId = int.Parse(drChild["SysUserParentId"].ToString());                SetNodeChild(dt, node);                root.Nodes.Add(node);            }        }        private DataTable dtList()        {            DataTable dt = new DataTable();            dt.Columns.Add("SysUserId");            dt.Columns.Add("SysUserName");            dt.Columns.Add("SysUserParentId");            dt.Rows.Add();            dt.Rows[0]["SysUserId"] = "1";            dt.Rows[0]["SysUserName"] = "CEO";            dt.Rows[0]["SysUserParentId"] = "0";            dt.Rows.Add();            dt.Rows[1]["SysUserId"] = "2";            dt.Rows[1]["SysUserName"] = "总经理";            dt.Rows[1]["SysUserParentId"] = "1";            dt.Rows.Add();            dt.Rows[2]["SysUserId"] = "3";            dt.Rows[2]["SysUserName"] = "副总经理";            dt.Rows[2]["SysUserParentId"] = "2";            dt.Rows.Add();            dt.Rows[3]["SysUserId"] = "4";            dt.Rows[3]["SysUserName"] = "项目一组";            dt.Rows[3]["SysUserParentId"] = "3";            dt.Rows.Add();            dt.Rows[4]["SysUserId"] = "5";            dt.Rows[4]["SysUserName"] = "项目二组";            dt.Rows[4]["SysUserParentId"] = "3";            dt.Rows.Add();            dt.Rows[5]["SysUserId"] = "6";            dt.Rows[5]["SysUserName"] = "运营总经理";            dt.Rows[5]["SysUserParentId"] = "1";            dt.Rows.Add();            dt.Rows[6]["SysUserId"] = "7";            dt.Rows[6]["SysUserName"] = "运营副总经理";            dt.Rows[6]["SysUserParentId"] = "6";            dt.Rows.Add();            dt.Rows[7]["SysUserId"] = "8";            dt.Rows[7]["SysUserName"] = "运营一组";            dt.Rows[7]["SysUserParentId"] = "7";            dt.Rows.Add();            dt.Rows[8]["SysUserId"] = "9";            dt.Rows[8]["SysUserName"] = "运营二组";            dt.Rows[8]["SysUserParentId"] = "7";            return dt;        }
View Code

    2、JOrgChart 前台实现代码:

<%@ Page Title="jOrgChart" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"    CodeBehind="About.aspx.cs" Inherits="WebApplication1.About" %>    
<%=html%>
View Code

         JOrgChart 后台实现代码:

StringBuilder str = new StringBuilder();        DataTable dt;        protected string html;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                html = ListBind();            }        }        protected string ListBind()        {            try            {                dt = dtList();                SysUserModel root = new SysUserModel();                str.Append(" 
  • CEO "); root.SysUserId = 1; root.Text = "CEO"; root.SysUserParentId = 0; SetNodeChild(dt, root); str.AppendLine("
"); return str.ToString(); } catch (Exception ex) { throw ex; } } private void SetNodeChild(DataTable dt, SysUserModel root) { DataRow[] rows = dt.Select(" SysUserParentId = '" + root.SysUserId + "'");// 选出所有子节点 if (rows.Length > 0) { str.Append("
    "); foreach (DataRow drChild in rows) { str.AppendFormat("
  • {1}", drChild["SysUserId"].ToString(), drChild["SysUserName"].ToString()); SysUserModel node = new SysUserModel(); node.Text = drChild["SysUserName"].ToString(); node.SysUserId = int.Parse(drChild["SysUserId"].ToString()); node.SysUserParentId = int.Parse(drChild["SysUserParentId"].ToString()); SetNodeChild(dt, node); str.Append("
  • "); } str.Append("
"); } } private DataTable dtList() { DataTable dt = new DataTable(); dt.Columns.Add("SysUserId"); dt.Columns.Add("SysUserName"); dt.Columns.Add("SysUserParentId"); dt.Rows.Add(); dt.Rows[0]["SysUserId"] = "1"; dt.Rows[0]["SysUserName"] = "CEO"; dt.Rows[0]["SysUserParentId"] = "0"; dt.Rows.Add(); dt.Rows[1]["SysUserId"] = "2"; dt.Rows[1]["SysUserName"] = "总经理"; dt.Rows[1]["SysUserParentId"] = "1"; dt.Rows.Add(); dt.Rows[2]["SysUserId"] = "3"; dt.Rows[2]["SysUserName"] = "副总经理"; dt.Rows[2]["SysUserParentId"] = "2"; dt.Rows.Add(); dt.Rows[3]["SysUserId"] = "4"; dt.Rows[3]["SysUserName"] = "项目一组"; dt.Rows[3]["SysUserParentId"] = "3"; dt.Rows.Add(); dt.Rows[4]["SysUserId"] = "5"; dt.Rows[4]["SysUserName"] = "项目二组"; dt.Rows[4]["SysUserParentId"] = "3"; dt.Rows.Add(); dt.Rows[5]["SysUserId"] = "6"; dt.Rows[5]["SysUserName"] = "运营总经理"; dt.Rows[5]["SysUserParentId"] = "1"; dt.Rows.Add(); dt.Rows[6]["SysUserId"] = "7"; dt.Rows[6]["SysUserName"] = "运营副总经理"; dt.Rows[6]["SysUserParentId"] = "6"; dt.Rows.Add(); dt.Rows[7]["SysUserId"] = "8"; dt.Rows[7]["SysUserName"] = "运营一组"; dt.Rows[7]["SysUserParentId"] = "7"; dt.Rows.Add(); dt.Rows[8]["SysUserId"] = "9"; dt.Rows[8]["SysUserName"] = "运营二组"; dt.Rows[8]["SysUserParentId"] = "7"; return dt; }
View Code

 

以上是本人对于组织结构图的总结 如有好的建议 请您留下  以便新手学习 利人利自!

项目下载地址:

 

转载于:https://www.cnblogs.com/yhyjy/p/3889858.html

你可能感兴趣的文章
数组去重:双for循环数组去重
查看>>
数据迁移方案 + Elasticsearch在综合搜索列表实现
查看>>
干货 | 分分钟教你用Python创建一个区块链
查看>>
Angular开发实践(八): 使用ng-content进行组件内容投射
查看>>
django rest framework mixins小结
查看>>
<<iOS 与OS X多线程和内存管理>>笔记:Blocks
查看>>
canvas+websocket+vue做一个完整的你画我猜小游戏
查看>>
android复习清单
查看>>
linux进阶
查看>>
工作代码备用
查看>>
spring cloud互联网分布式微服务云平台规划分析--spring cloud定时调度平台
查看>>
Scrapy框架的使用之Scrapy入门
查看>>
说说如何配置 Webpack
查看>>
小程序中使用箭头函数的问题
查看>>
走进 JDK 之 Long
查看>>
Android打地鼠游戏的修改和优化
查看>>
Java异常
查看>>
map、reduce、filter、for...of、for...in等总结
查看>>
html2canvas-实现页面截图
查看>>
入门 | 从文本处理到自动驾驶:机器学习最常用的50大免费数据集
查看>>