Esempio n. 1
0
 /// <summary>
 /// Add node children nodes.
 /// </summary>
 /// <param name="node"></param>
 public void AddChild(PositionNode node)
 {
     if (node != null)
     {
         node.PositionStatusChanged += OnChildPositionStatusChanged;
         Nodes.Add(node);
     }
     else
     {
         throw new ArgumentNullException(nameof(node));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Constructor with children filling.
        /// Call constructor without children filling and then creating all children nodes recursively.
        /// </summary>
        public PositionNode(Position position, IEnumerable <Position> positions, IEnumerable <PositionStatusBitInfo> positionStatusBitsInfo)
            : this(position, positionStatusBitsInfo)
        {
            var childrenPositions = positions.Where(c => c.ParentName == PositionData.Name);

            foreach (var pos in childrenPositions)
            {
                PositionNode posNode = new PositionNode(pos, positions, positionStatusBitsInfo);
                posNode.PositionStatusChanged += OnChildPositionStatusChanged;
                Nodes.Add(posNode);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Extract Positions from node and his children.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="positions"></param>
        private void GetPositionsList(PositionNode node, List <Position> positions)
        {
            positions?.Add(node.PositionData);

            if (node.Nodes != null)
            {
                foreach (PositionNode posNode in node.Nodes)
                {
                    GetPositionsList(posNode, positions);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Update position data in Position table and add journal entry at changed status bit
        /// </summary>
        /// <param name="positionNode"></param>
        /// <param name="statusBit"></param>
        private void OnPositionNodeStatusChanged(PositionNode positionNode, PositionStatusBit statusBit)
        {
            _positionsRepository.Update(positionNode.PositionData);

            JournalEntry jEntry = new JournalEntry()
            {
                DateTime              = DateTime.Now,
                Description           = "",
                Position              = positionNode.PositionData,
                PositionStatusBitInfo = statusBit.StatusBitInfo,
                IsIncoming            = statusBit.Value
            };

            JournalEntryCreatedEv?.Invoke(jEntry);
        }
Esempio n. 5
0
        /// <summary>
        /// Execute method for AddChildPositionCommand
        /// </summary>
        /// <param name="parametr"></param>
        private void AddChildPositionExecute(object parametr)
        {
            Position pos = new Position()
            {
                Name       = SelectedNode.PositionData.Name + "_XX",
                ParentName = SelectedNode.PositionData.Name
            };

            var posNode = new PositionNode(pos, _positionStatusBitsInfo)
            {
                IsSelected = true
            };

            SelectedNode.AddChild(posNode);
        }
Esempio n. 6
0
        /// <summary>
        /// Execute method for AddRootPositionCommand
        /// </summary>
        /// <param name="parametr"></param>
        private void AddRootPositionExecute(object parametr)
        {
            Position pos = new Position()
            {
                Name = "ROOT_POS"
            };

            var posNode = new PositionNode(pos, _positionStatusBitsInfo)
            {
                IsSelected = true
            };

            posNode.PositionStatusChanged += OnPositionNodeStatusChanged;

            PositionsTree.Add(posNode);
        }
Esempio n. 7
0
        /// <summary>
        /// Remove child node rerursively.
        /// Return True if removing success, else False.
        /// </summary>
        /// <param name="desiredNode"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>
        private bool RemoveChildFromNode(PositionNode desiredNode, PositionNode parentNode)
        {
            foreach (PositionNode node in parentNode.Nodes)
            {
                if (node == desiredNode)
                {
                    parentNode.Nodes.Remove(node);
                    return(true);
                }

                if (RemoveChildFromNode(desiredNode, node))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="repository"></param>
        public PositionsVM(IGenericRepository <Position> repository, IEnumerable <PositionStatusBitInfo> positionStatusBitsInfo)
        {
            _positionsRepository    = repository;
            _positions              = _positionsRepository.Get();
            _positionStatusBitsInfo = positionStatusBitsInfo;

            PositionsTree = new ObservableCollection <PositionNode>();

            //добавляем узлы верхнего уровня
            foreach (Position pos in _positions)
            {
                if (pos.ParentName == null)
                {
                    PositionNode posNode = new PositionNode(pos, _positions, _positionStatusBitsInfo);
                    posNode.PositionStatusChanged += OnPositionNodeStatusChanged;
                    PositionsTree.Add(posNode);
                }
            }

            JournalEntryCreateReqCommand = new DelegateCommand <object>(
                execute: RiseJournalEntryCreateReqEv
                );

            AddRootPositionCommand = new DelegateCommand <object>(
                execute: AddRootPositionExecute
                );

            AddChildPositionCommand = new DelegateCommand <object>(
                execute: AddChildPositionExecute,
                canExecute: (s) => { return(_selectedNode != null); }
                );

            DeletePositionCommand = new DelegateCommand <object>(
                execute: DeletePositionExecute,
                canExecute: (s) => { return(_selectedNode != null); }
                );

            SavePosDataCommand = new DelegateCommand <object>(
                execute: SavePosDataExecute
                );
        }
Esempio n. 9
0
 /// <summary>
 /// Remove child node all over tree.
 /// Return True if removing success, else False.
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public bool RemoveChildWholeTree(PositionNode node)
 {
     return(RemoveChildFromNode(node, this));
 }
Esempio n. 10
0
 /// <summary>
 /// Invoke PositionStatusChanged event on child StatusBit changed.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="statusBit"></param>
 private void OnChildPositionStatusChanged(PositionNode node, PositionStatusBit statusBit)
 {
     PositionStatusChanged?.Invoke(node, statusBit);
 }