コード例 #1
0
        private Dictionary <string, Account> RetrieveAccounts()
        {
            Dictionary <string, Account> accounts = new Dictionary <string, Account>();

            StreamReader sr = null;

            try
            {
                sr = new StreamReader(FILENAME);
                string row = "";
                while ((row = sr.ReadLine()) != null)
                {
                    Account a = AccountMapper.StringToAccount(row);
                    accounts.Add(a.AccountNumber, a);
                }
            }
            catch (FileNotFoundException fileNotFound)
            {
                Console.WriteLine(fileNotFound.FileName + " was not found");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
            return(accounts);
        }
コード例 #2
0
        public void SaveAccount(Account account)
        {
            Dictionary <string, Account> accounts = new Dictionary <string, Account>();

            accounts = RetrieveAccounts();
            accounts[account.AccountNumber] = account;
            StreamWriter sw = new StreamWriter("Accounts.txt");

            foreach (Account item in accounts.Values)
            {
                sw.WriteLine(AccountMapper.AccountToString(item));
                sw.Flush();
            }
            if (sw != null)
            {
                sw.Close();
            }
        }