Beispiel #1
0
        private void BindTreeview()
        {
            var hierarchicalData = new CategoryRepository().GethierarchicalTree(null, true);

            tv1.Nodes.Clear();
            var root = new CustomTreeNode("گروه ها", "0", "", "", "");

            tv1.Nodes.Add(root);
            BindTreeRecursive(hierarchicalData, root);
        }
Beispiel #2
0
        private void BindTreeRecursive(List <Repository.Entity.Domain.Category> hierarchicalData, TreeNode node)
        {
            foreach (Repository.Entity.Domain.Category category in hierarchicalData)
            {
                if (category.Children.Any())
                {
                    var n = new CustomTreeNode(TreeNodeSelectAction.None, category.Name + "(" + category.Code + ")", "", "", category.Id.ToString(), category.Name);
                    node.ChildNodes.Add(n);
                    BindTreeRecursive(category.Children.ToList(), n);
                }
                else
                {
                    var n = new CustomTreeNode(category.Name, "", "", category.Id.ToString(), category.Name);
                    node.ChildNodes.Add(n);
                    if (n.Parent != null)
                    {
                        n.Parent.SelectAction = TreeNodeSelectAction.None;
                    }

                    if (new ProductRepository().Get(a => a.ProductCategoryId == category.Id).Any())
                    {
                        var catRelatedProducts = new ProductRepository().Get(a => a.ProductCategoryId == category.Id).ToList();
                        n.SelectAction = TreeNodeSelectAction.None;

                        foreach (Repository.Entity.Domain.Product product in catRelatedProducts)
                        {
                            if (string.IsNullOrWhiteSpace(txtSearchTree.Text))
                            {
                                n.ChildNodes.Add(new CustomTreeNode(product.Name + "(" + product.Code + ")", product.Id.ToString(), product.Name, product.ProductCategoryId.ToString(), product.ProductCategory?.Name));
                            }
                            else if (product.Name.Contains(txtSearchTree.Text) || product.Code.Contains(txtSearchTree.Text))
                            {
                                n.ChildNodes.Add(new CustomTreeNode(product.Name + "(" + product.Code + ")", product.Id.ToString(), product.Name, product.ProductCategoryId.ToString(), product.ProductCategory?.Name));
                            }
                        }
                    }
                }
            }
        }