public virtual void Add(BusinessObjectHierarchical parent, BusinessObjectHierarchical item) { _list[parent].Add(item); _list.Add(item, new BusinessObjectHierarchicalCollection()); item._parent = parent; item._tree = this; }
protected BusinessObjectTree(BusinessObjectHierarchical root) { _root = root; _root.Tree = this; _list = new Dictionary <BusinessObjectHierarchical, BusinessObjectHierarchicalCollection>(); _list.Add(_root, new BusinessObjectHierarchicalCollection()); }
public BusinessObjectTreeBindingSource GetBindingSource() { BusinessObjectHierarchical[] list = new BusinessObjectHierarchical[_list[_root].Count]; int i = 0; foreach (BusinessObjectHierarchical item in _list[_root]) { list.SetValue(item, i++); } return(new BusinessObjectTreeBindingSource(list)); }
public void RemoveDB(BusinessObjectHierarchical item) { Remove(item); Database database = new Database(ConnectionStringNameVirtual); using (DbConnection connection = database.GetConnection()) { DbCommand command = item.GetDeleteCommand(); command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); } }
public void AddDB(BusinessObjectHierarchical item) { Add(_root, item); Database database = new Database(ConnectionStringNameVirtual); using (DbConnection connection = database.GetConnection()) { DbCommand command = item.GetInsertCommand(); command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); } }
public List <BusinessObjectHierarchical> GetAll(BusinessObjectHierarchical node) { List <BusinessObjectHierarchical> result = new List <BusinessObjectHierarchical>(); System.Collections.Generic.Stack <BusinessObjectHierarchical> stack = new Stack <BusinessObjectHierarchical>(); stack.Push(node); while (stack.Count > 0) { BusinessObjectHierarchical temp = stack.Pop(); for (int j = _list[temp].Count - 1; j >= 0; j--) { stack.Push(_list[temp][j]); } result.Add(temp); } return(result); }
public BusinessObjectHierarchical Search(Predicate <BusinessObjectHierarchical> method) { BusinessObjectHierarchical result = null; System.Collections.Generic.Stack <BusinessObjectHierarchical> stack = new Stack <BusinessObjectHierarchical>(); stack.Push(_root); while (stack.Count > 0) { BusinessObjectHierarchical temp = stack.Pop(); if (method.Invoke(temp)) { result = temp; } for (int j = _list[temp].Count - 1; j >= 0; j--) { stack.Push(_list[temp][j]); } } return(result); }
private BusinessObjectHierarchical[] GetArray() { int count = _list.Count; BusinessObjectHierarchical[] result = new BusinessObjectHierarchical[count]; int i = 0; System.Collections.Generic.Stack <BusinessObjectHierarchical> stack = new Stack <BusinessObjectHierarchical>(); stack.Push(_root); while (stack.Count > 0) { BusinessObjectHierarchical temp = stack.Pop(); for (int j = _list[temp].Count - 1; j >= 0; j--) { stack.Push(_list[temp][j]); } result[i++] = temp; } return(result); }
public virtual void Remove(BusinessObjectHierarchical item) { System.Collections.Generic.Queue <BusinessObjectHierarchical> queue = new Queue <BusinessObjectHierarchical>(); queue.Enqueue(item); while (queue.Count > 0) { BusinessObjectHierarchical temp = queue.Dequeue(); Dictionary <BusinessObjectHierarchical, BusinessObjectHierarchicalCollection> .Enumerator it = _list.GetEnumerator(); while (it.MoveNext()) { if (it.Current.Value.Remove(temp)) { break; } } foreach (BusinessObjectHierarchical child in _list[temp]) { queue.Enqueue(child); } _list.Remove(temp); } }
public void Add(BusinessObjectHierarchical item) { Add(_root, item); }
protected internal void ChangeNodeParent(BusinessObjectHierarchical parent, BusinessObjectHierarchical item) { _list[item._parent].Remove(item); _list[parent].Add(item); item._parent = parent; }
protected internal BusinessObjectHierarchicalCollection GetChilds(BusinessObjectHierarchical item) { return(_list[item]); }