Пример #1
0
 /// <summary>
 /// Protected constructor for Answer objects.
 /// Answer objects need not be constructed directly by callers;
 /// use AnswerCollection.CreateAnswer() instead.
 /// </summary>
 /// <param name="parent">The AnswerCollection the answer should be a part of.</param>
 /// <param name="name">The answer name.</param>
 protected Answer(AnswerCollection parent, string name)
 {
     _coll           = parent;
     _name           = name;
     _save           = (!String.IsNullOrEmpty(name) && _name[0] != '(');
     _userExtendible = true;
 }
            /// <summary>
            /// Gets the parent of the requested node,
            /// and deletes the indicated child iteration.
            /// </summary>
            /// <include file="../Shared/Help.xml" path="Help/intAry/param[@name='rptIdx']"/>
            public override void DeleteIteration(int[] rptIdx)
            {
                // get the parent of the requested node,
                // and delete the indicated child iteration
                int iterationToDelete;

                int[] parIdx = TrimIndices(IndexTrimOptions.TruncateLastIndex, out iterationToDelete, rptIdx);
                if (iterationToDelete < 0)                 // there is no iteration to be deleted!
                {
                    return;
                }

                ValueNode <T> parentNode = GetNode(GetNodeOptions.NoBubbleAndFlow, parIdx);

                if (parentNode == null || parentNode.Children == null || iterationToDelete >= parentNode.Children.SetCount)
                {
                    return;
                }

                parentNode.Children.RemoveAt(iterationToDelete);

                if (AnswerCollection != null)
                {
                    AnswerCollection.OnAnswerChanged(this, rptIdx, ValueChangeType.IndexShift);
                }
            }
            /// <summary>
            /// Gets the parent of the requested node,
            /// and inserts an unanswered child iteration at the requested index.
            /// </summary>
            /// <include file="../Shared/Help.xml" path="Help/intAry/param[@name='rptIdx']"/>
            public override void InsertIteration(int[] rptIdx)
            {
                // get the parent of the requested node,
                // and insert an unanswered child iteration at the requested index
                int iterationToInsert;

                int[] parIdx = TrimIndices(IndexTrimOptions.TruncateLastIndex, out iterationToInsert, rptIdx);
                if (iterationToInsert < 0)                 // there is no iteration before which to insert!
                {
                    return;
                }

                ValueNode <T> parentNode = GetNode(GetNodeOptions.NoBubbleAndFlow, parIdx);

                if (parentNode == null || parentNode.Children == null || iterationToInsert >= parentNode.Children.SetCount)
                {
                    return;
                }

                parentNode.Children.Insert(iterationToInsert, new ValueNode <T>());
                if (AnswerCollection != null)
                {
                    AnswerCollection.OnAnswerChanged(this, rptIdx, ValueChangeType.IndexShift);
                }
            }
            /// <summary>
            /// Gets the parent of the requested node, and removes the indicated child iteration from the parent, and re-inserts it at the indicated new position.
            /// </summary>
            /// <include file="../Shared/Help.xml" path="Help/intAry/param[@name='rptIdx']"/>
            /// <param name="newPosition">newPosition</param>
            public override void MoveIteration(int[] rptIdx, int newPosition)
            {
                if (newPosition < 0)
                {
                    throw new ArgumentException("Cannot move repeated data before the first repeat iteration.", "newPosition");
                }
                // get the parent of the requested node,
                // removes the indicated child iteration from the parent,
                // and re-inserts it at the indicated new position
                int iterationToMove;

                int[] parIdx = TrimIndices(IndexTrimOptions.TruncateLastIndex, out iterationToMove, rptIdx);
                if (iterationToMove < 0)                 // there is no iteration to be moved!
                {
                    return;
                }

                ValueNode <T> parentNode = GetNode(GetNodeOptions.NoBubbleAndFlow, parIdx);

                if (parentNode == null || parentNode.Children == null ||
                    (newPosition < iterationToMove && newPosition >= parentNode.Children.SetCount) ||                     // move up
                    (newPosition > iterationToMove && iterationToMove >= parentNode.Children.SetCount))                        // move down
                {
                    // nothing to do
                    return;
                }

                int maxIteration = Math.Max(iterationToMove, newPosition);

                if (maxIteration >= parentNode.Children.SetCount)
                {
                    //[LRS] Need to be able to do the following! (Because other answers in same iteration may be moving.)
                    //throw new ArgumentException("Cannot move repeated data after the final repeat iteration.", "newPosition");
                    parentNode.Children.PrepareForIndex(maxIteration);
                }

                ValueNode <T> movedNode = parentNode.Children.RemoveAt(iterationToMove);

                parentNode.Children.Insert(newPosition, movedNode);
                if (AnswerCollection != null)
                {
                    AnswerCollection.OnAnswerChanged(this, rptIdx, ValueChangeType.IndexShift);
                }
            }
Пример #5
0
 public TypedAnswer(AnswerCollection set, string name)
     : base(set, name)
 {
     _value = new ValueNode <T>();
 }
Пример #6
0
 // Factory method:
 internal static Answer Create <T>(AnswerCollection parent, string name) where T : IValue
 {
     return(new TypedAnswer <T>(parent, name));
 }