Ejemplo n.º 1
0
 /// <summary>
 /// Sets the account to which <see cref="AddTransaction(string,object)"/> will subsequently add transactions.
 /// Adds the account to the account list if absent.
 /// </summary>
 /// <param name="setAcct">The AccountListTransaction of the account to make current or add.</param>
 /// <returns></returns>
 private void SetCurrentAccount(AccountListTransaction setAcct)
 {
     currentAccount = -1;
     for (int i = 0; i < autoSwitchAccounts.Count; i++)
     {
         if (autoSwitchAccounts[i].accountListTransaction.ToString().Equals(setAcct.ToString()))
         {
             currentAccount = i;
             break;
         }
     }
     if (currentAccount == -1)
     {
         AutoSwitchAccount qifAccount = new AutoSwitchAccount(setAcct);
         autoSwitchAccounts.Add(qifAccount);
         currentAccount = autoSwitchAccounts.Count - 1;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Write a single <see cref="AccountListTransaction"/>
        /// </summary>
        /// <param name="writer">Desitnation Stream</param>
        /// <param name="item">AccountListTransaction to write</param>
        /// <param name="autoSwitched">True to only write the account name and type</param>
        internal static void Write(TextWriter writer, AccountListTransaction item, bool autoSwitched)
        {
            if (!string.IsNullOrEmpty(item.Name))
            {
                writer.Write(AccountInformationFields.Name);
                writer.WriteLine(item.Name);
            }

            if (!string.IsNullOrEmpty(item.Type))
            {
                writer.Write(AccountInformationFields.AccountType);
                writer.WriteLine(item.Type);
            }

            if (!autoSwitched)
            {
                if (item.CreditLimit.HasValue)
                {
                    writer.WriteLine($"{AccountInformationFields.CreditLimit}{item.CreditLimit:n}");
                }

                if (!string.IsNullOrEmpty(item.Description))
                {
                    writer.Write(AccountInformationFields.Description);
                    writer.WriteLine(item.Description);
                }

                if (item.StatementBalance.HasValue)
                {
                    writer.Write(AccountInformationFields.StatementBalance);
                    writer.WriteLine(item.StatementBalance.Value.ToString(CultureInfo.CurrentCulture));
                }

                if (item.StatementBalanceDate != DateTime.MinValue)
                {
                    writer.Write(AccountInformationFields.StatementBalanceDate);
                    writer.WriteLine(item.StatementBalanceDate.ToString("d", CultureInfo.CurrentCulture));
                }
            }

            writer.WriteLine(InformationFields.EndOfEntry);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a collection of account list transactions
        /// </summary>
        /// <param name="transactionItems">The transaction delimited string</param>
        /// <param name="config">The configuration to use while importing raw data</param>
        /// <returns>A collection of bank transactions</returns>
        public static List <AccountListTransaction> Import(string transactionItems, Configuration config)
        {
            List <AccountListTransaction> result = new List <AccountListTransaction>();

            // Create a new transaction
            AccountListTransaction alt = new AccountListTransaction();

            // Split the string by new lines
            string[] sEntries = Regex.Split(transactionItems, "$", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);

            // Iterate over the array
            for (int i = 0; i < sEntries.Length; i++)
            {
                // Extract a line entry
                string sEntry = sEntries[i].Replace("\r", "").Replace("\n", "");

                // If the string has a value
                if (sEntry.Length > 0)
                {
                    // Test the first value of the string
                    switch (sEntry[0].ToString())
                    {
                    case AccountInformationFields.AccountType:
                        // Set the date value
                        alt.Type = sEntry.Substring(1);

                        // Stop processing
                        break;

                    case AccountInformationFields.CreditLimit:
                        // Set the amount value
                        alt.CreditLimit = sEntry.Substring(1).ParseDecimalString(config);

                        // Stop processing
                        break;

                    case AccountInformationFields.Description:
                        // Set the cleared status value
                        alt.Description = sEntry.Substring(1);

                        // Stop processing
                        break;

                    case AccountInformationFields.Name:
                        // Set the number value
                        alt.Name = sEntry.Substring(1);

                        // Stop processing
                        break;

                    case AccountInformationFields.StatementBalance:
                        // Set the payee value
                        alt.StatementBalance = sEntry.Substring(1).ParseDecimalString(config);

                        // Stop processing
                        break;

                    case AccountInformationFields.StatementBalanceDate:
                        // Set the memo value
                        alt.StatementBalanceDate = sEntry.Substring(1).ParseDateString(config);

                        // Stop processing
                        break;

                    case AccountInformationFields.EndOfEntry:
                        // Add the transaction instance to the collection
                        result.Add(alt);

                        // Call the destructor
                        alt = null;

                        // Create a new bank transaction
                        alt = new AccountListTransaction();

                        // Stop processing
                        break;
                    }
                }
            }

            // Return the populated collection
            return(result);
        }
Ejemplo n.º 4
0
 public void Yield(QifDocument document)
 {
     document.AddTransaction(GetType().Name, item);
     item = new AccountListTransaction();
 }
Ejemplo n.º 5
0
 public void Yield(QifDocument document)
 {
     document.AccountListTransactions.Add(item);
     item = new AccountListTransaction();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor sets the account to which transactions are associated.
 /// </summary>
 /// <param name="acct">Account to which the following transactions are added</param>
 public AutoSwitchAccount(AccountListTransaction acct)
 {
     accountListTransaction = acct;
 }