コード例 #1
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);
            }
        }
コード例 #2
0
        public static R CreateRow <R>(RFRawReportRow sourceRow) where R : RFDataRow, new()
        {
            var r = new R();

            foreach (var p in r.GetType().GetProperties())
            {
                var attr = GetMappedAttribute(p);
                if (attr != null)
                {
                    try
                    {
                        var    t = p.PropertyType;
                        object v = null;
                        if (t.Equals(typeof(string)))
                        {
                            v = sourceRow.GetString(attr.SourceColumn);
                        }
                        else if (t.Equals(typeof(decimal?)) || t.Equals(typeof(decimal)))
                        {
                            v = sourceRow.GetDecimal(attr.SourceColumn);
                        }
                        else if (t.Equals(typeof(double?)) || t.Equals(typeof(double)))
                        {
                            v = sourceRow.GetDouble(attr.SourceColumn);
                        }
                        else if (t.Equals(typeof(float?)) || t.Equals(typeof(float)))
                        {
                            v = sourceRow.GetFloat(attr.SourceColumn);
                        }
                        else if (t.Equals(typeof(int?)) || t.Equals(typeof(int)))
                        {
                            v = sourceRow.GetInt(attr.SourceColumn);
                        }
                        else if (t.Equals(typeof(bool?)) || t.Equals(typeof(bool)))
                        {
                            v = sourceRow.GetBool(attr.SourceColumn);
                        }
                        else if (t.Equals(typeof(RFDate?)) || t.Equals(typeof(RFDate)))
                        {
                            v = sourceRow.GetDate(attr.SourceColumn, attr.Format);
                        }
                        else if (t.Equals(typeof(DateTime?)) || t.Equals(typeof(DateTime)))
                        {
                            v = sourceRow.GetDateTime(attr.SourceColumn, attr.Format);
                        }
                        else if (t.Equals(typeof(DateTimeOffset?)) || t.Equals(typeof(DateTimeOffset)))
                        {
                            v = sourceRow.GetDateTime(attr.SourceColumn, attr.Format);
                            if (v != null)
                            {
                                v = new DateTimeOffset((DateTime)v);
                            }
                        }

                        if (v == null)
                        {
                            if (attr.IsMandatory)
                            {
                                throw new RFLogicException(typeof(RFPropertyMapper), "Missing mandatory value in column {0}", attr.SourceColumn);
                            }
                        }
                        else
                        {
                            p.SetValue(r, v);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (attr.IsMandatory)
                        {
                            throw new RFLogicException(typeof(RFPropertyMapper), ex, "Error parsing value in column {0}", attr.SourceColumn);
                        }
                        RFStatic.Log.Warning(typeof(RFPropertyMapper), "Error parsing value in column {0}", attr.SourceColumn);
                    }
                }
            }
            return(r);
        }