예제 #1
0
파일: Bank.cs 프로젝트: anadera/metanit
        public void Open(AccountType accountType, decimal sum,
                         AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler,
                         AccountStateHandler calculationHandler, AccountStateHandler closeAccountHandler,
                         AccountStateHandler openAccountHandler)
        {
            T newAccount = null;

            switch (accountType)
            {
            case AccountType.Ordinary:
                newAccount = new DemandAccount(sum, 1) as T;
                break;

            case AccountType.Deposit:
                newAccount = new DemandAccount(sum, 40) as T;
                break;
            }

            if (newAccount == null)
            {
                throw new Exception("Ошибка создания счета");
            }
            if (accounts == null)
            {
                accounts = new T[] { newAccount }
            }
            ;
            else
            {
                T[] tempAccountts = new T[accounts.Length + 1];
                for (int i = 0; i < accounts.Length; i++)
                {
                    tempAccountts[i] = accounts[i];
                }
                tempAccountts[tempAccountts.Length - 1] = newAccount;
                accounts = tempAccountts;
            }

            newAccount.Added      += addSumHandler;
            newAccount.Withdrawed += withdrawSumHandler;
            newAccount.Closed     += closeAccountHandler;
            newAccount.Opened     += openAccountHandler;
            newAccount.Calculated += calculationHandler;

            newAccount.Open();
        }
예제 #2
0
        public void Open(AccountType accounttype, decimal sum, AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler, AccountStateHandler calculateHandler, AccountStateHandler closeAccountHandler, AccountStateHandler openAccountHandler)
        {
            T newAccount = null;

            switch (accounttype)
            {
            case AccountType.Ordinary:
                newAccount = new DemandAccount(sum, 1) as T;
                break;

            case AccountType.Deposit:
                newAccount = new DemandAccount(sum, 40) as T;
                break;
            }
            if (newAccount == null)
            {
                throw new Exception("Ошибка создания счета");
            }
            if (Accounts == null)
            {
                Accounts = new T[] { newAccount };
            }
            else
            {
                T[] TempAccounts = new T [Accounts.Length + 1];
                for (int x = 0; x < Accounts.Length; x++)
                {
                    TempAccounts[x] = Accounts[x];
                }
                TempAccounts[Accounts.Length - 1] = newAccount;
                Accounts = TempAccounts;
            }
            newAccount.Added      += addSumHandler;
            newAccount.Withdrawed += withdrawSumHandler;
            newAccount.Calculated += calculateHandler;
            newAccount.Closed     += closeAccountHandler;
            newAccount.Opened     += openAccountHandler;
            newAccount.Open();
        }