Пример #1
0
        private bool TryParseTransaction(string line, out Transaction transaction)
        {
            transaction = null;

            var parts = line.Split('\t');

            if (parts.Length != 8)
                return false;

            var data = new
            {
                AccountNumber = parts[0],
                Corrency = parts[1],
                Date1 = DateTime.ParseExact(parts[2], "yyyyMMdd", CultureInfo.InvariantCulture),
                BalanceBefore = decimal.Parse(parts[3], new NumberFormatInfo { NumberDecimalSeparator = "," }),
                BalanceAfter = decimal.Parse(parts[4], new NumberFormatInfo { NumberDecimalSeparator = "," }),
                Date2 = DateTime.ParseExact(parts[5], "yyyyMMdd", CultureInfo.InvariantCulture),
                Amount = decimal.Parse(parts[6], new NumberFormatInfo { NumberDecimalSeparator = ","}),
                Description = parts[7]
            };

            transaction = new Transaction
            {
                AccountNumber = data.AccountNumber,
                Date = data.Date1,
                BalanceBefore = data.BalanceBefore,
                BalanceAfter = data.BalanceAfter,
                Debit = data.Amount > 0 ? data.Amount : 0,
                Credit = data.Amount < 0 ? Math.Abs(data.Amount) : 0,
                Description = data.Description
            };

            return true;
        }
        private void Categorize(Transaction transaction, IEnumerable<ICategorizer> categorizers)
        {
            foreach (var categorizer in categorizers)
            {
                var category = categorizer.FindCategory(transaction.Description);

                if (category != null)
                {
                    transaction.SubCategory = category;
                    return;
                }
            }
        }