// Accounts Types private void FillAccountsTypeTree() { try { Tv_Tree.Nodes.Clear(); //Tv_TypeTree.Nodes.Add(new TreeNode("Products Tree", "-1")); FillAccountsTypeParentNodes(); FillAccountsByType(); } catch (Exception ex) { throw new Exception(ex.Message); } } private void FillAccountsTypeParentNodes() { try { List<accounttype> _list = new List<accounttype>(); _list = _dbml.AccountTypes.Where(p => p.ParentTypeID == null && p.CompanyID.Contains(Ddl_Companies.SelectedValue)).ToList(); if (_list.Count != 0) { foreach (AccountType row in _list) { TreeNode tn = new TreeNode(row.AccountTypeID.ToString() + "--" + row.TypeName, row.AccountTypeID.ToString()); Tv_Tree.Nodes.Add(tn); FillAccountsTypeChildNodes(tn, row.AccountTypeID); } } } catch (Exception ex) { ErrHandler.WriteError(ex.Message); throw new Exception(ex.Message); } } private void FillAccountsTypeChildNodes(TreeNode Parent, Int64 ID) { try { List<accounttype> _list = new List<accounttype>(); _list = _dbml.AccountTypes.Where(p => p.ParentTypeID == ID && p.CompanyID.Contains(Ddl_Companies.SelectedValue)).ToList(); if (_list.Count != 0) { foreach (AccountType row in _list) { TreeNode tn = new TreeNode(row.AccountTypeID.ToString() + "--" + row.TypeName, row.AccountTypeID.ToString()); Parent.ChildNodes.Add(tn); FillAccountsTypeChildNodes(tn, row.AccountTypeID); } } } catch (Exception ex) { ErrHandler.WriteError(ex.Message); throw new Exception(ex.Message); } } private void FillAccountsByType() { foreach (TreeNode Tn in Tv_Tree.Nodes) { FillAccountNodeByType(Tn); GetAccountsChildNodesByType(Tn); //if (Tn.ChildNodes.Count == 0) //{ FillAccountNode(Tn); } //else //{ GetAccountsChildNodes(Tn); } } } private void GetAccountsChildNodesByType(TreeNode Parent) { try { foreach (TreeNode tn in Parent.ChildNodes) { FillAccountNodeByType(tn); GetAccountsChildNodesByType(tn); //if (tn.ChildNodes.Count == 0) //{ FillAccountNode(tn); } //else { GetAccountsChildNodes(tn); } } } catch (Exception ex) { ErrHandler.WriteError(ex.Message); throw new Exception(ex.Message); } } private void FillAccountNodeByType(TreeNode Parent) { try { List<accounttree> _list = new List<accounttree>(); _list = _dbml.AccountTrees.Where(p => p.AccountTypeID == Convert.ToInt64(Parent.Value) && p.CompanyID == Convert.ToInt32(Ddl_Companies.SelectedValue)).ToList(); if (_list.Count != 0) { foreach (AccountTree row in _list) { TreeNode tn = new TreeNode(row.AccountName, row.AccountID.ToString()); Parent.ChildNodes.Add(tn); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)