private TransactionHistory LoadFromFile(string filename, string ID) { TransactionHistory history = new TransactionHistory(ID); if (File.Exists(filename)) { StreamReader file = new StreamReader(filename); history.SetKey(file.ReadLine()); string entry = file.ReadLine(); while (String.IsNullOrEmpty(entry) == false) { BankTransaction transaction = ParseEntry(entry); if (transaction.IsActive) { history.AddEntry(transaction); } entry = file.ReadLine(); } history.Activate(); file.Close(); Console.WriteLine($"Loaded history details for {history.Key} (count:{history.Count})"); } else { Console.WriteLine("File not found: " + filename); } return(history); }
private void RecordToHistory(BankTransaction transaction) { if (transaction.TransactionType != BankTransactionType.NONE) { TransactionHistoryDao historyDao = new TransactionHistoryDao(); TransactionHistory history = historyDao.Load(_account.Key); history.AddEntry(transaction); historyDao.Save(history); } }
public void Save(TransactionHistory history) { string filename = StorageFilePath(history.Key); StreamWriter file = new StreamWriter(filename); file.WriteLine(history.Key); int countWritten = 0; foreach (BankTransaction transaction in history.Items) { WriteEntry(transaction, file); countWritten++; } file.Close(); Console.WriteLine($"TX History: Written {countWritten} entries."); }