public void BuildRoot() { using (IUnitOfWork uow = new UnitOfWork()) { IList <Model.Category> lstCategory = uow.CategoryRepository.All(); if (lstCategory == null) { return; } TreeTag treeTag; foreach (Model.Category cate in lstCategory) { TreeNode node = new TreeNode(cate.CategoryName); treeTag = new TreeTag(); treeTag.NodeTye = TreeTag.Types.Category; treeTag.CateId = cate.CategoryId; treeTag.CateName = cate.CategoryName; node.Tag = treeTag; List <Model.Series> lstSerie = uow.SeriesRepository.FindByCategory(cate.CategoryId); BuildSerie(lstSerie, node, treeTag, uow); _mTree.Nodes.Add(node); } uow.Commit(); } }
public static List <Model.Product> FindProductByParent(TreeTag tag) { List <Model.Product> lstProduct = null; using (IUnitOfWork uow = new UnitOfWork()) { if (tag.NodeTye == TreeTag.Types.Category) { lstProduct = uow.ProductRepository.FindByCategory(tag.CateId); uow.Commit(); } else if (tag.NodeTye == TreeTag.Types.Serie) { lstProduct = uow.ProductRepository.FindBySerie(tag.SerieId); } else if (tag.NodeTye == TreeTag.Types.Line) { lstProduct = uow.ProductRepository.FindByLine(tag.LineId); } uow.Commit(); } return(lstProduct); }
private void BuildLine(List <Model.ProductLine> lstLine, TreeNode cateNode, TreeTag Tag) { if (lstLine == null) { return; } foreach (Model.ProductLine line in lstLine) { TreeNode node = new TreeNode(line.ProductLineName); TreeTag treeTag = new TreeTag(); treeTag.NodeTye = TreeTag.Types.Line; treeTag.CateId = Tag.CateId; treeTag.CateName = Tag.CateName; treeTag.LineId = line.ProductLineId; treeTag.LineName = line.ProductLineName; treeTag.SerieName = Tag.SerieName; treeTag.SerieId = Tag.SerieId; node.Tag = treeTag; cateNode.Nodes.Add(node); } }
private void BuildSerie(List <Model.Series> lstSerie, TreeNode subNode, TreeTag subTag, IUnitOfWork uow) { if (lstSerie == null) { return; } foreach (Model.Series serie in lstSerie) { TreeNode node = new TreeNode(serie.SerieName); TreeTag treeTag = new TreeTag(); treeTag.NodeTye = TreeTag.Types.Serie; treeTag.CateId = subTag.CateId; treeTag.CateName = subTag.CateName; treeTag.SerieId = serie.SerieId; treeTag.SerieName = serie.SerieName; node.Tag = treeTag; subNode.Nodes.Add(node); List <Model.ProductLine> lstLine = uow.ProductLineRepository.FindBySerie(serie.SerieId); BuildLine(lstLine, node, treeTag); } }
public static TreeNode FindNode(TreeNodeCollection NodesCollection, TreeTag treeTag) { TreeNode returnNode = null; // Default value to return foreach (TreeNode checkNode in NodesCollection) { if (checkNode.Tag == treeTag) //checks if this node name is correct { returnNode = checkNode; } else if (checkNode.Nodes.Count > 0) //node has child { returnNode = FindNode(checkNode.Nodes, treeTag); } if (returnNode != null) //check if founded do not continue and break { return(returnNode); } } return(null); }