示例#1
0
        private void CheckEnumerator(ICustomEnumerator enumerator, int count)
        {
            Assert.AreEqual(count, enumerator.RowCount);

            IList <object> result = new List <object>();

            while (enumerator.MoveNext())
            {
                result.Add(enumerator.Current);
            }

            Assert.AreEqual(count, result.Count);
            Assert.AreEqual(count, enumerator.RowCount);

            enumerator.Reset();
            result.Clear();

            Assert.AreEqual(count, enumerator.RowCount);

            while (enumerator.MoveNext())
            {
                result.Add(enumerator.Current);
            }

            Assert.AreEqual(count, result.Count);
            Assert.AreEqual(count, enumerator.RowCount);
        }
        public override void Render()
        {
            // Receive parent data item context
            HierarchicalDataItem parentDataItem = GetDataContext();

            _data = _isDataReceivedDirectly ? _data : _templateProcessor.GetValue(_dataSourceTemplate, parentDataItem);

            bool isCanceled = CallBeforeRenderMethod();

            if (isCanceled)
            {
                ResultRange = ExcelHelper.CloneRange(Range);
                return;
            }

            ICustomEnumerator enumerator = null;

            try
            {
                enumerator = EnumeratorFactory.Create(_data);
                // Removing the template if there are no data
                if (enumerator == null || enumerator.RowCount == 0)
                {
                    DeletePanel(this);
                    return;
                }

                // Creating the panel template which will be replicated then
                ExcelDataItemPanel templatePanel = CreateTemplatePanel();
                _templatePanelRowCount    = templatePanel.Range.RowCount();
                _templatePanelColumnCount = templatePanel.Range.ColumnCount();

                // Allocating space for data
                if (enumerator.RowCount > 1)
                {
                    AllocateSpaceForData(templatePanel, enumerator.RowCount);
                }

                int rowNum = 0;
                while (enumerator.MoveNext())
                {
                    object             currentItem = enumerator.Current;
                    ExcelDataItemPanel currentPanel;
                    if (rowNum != enumerator.RowCount - 1)
                    {
                        IXLCell templateFirstCell = templatePanel.Range.FirstCell();
                        // The template itself is moved down or right, depending on the type of panel
                        MoveTemplatePanel(templatePanel);
                        // Copying the template on its previous place for the panel which the current data item will be rendered in
                        currentPanel = (ExcelDataItemPanel)templatePanel.Copy(templateFirstCell);
                    }
                    else
                    {
                        // Rendering data directly in the template if there is the last data item
                        currentPanel = templatePanel;
                    }

                    currentPanel.DataItem = new HierarchicalDataItem {
                        Value = currentItem, Parent = parentDataItem
                    };

                    // Fill template with data
                    currentPanel.Render();
                    ResultRange = ExcelHelper.MergeRanges(ResultRange, currentPanel.ResultRange);

                    RemoveAllNamesRecursive(currentPanel);
                    rowNum++;
                }

                RemoveName();
            }
            finally
            {
                (enumerator as IDisposable)?.Dispose();
            }

            GroupResult();
            CallAfterRenderMethod();
        }