Esempio n. 1
0
        public static List<TreeNodeData> CreateJsonTree(List<TreeView> data)
        {
            List<TreeNodeData> treeList = new List<TreeNodeData>();
            if (data.Count == 0)
            {
                treeList.Add(new TreeNodeData() { id = -100, text = SessionManagement.FactoryDesc, textCss = "customnode", objecttype = "companyNode" });
            }
            TreeNodeData parentTreeNode = new TreeNodeData();
            CreateTreeNodes(data, ref treeList, ref parentTreeNode, false);

            return treeList;
        }
Esempio n. 2
0
        public static void CreateTreeNodes(List<TreeView> data, ref List<TreeNodeData> treeList, ref TreeNodeData parentTreeNode, bool hasChildren = false)
        {
            TreeNodeData objTreeNodeData;
            foreach (var objTreeView in data)
            {
                if (objTreeView.EmployeeID != null)
                {
                    var emp = dataContext.Employees.Where(x => x.EmployeeId == objTreeView.EmployeeID).FirstOrDefault();
                    objTreeNodeData = new TreeNodeData() { id = objTreeView.ID, text = emp.LastName + " " + emp.FirstName, objectid = objTreeView.EmployeeID, textCss = "employeeTitle", objecttype = "employee", iconUrl = "/images/img/employee_16.png" };
                }
                else if (objTreeView.CustomerID != null)
                {
                    var cust = dataContext.Customers.Where(x => x.CustomerId == objTreeView.CustomerID).FirstOrDefault();
                    objTreeNodeData = new TreeNodeData() { id = objTreeView.ID, text = cust.LastName + " " + cust.FirstName, objectid = objTreeView.CustomerID, textCss = "customerTitle", objecttype = "customer", iconUrl = "/images/img/customer_16.png" };
                }
                else
                    objTreeNodeData = new TreeNodeData() { id = objTreeView.ID, text = objTreeView.Description, textCss = "customnode", objecttype = objTreeView.ParentID == null ? "companyNode" : "branchNode" };
                if (hasChildren)
                {
                    if (parentTreeNode.children == null)
                    {
                        parentTreeNode.children = new List<TreeNodeData>();
                    }
                    parentTreeNode.children.Add(objTreeNodeData);
                }
                else
                {
                    treeList.Add(objTreeNodeData);
                }

                if (objTreeView.TreeView1.Any())
                {
                    CreateTreeNodes(objTreeView.TreeView1.ToList(), ref  treeList, ref objTreeNodeData, true);
                }
            }
        }