public static Person GetPerson(string id, string name, string manager, string title, string department, string extension, string email) { Person p = new Person(); p.ID = id; p.Name = name; p.Manager = manager; p.Title = title; p.Department = department; p.Extension = extension; p.Email = email; return p; }
private void SetCurrentRootFromInit() { if (!string.IsNullOrEmpty(CurrentRootStr)) { CurrentRoot = persons.First(s => CurrentRootStr == s.ID); } }
private void DrawNode(Person parent, bool subset) { if (CurrentRoot == null) { // Check if the current node is the parent node or not if (string.IsNullOrEmpty(parent.Manager)) { AddBox(MyCanvas, parent.X, parent.Level * levelHight, null, parent.ID, parent.Name, parent.Title, parent.Department, parent.Extension, false, true, parent.HiddenSubNodes > 0, parent.Field1, parent.Field2, parent.Field3, parent.Field4, parent.Field5, parent.dotted); } } else if(!subset) { AddBox(MyCanvas, parent.X, parent.Level * levelHight, null, parent.ID, parent.Name, parent.Title, parent.Department, parent.Extension, false, true, parent.HiddenSubNodes > 0, parent.Field1, parent.Field2, parent.Field3, parent.Field4, parent.Field5, parent.dotted); } // Get the child nodes var results = from n in persons where n.Manager == parent.Name && n.Opened == true select n; foreach (Person p in results) { AddBox(MyCanvas, p.X, p.Level * levelHight, parent.X, p.ID, p.Name, p.Title, p.Department, p.Extension, true, p.SubNodes > 0, p.HiddenSubNodes > 0, p.Field1, p.Field2, p.Field3, p.Field4, p.Field5, p.dotted); DrawNode(p,true); } }
private void DrawNode(Person parent) { DrawNode(parent, false); }
private void CalculateX(Person parent) { if (parent.SubNodes > 0) { var result = from n in persons where n.Manager == parent.Name && n.Opened == true orderby n.NodeOrder select n; Person[] nodes = result.ToArray(); // Calculate the startX for each node double start = parent.StartX; for (int i = 0; i < nodes.Length; i++) { nodes[i].StartX = start; nodes[i].X = nodes[i].StartX + nodes[i].MinChildWidth / 2; CalculateX(nodes[i]); start = start + nodes[i].MinChildWidth; } // realign the parent node to the middle of the child nodes if (nodes.Length > 1) { parent.X = (nodes[0].X + nodes[nodes.Length - 1].X) / 2; } else // root element { parent.X = nodes[0].X; } } }
private void CalculateWidth(Person parent) { if (parent.SubNodes > 0) { var result = from n in persons where n.Manager == parent.Name && n.Opened == true orderby n.NodeOrder select n; Person[] nodes = result.ToArray(); double width = 0; for (int i = 0; i < nodes.Length; i++) { // calculate the width of the child before adding it to the parent CalculateWidth(nodes[i]); // calculate the new width width = width + nodes[i].MinChildWidth; } if (width > parent.MinChildWidth) { parent.MinChildWidth = width; if (MyCanvas.Width < width) { MyCanvas.Width = width; //totalWidth = width; } } } }
public void SetLevel(Person parent, int level) { Debug.WriteLine(parent.Name + "-" + level); // Set the node level parent.Level = level; // Calculate the total height based on the number of levels if (totalHight < levelHight * (level + 2)) { totalHight = levelHight * (level + 2); MyCanvas.Height = totalHight; } // Select the closed items under this parent var resultN = from n in persons where n.Manager == parent.Name && n.Opened == false select n; // Get the closed nodes number parent.HiddenSubNodes = resultN.Count(); // Select the opend nodes under this parent var result = from n in persons where n.Manager == parent.Name && n.Opened == true select n; Person[] nodes = result.ToArray(); // Get the Opend nodes number parent.SubNodes = nodes.Length; // Call the child nodes for (int i = 0; i < nodes.Length; i++) { nodes[i].NodeOrder = i + 1; nodes[i].MinChildWidth = buttonWidth + minHorizontalSpace; SetLevel(nodes[i], parent.Level + 1); } }
public void Refresh(Person employeePerson) { MyCanvas.Children.Clear(); MyCanvas.Width = buttonWidth; MyCanvas.Height = buttonHeight; totalWidth = MyCanvas.Width; totalHight = MyCanvas.Height; employeePerson.MinChildWidth = buttonWidth + minHorizontalSpace; employeePerson.StartX = 0; employeePerson.X = employeePerson.MinChildWidth / 2; SetLevel(employeePerson, 1); CalculateWidth(employeePerson); CalculateX(employeePerson); DrawNode(employeePerson); }