0

我需要构建一个从网页打印的组织结构图,第二级有 19 到 32 个实体,第三级有 3-7 个实体。

我在http://www.orgchartcomponent.com/default.aspx上尝试了来自 Team Improvementr 的名为 OrgChart 组件的解决方案, 但他们在英国并且不回复他们的电子邮件。

我还尝试了来自 https://www.codeproject.com/Articles/18378/Organization-Chart-Generator的解决方案,该解决方案 具有基本的树形组织结构图。

我通过 Ling 从数据库填充到 SQL,没问题。

Parent Entity - Level 1
|
|
---Child Entity Level 2
|
|
---Child Entity Level 2
|
|
---Child Entity Level 2
|
|
---Child Entity Level 2
|
|
---Child Entity Level 2
|
|
---Child Entity Level 2
          |
          |
          Child Entity Level 3
          |
          |
          Child Entity Level 3
          |
          |
          Child Entity Level 3
          |
          |
          Child Entity Level 3
4

1 回答 1

0
// using recursive function.

    static void Get_Geneology(Employee manager, int Level = 0)  // find all genealogy (kid to great grandkids or employee under a manager down the pyramid)
    {
        string indentLines = new string(' ', Level * 2);
        var managedEmployees = Employees.Where(e => e.Manager_ID == manager.Emp_ID); // 1st call. look all employees under a Manager. or all kids of a father.
        Console.WriteLine($"{indentLines} {Level + 1}-{manager.FirstName}{(managedEmployees.Count() > 0 ? "*" : "")}"); // with * after name mean that person manage sombody or father have kid(s)

        foreach (var employee in managedEmployees) Get_Geneology(employee, Level + 1);   // recursive, find all under under (to the deapest of each people geneology for each manager)
    }
于 2021-10-11T19:20:49.017 回答