diff --git a/PriorBankParser/Constants.cs b/PriorBankParser/Constants.cs new file mode 100644 index 0000000..913e460 --- /dev/null +++ b/PriorBankParser/Constants.cs @@ -0,0 +1,11 @@ +namespace PriorBankParser +{ + public static class Constants + { + public static class SectionNames + { + internal const string LockedSectionPrefix = "Заблокированные суммы по ........"; + internal const string OperationSectionPrefix = "Операции по ........"; + } + } +} diff --git a/PriorBankParser/Parser.cs b/PriorBankParser/Parser.cs new file mode 100644 index 0000000..72fdd11 --- /dev/null +++ b/PriorBankParser/Parser.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Globalization; +using System.IO; +using CsvHelper; +using CsvHelper.Configuration; + +namespace PriorBankParser +{ + public class SectionParser + { + public enum SectionType + { + AccountInfo, + StatementDetails, + ContractOperations, + ContractLocked, + ContractTotal, + StatementTotal + } + + public SectionParseResultDto Parse(string filePath) + { + var result = new SectionParseResultDto(); + var transactions = new List(); + result.Transactions = transactions; + + using var reader = new StreamReader(filePath); + using var csv = new CsvReader(reader, CultureInfo.InvariantCulture); + csv.Configuration.HasHeaderRecord = false; + csv.Configuration.RegisterClassMap(); + //csv.Configuration. + + var currentSection = SectionType.AccountInfo; + var contractName = string.Empty; + + while (csv.Read()) + { + var field = csv.GetField(0); + if (field.Equals(Constants.SectionNames.OperationSectionPrefix)) + { + currentSection = SectionType.StatementTotal; + contractName = field.Replace(Constants.SectionNames.OperationSectionPrefix, string.Empty); + continue; + } + + //switch (currentSection) + //{ + // case "FooId": + // fooRecords.Add(csv.GetRecord()); + // break; + // case "BarId": + // barRecords.Add(csv.GetRecord()); + // break; + // default: + // throw new InvalidOperationException("Unknown record type."); + //} + } + + return result; + } + + + } + + public sealed class TransactionInfoDtoMap : ClassMap + { + public TransactionInfoDtoMap() + { + Map(m => m.TransactionDate).Name("Дата транзакции"); + Map(m => m.OperationName).Name("Операция"); + Map(m => m.Amount).Name("Сумма"); + Map(m => m.Currency).Name("Валюта"); + Map(m => m.OperationDate).Name("Дата операции по счету"); + Map(m => m.Commission).Name("Комиссия/Money-back"); + Map(m => m.AccountTurnover).Name("Обороты по счету"); + Map(m => m.DigitalCard).Name("Цифровая карта"); + Map(m => m.OperationCategory).Name("Категория операции"); + } + } + +} \ No newline at end of file diff --git a/PriorBankParser/SectionParseResult.cs b/PriorBankParser/SectionParseResult.cs new file mode 100644 index 0000000..bc4f301 --- /dev/null +++ b/PriorBankParser/SectionParseResult.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace PriorBankParser +{ + public class SectionParseResultDto + { + public string ContractNo { get; set; } + + public IReadOnlyCollection Transactions { get; set; } + } +} \ No newline at end of file diff --git a/PriorBankParser/StatementDto.cs b/PriorBankParser/StatementDto.cs new file mode 100644 index 0000000..b2e48fe --- /dev/null +++ b/PriorBankParser/StatementDto.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; + +namespace PriorBankParser +{ + public class StatementDto + { + public ICollection> AccountInfos { get; set; } + + public ICollection ContractsInfo { get; set; } + + public ICollection LockedInfo { get; set; } + + public TotalDto StatementTotal { get; set; } + } + + public class LockedSection + { + public string SectionName { get; set; } + + public IReadOnlyCollection Items { get; set; } + } + + public class OperationalSectionDto + { + public string SectionName { get; set; } + + public IReadOnlyCollection Items { get; set; } + + public TotalDto Total { get; set; } + } + + public class TotalDto + { + public decimal IncomeAmount { get; set; } + + public decimal OutcomeAmount { get; set; } + + public decimal Commission { get; set; } + + public decimal FinalAmount { get; set; } + } +} \ No newline at end of file diff --git a/PriorBankParser/TransactionInfoDto.cs b/PriorBankParser/TransactionInfoDto.cs new file mode 100644 index 0000000..8edaa8f --- /dev/null +++ b/PriorBankParser/TransactionInfoDto.cs @@ -0,0 +1,25 @@ +using System; + +namespace PriorBankParser +{ + public class TransactionInfoDto + { + public DateTime TransactionDate { get; set; } + + public string OperationName { get; set; } + + public decimal Amount { get; set; } + + public string Currency { get; set; } + + public DateTime OperationDate { get; set; } + + public decimal Commission { get; set; } + + public decimal AccountTurnover { get; set; } + + public string DigitalCard { get; set; } + + public string OperationCategory { get; set; } + } +} \ No newline at end of file