public DisplayField(DisplayFieldName name, IMappingField requiredField, Func <SqlLedgerEntry, object> getter, string headerValue, IExcelColumnFormatter columnFormatter) { RequiredField = requiredField; this.getter = getter; this.headerValue = headerValue; this.columnFormatter = columnFormatter; Name = name; }
private static T GetField <T>(IFieldReader <T> reader, IDataRecord record, int recordIndex, IMappingField mappingField) { try { return(reader.GetField(record, recordIndex)); } catch (Exception e) { var message = String.Format("Could not read {0} of row {1}: {2}. It looks like the data for the {0} is incorrect. If you are importing data from Excel, please check the mapping for this column and try again.", mappingField.UserFriendlyName, recordIndex, e.Message); throw new SqlDataFormatUnexpectedException(message, e); } }
public DisplayField(DisplayFieldName name, IMappingField requiredField, Func <SqlLedgerEntry, object> getter, string headerValue) : this(name, requiredField, getter, headerValue, new NoFormattingRequiredFormatter()) { }
private static T GetField <T>(IList <SqlLedgerEntry> ledgerEntries, Func <SqlLedgerEntry, T> getter, IMappingField mappingField) { var values = ledgerEntries.Select(getter).Distinct().ToList(); if (values.Count > 1) { throw new SqlDataFormatUnexpectedException(String.Format("Expected only one value for {0} per transaction. Actual values for transaction with id {1}: {2}. This can happen if you assign the 'ID' column incorrectly when importing data from Excel.", mappingField, ledgerEntries.First().TransactionId, ValuesString(values))); } return(values.Single()); }