Example #1
0
        /// <summary>
        /// Изменение привязки объекта при перемещении объекта по дереву
        /// </summary>
        /// <param name="attachedObjects">Элемент с объектами</param>
        /// <param name="oldNum">Старый номер объекта</param>
        /// <param name="newNum">Новый номер объекта</param>
        private void ChangeAttachedObjectAfterMove(
            AttachedObjects attachedObjects, int oldNum, int newNum)
        {
            string attachingObjectsStr = attachedObjects.Value;

            string[] attachingObjectsArr = attachingObjectsStr.Split(' ');
            for (int index = 0; index < attachingObjectsArr.Length; index++)
            {
                if (attachingObjectsArr[index] == newNum.ToString())
                {
                    attachingObjectsArr[index] = oldNum.ToString();
                }
                else if (attachingObjectsArr[index] == oldNum.ToString())
                {
                    attachingObjectsArr[index] = newNum.ToString();
                }
            }
            attachedObjects.SetValue(string.Join(" ", attachingObjectsArr));
        }
Example #2
0
        /// <summary>
        /// Изменение привязки объекта при удалении объекта из дерева
        /// </summary>
        /// <param name="attachedObjects">Элемент для обработки</param>
        /// <param name="deletedObjectNum">Номер удаленного объекта</param>
        private void ChangeAttachedObjectAfterDelete(
            AttachedObjects attachedObjects, int deletedObjectNum)
        {
            if (attachedObjects?.Value == string.Empty)
            {
                return;
            }

            string attachingObjectsStr = attachedObjects.Value;

            int[] attachingObjectsArr = attachingObjectsStr.Split(' ')
                                        .Select(int.Parse).ToArray();
            for (int index = 0; index < attachingObjectsArr.Length; index++)
            {
                int attachedObjectNum = attachingObjectsArr[index];
                if (attachedObjectNum > deletedObjectNum)
                {
                    attachingObjectsArr[index] = attachedObjectNum - 1;
                }
            }
            attachedObjects.SetValue(string.Join(" ", attachingObjectsArr));
        }