示例#1
0
        public bool UpdateExistingAccount(char transactionType, Account account, decimal amount)
        {
            bool success = false;

            try
            {
                switch (transactionType)
                {
                case 'D':
                    //account.Balance += amount;
                    account.deposit(amount);
                    break;

                case 'W':
                    //account.Balance -= amount;
                    account.withdrawl(amount);
                    break;
                }

                ArrayList accounts  = GetAccounts();
                int       accountID = account.AccountID;

                // Find and replace the account
                for (int i = 0; i < accounts.Count; ++i)
                {
                    if (accountID == ((Account)accounts[i]).AccountID)
                    {
                        accounts[i] = account;
                    }
                }

                using (outFile = new StreamWriter(filename))
                {
                    foreach (Account acct in accounts)
                    {
                        outFile.WriteLine(acct.AccountID + DELIMETER + acct.Customer.CustomerID + DELIMETER + acct.Customer.FirstName + DELIMETER + acct.Customer.LastName + DELIMETER + acct.Balance + DELIMETER + Convert.ToInt32(acct.AccountType));
                    }
                    outFile.Close();
                }
                success = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                success = false;
            }
            return(success);
        }