Пример #1
0
        private static FineAntsCore.Transaction TransactionFromCSVFields(string[] fields)
        {
            // We must have 5 fields; Transaction Date, Entered date, some kind of number..., Transaction Description, Amount, and possibly a stupid blank one
            if (!(fields.Length == 5 || (fields.Length == 6 && fields[5] == "")))
            {
                throw new Exception("CSV file must have 5 fields per line, or 6 and a blank one. Format may have changed since this program was written.");
            }

            // Date is in the first column, stored as "dd/MM/yyyy".
            DateTime date = DateTime.ParseExact(fields[0], "dd\\/MM\\/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            // Merchant/description is in the 4th column. They don't appear to be separated so just use the whole thing as the merchant.
            string merchant = fields[3].Trim();

            // The 5th column is the transaction amount. Positive numbers are debits.
            int amount = -AmountFromString(fields[4]);

            // Create the transaction.
            FineAntsCore.Transaction transaction = new FineAntsCore.Transaction(amount, date, merchant, "");
            return transaction;
        }
Пример #2
0
        private static FineAntsCore.Transaction TransactionFromCSVFields(string[] fields)
        {
            // We must have 4 fields; date, merchant/description, amount, and running balance.
            if (fields.Length != 4)
            {
                throw new Exception("CSV file must have 4 fields per line");
            }

            // Date is in the first column, stored as "dd/MM/yyyy".
            DateTime date = DateTime.ParseExact(fields[0], "dd\\/MM\\/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            // The first 19 chars of the second column are the merchant name, and the rest (if any) are the description.
            int maxNumMerchantChars = 19;
            int numMerchantChars = Math.Min(maxNumMerchantChars, fields[1].Length);

            string merchant = fields[1].Substring(0, numMerchantChars).Trim();
            string description = (fields[1].Length > numMerchantChars) ? fields[1].Substring(numMerchantChars).Trim() : "";

            // The third column is the transaction amount.
            int amount = AmountFromString(fields[2]);

            // Create the transaction.
            FineAntsCore.Transaction transaction = new FineAntsCore.Transaction(amount, date, merchant, description);
            return transaction;
        }
Пример #3
0
        private static FineAntsCore.Transaction TransactionFromCSVFields(string[] fields)
        {
            // We must have 4 fields; date, merchant/description, amount, and running balance.
            if (fields.Length != 4)
            {
                throw new Exception("CSV file must have 4 fields per line");
            }

            // Date is in the first column, stored as "dd/MM/yyyy".
            DateTime date = DateTime.ParseExact(fields[0], "dd\\/MM\\/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            // The second column is the merchant name mushed together with the description. The two are inseparable so just treat it as the merchant name.
            string merchant = fields[1].Trim();
            string description = "";

            // The third column is the transaction amount.
            int amount = AmountFromString(fields[2]);

            // Create the transaction.
            FineAntsCore.Transaction transaction = new FineAntsCore.Transaction(amount, date, merchant, description);
            return transaction;
        }
Пример #4
0
        private static FineAntsCore.Transaction TransactionFromCSVFields(string[] fields)
        {
            // We must have 8 fields; Transaction Date, Transaction Type, Sort Code, Account Number, Transaction Description, Debit Amount, Credit Amount, Balance
            if (fields.Length != 8)
            {
                throw new Exception("CSV file must have 8 fields per line");
            }

            // Date is in the first column, stored as "dd/MM/yyyy".
            DateTime date = DateTime.ParseExact(fields[0], "dd\\/MM\\/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            // The first 19 chars of the second column are the merchant name, and the rest (if any) are the description.
            string merchant = fields[4].Trim();
            string description = "";

            // The 6th column is debit amount and the 7th is credit. Only one will be filled out, and both will be positive. So check which has contents and parse it, and negate the amount if it is a debit.
            int amount = AmountFromFields(fields);

            // Create the transaction.
            FineAntsCore.Transaction transaction = new FineAntsCore.Transaction(amount, date, merchant, description);
            return transaction;
        }