示例#1
0
 public virtual void Add(BusinessObjectHierarchical parent, BusinessObjectHierarchical item)
 {
     _list[parent].Add(item);
     _list.Add(item, new BusinessObjectHierarchicalCollection());
     item._parent = parent;
     item._tree   = this;
 }
示例#2
0
        protected BusinessObjectTree(BusinessObjectHierarchical root)
        {
            _root = root;

            _root.Tree = this;
            _list      = new Dictionary <BusinessObjectHierarchical, BusinessObjectHierarchicalCollection>();
            _list.Add(_root, new BusinessObjectHierarchicalCollection());
        }
示例#3
0
        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));
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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();
            }
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
 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);
     }
 }
示例#10
0
 public void Add(BusinessObjectHierarchical item)
 {
     Add(_root, item);
 }
示例#11
0
 protected internal void ChangeNodeParent(BusinessObjectHierarchical parent, BusinessObjectHierarchical item)
 {
     _list[item._parent].Remove(item);
     _list[parent].Add(item);
     item._parent = parent;
 }
示例#12
0
 protected internal BusinessObjectHierarchicalCollection GetChilds(BusinessObjectHierarchical item)
 {
     return(_list[item]);
 }