예제 #1
0
        /// <summary>
        /// Information printed when closing account.
        /// </summary>
        public static string PrintAccountInfo(Account account)
        {
            string info = "null...";

            switch (account)
            {
            //Credit with a negative balance, interest
            case CreditAccount creditNegative when creditNegative.Balance < 0:
                account.Balance += account.Balance * (decimal)creditNegative.DebtInterest;
                info             = $"AccountID: {account.AccountID} Account Type: {account.GetType().Name}\n" +
                                   $"Account balance: {account.Balance} Debt rate: {creditNegative.DebtInterest * 100}%";
                return(info);

            //Savings account uses the same code as credit account.
            case SavingsAccount _:
            case CreditAccount _ when account.Balance >= 0:
                account.Balance *= (1 + (decimal)account.Interest);
                info             = $"AccountID: {account.AccountID} Account Type: {account.GetType().Name}\n" +
                                   $"Account balance: {account.Balance} Account rate: {account.Interest * 100}%";
                return(info);

            default:
                return(info);
            }
        }
예제 #2
0
        /// <summary>
        /// Prints selected account transaction history to a file.
        /// </summary>
        /// <param name="account"></param>
        public async void PrintTransactionsHistory(Account account)
        {
            try
            {
                Windows.Storage.StorageFolder storageFolder =
                    Windows.Storage.ApplicationData.Current.LocalFolder;
                Windows.Storage.StorageFile sampleFile =
                    await storageFolder.CreateFileAsync($"TransactionHistory - {account.AccountID}.txt",
                                                        Windows.Storage.CreationCollisionOption.ReplaceExisting);

                string result = $"AccountID: {account.AccountID} || Remaining balance: {account.Balance} SEK " +
                                $"|| {account.GetType().Name} ({account.Interest*100}%) \n ";

                foreach (var transaction in account.Transactions)
                {
                    result += $"\n{transaction.Time}\t" +
                              $"{transaction.TransactionType}: \t" +
                              $"Amount: {transaction.Amount} SEK \t " +
                              $"Remaining balance: {transaction.NewBalance} SEK \n";
                }

                await Windows.Storage.FileIO.WriteTextAsync(sampleFile, result);
            }
            catch (Exception) { }
        }