/// <summary> /// Gets the data sheet based on the custom format. /// </summary> /// <param name="source">The source.</param> /// <param name="settings">The settings.</param> /// <param name="bankName">Name of the bank.</param> /// <returns></returns> public static List <Data> GetCustomDataSheet(TextSource source, BankSetting settings, string bankName) { var properties = source.GetProperties(settings.DataSetting.Pattern); List <Data> data = null; Func <Data, string> getKey = item => item.Customer + item.Detail; if (properties == null && settings.DataMapping?.MappingFields?.Count > 0) { properties = PropertyHelper.GetProperties <Data>(settings.DataMapping); } if (properties != null) { data = source.GetSheet <Data>(settings.FileSetting?.RowIndex ?? 0, settings.FileSetting?.SheetIndex ?? 0, properties); if (data != null) { if (settings.DataMapping?.KeyFields?.Count > 0) { var keyProperties = source.InitProperties <Data>(); var usedProperties = new List <PropertyInfo>(); foreach (var prop in settings.DataMapping.KeyFields) { var property = keyProperties.FirstOrDefault(v => v.ColumnIn == prop); if (property != null) { usedProperties.Add(property.PropertyInfo); } } if (usedProperties.Count > 0) { getKey = item => { var rtnVal = string.Empty; foreach (var prop in usedProperties) { rtnVal = string.Concat(rtnVal, (prop.GetValue(item, null) ?? string.Empty)); } return(settings.DataMapping.IsKeyUpper ? rtnVal.ToUpper() : rtnVal); }; } } foreach (var item in data) { item.Sign = item.Value > 0; item.Bank = bankName ?? "Custom"; if (string.IsNullOrWhiteSpace(item.Category)) { string key = Factory.Categories.Keys.FirstOrDefault(k => getKey(item).Contains(k)); item.Category = !string.IsNullOrEmpty(key) ? Factory.Categories[key] : "Autres"; } } } } return(data); }