コード例 #1
0
        public RFRawReport BuildReport(List <DataTable> tables, IRFReportBuilder builder, RFReportParserConfig config)
        {
            _report         = new RFRawReport();
            _currentSection = null;
            _parentSection  = null;
            _builder        = builder;

            foreach (var table in tables)
            {
                _parentSection  = table.TableName;
                _currentSection = new RFRawReportSection
                {
                    Name    = String.Format("{0}.{1}", _parentSection, HEADER_SECTION_NAME),
                    Columns = new List <string>()
                };
                _report.Sections.Add(_currentSection);
                bool isFirstRow = true;
                foreach (DataRow row in table.Rows)
                {
                    ProcessRow(row, isFirstRow, config.HasHeaders);
                    isFirstRow = false;
                }
            }

            return(_report);
        }
コード例 #2
0
        protected void ProcessRow(DataRow row, bool isFirstRow, bool hasHeaders)
        {
            if (IsEmpty(row))
            {
                return;
            }
            var itemList         = row.ItemArray.Select(i => i == null ? String.Empty : i.ToString()).ToList();
            var newSectionStart  = _builder.IsNewSectionStart(itemList.ToArray());
            var newSectionPrefix = _builder.IsNewSectionPrefix(itemList.ToArray());

            if (newSectionStart.NotBlank())
            {
                // new section - assume these are column headers
                _currentSection = new RFRawReportSection
                {
                    Name    = String.Format("{0}.{1}", _parentSection, newSectionStart),
                    Columns = RenameDupeColumns(itemList)
                };
                _report.Sections.Add(_currentSection);
            }
            else if (newSectionPrefix.NotBlank())
            {
                // next line will be new section
                _currentSection = new RFRawReportSection
                {
                    Name = String.Format("{0}.{1}", _parentSection, newSectionPrefix),
                };
                _expectingColumns = true;
                _report.Sections.Add(_currentSection);
            }
            else if (_expectingColumns)
            {
                _currentSection.Columns = RenameDupeColumns(itemList);
                _expectingColumns       = false;
            }
            else if (isFirstRow)
            {
                if (hasHeaders)
                {
                    _currentSection.Columns = RenameDupeColumns(itemList);
                }
                else
                {
                    // use table columns and treat as data row
                    _currentSection.Columns = RenameDupeColumns(row.Table.Columns.OfType <DataColumn>().Select(s => s.ColumnName).ToList());
                    var newRow = new RFRawReportRow();
                    newRow.Values = itemList;
                    _currentSection.Rows.Add(newRow);
                }
            }
            else
            {
                var newRow = new RFRawReportRow();
                newRow.Values = itemList;
                _currentSection.Rows.Add(newRow);
            }
        }