/// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="group">Source group reference</param>
        public TemplateFieldsGroup(TemplateFieldsGroup group)
            : this()
        {
            this._nCurrentIndex = group._nCurrentIndex;
            this._nHighIndex    = group._nHighIndex;
            this._nLowIndex     = group._nLowIndex;
            this._sName         = group._sName;

            foreach (string field_id in group._lstFieldIds)
            {
                this._lstFieldIds.Add(new string(field_id.ToCharArray()));
            }
        }
Example #2
0
        /// <summary>
        /// Fill set of grouped fields
        /// </summary>
        /// <param name="group_name">Group name/id</param>
        /// <param name="values">Values</param>
        /// <seealso cref="FieldsExpansion"/>
        /// <returns>True if new page is needed false otherwise</returns>
        public bool FillSet(string group_name, bool format, params object[] values)
        {
            TemplateFieldsGroup _tfgGroup = _lstGroups.Find(x => x.Name.Equals(group_name));

            if (_tfgGroup == null)
            {
                throw (new KeyNotFoundException());
            }

            int _index = _lstGroups.IndexOf(_tfgGroup);

            return(FillSet(_index, format, values));
        }
        /// <summary>
        /// Create group.
        /// </summary>
        /// <param name="low_index">Low set index</param>
        /// <param name="high_index">High set index</param>
        /// <param name="field_ids">Fields ids</param>
        /// <returns>Group</returns>
        public TemplateFieldsGroup Create(string name, int low_index, int high_index, string[] field_ids)
        {
            TemplateFieldsGroup _tfgNewGroup = new TemplateFieldsGroup(name, low_index, high_index, field_ids);

            return(_tfgNewGroup);
        }
Example #4
0
        /// <summary>
        /// Add new group
        /// <param name="fields_ids">Parameters</param>
        /// </summary>
        public void AddGroup(string name, int low_index, int high_index, params string[] fields_ids)
        {
            TemplateFieldsGroup _tfgNewGroup = new TemplateFieldsGroup(name, low_index, high_index, fields_ids);

            _lstGroups.Add(_tfgNewGroup);
        }
Example #5
0
        /// <summary>
        /// Fill set of grouped fields
        /// </summary>
        /// <param name="group_index">Index of group</param>
        /// <param name="values">Values</param>
        /// <seealso cref="FieldsExpansion"/>
        /// <returns>True if new page is needed false otherwise</returns>
        public bool FillSet(int group_index, bool format, params object[] values)
        {
            if ((group_index >= _lstGroups.Count) || (group_index < 0))
            {
                throw new IndexOutOfRangeException("Group index out of range");
            }

            TemplateFieldsGroup _tfgGroup = _lstGroups[group_index];

            int _values_idx = 0;
            int _nStep      = 0;
            int _nElements  = 0;

            foreach (string _sFieldNamePattern in _tfgGroup.FieldIds)
            {
                string _sFieldName;

                _sFieldName = String.Format(_sFieldNamePattern, _tfgGroup.CurrentIndex);

                TemplateField _tfField = null;

                _tfField = this[_sFieldName];

                if (_tfField != null)
                {
                    if ((_tfField.Expansion == TemplateFieldExpansion.Vertical) && (_tfField.Type == TemplateFieldType.Text) && (values[_values_idx] is string) &&
                        ((_tfField.SplitPolicy == SplitType.ByChar) || ((_tfField.SplitPolicy == SplitType.BySize) && (_tfField.Size < ((string)values[_values_idx]).Length))))
                    {
                        // Overflow on row
                        string[] _sValues = null;

                        switch (_tfField.SplitPolicy)
                        {
                        case SplitType.BySize:
                            _sValues = ((string)values[_values_idx]).Split(_tfField.Size);
                            break;

                        case SplitType.ByChar:
                            _sValues = ((string)values[_values_idx]).Split(_tfField.SplitChar);
                            break;

                        default:
                            throw new ArgumentException("SplitType " + _tfField.SplitPolicy + " not managed");
                        }

                        if ((_tfgGroup.HighIndex - _tfgGroup.LowIndex) < _sValues.Length)
                        {
                            throw new SetTooHighException("Set will not fit in this page");
                        }

                        if (_tfgGroup.CurrentIndex + _sValues.Length > _tfgGroup.HighIndex)
                        {
                            return(true);
                        }

                        _nElements = 0;

                        foreach (string _sValue in _sValues)
                        {
                            string _sFieldId;

                            _sFieldId = String.Format(_sFieldNamePattern, _tfgGroup.CurrentIndex + _nElements);

                            if (format && !String.IsNullOrWhiteSpace(this[_sFieldId].Format))
                            {
                                this[_sFieldId].Set(_sValue);
                            }
                            else
                            {
                                this[_sFieldId].Value = _sValue;
                            }

                            _nElements++;
                        }

                        //_nElements--;
                    }
                    else
                    {
                        if (_tfgGroup.CurrentIndex + 1 > _tfgGroup.HighIndex)
                        {
                            return(true);
                        }

                        if (format && !String.IsNullOrWhiteSpace(_tfField.Format))
                        {
                            _tfField.Set(values[_values_idx]);
                        }
                        else if (values[_values_idx] is string)
                        {
                            _tfField.Value = (string)values[_values_idx];
                        }
                        else
                        {
                            _tfField.Value = values[_values_idx].ToString();
                        }

                        _nElements = 1;
                    }
                }
                else
                {
                    throw new ArgumentException("Field identifier unknown");
                }

                _values_idx++;

                if (_nElements > _nStep)
                {
                    _nStep = _nElements;
                }
            }

            _tfgGroup.CurrentIndex += _nStep;

            return(false);
        }