private void CallEvent(AccountEventArgs e, AccountStateHandler handler) { if (e != null && handler != null) { handler(this, e); } }
} // Уникальный идентификатор счета // Определяем методы генерации: private void CallEvent(AccountEventArgs e, AccountStateHandler handler) // Вызов событий { if (e != null) { handler?.Invoke(this, e); } }
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 DepositAccount(sum, 40) as T; break; } if (newAccount == null) { throw new Exception("Error creating account"); } accounts.Add(newAccount); newAccount.Added += addSumHandler; newAccount.Withdrawed += withdrawSumHandler; newAccount.Closed += closeAccountHandler; newAccount.Opened += openAccountHandler; newAccount.Calculated += calculationHandler; newAccount.Open(); }
static void Main(string[] args) { int sum, sum1; int mainThredId = Thread.CurrentThread.ManagedThreadId; Account account = new Account(200); account.RegisterHandler(new AccountStateHandler(Show_Message)); AccountStateHandler handler = new AccountStateHandler(Show_Message); IAsyncResult result = handler.BeginInvoke("начало операции", new AsyncCallback((incomingResult) => Console.WriteLine(handler.EndInvoke(incomingResult))), null); Console.WriteLine("введите сумму"); int.TryParse(Console.ReadLine(), out sum); account.Put(sum); Console.WriteLine("введите сумму для снятие суммы"); int.TryParse(Console.ReadLine(), out sum1); account.Withdraw(sum1); Console.ReadLine(); }
//account's opening //result: addidtion of a new account to the list of existing accounts public void Open(AccountType accountType, decimal sum, float percentage, AccountStateHandler openStateHandler, AccountStateHandler closeStateHandler, AccountStateHandler receiveStateHandler, AccountStateHandler withdrawStateHandler, AccountStateHandler percentageStateHandler, AccountStateHandler showInfoStateHandler, int period = 0) { T newAccount = default(T); switch (accountType) { case AccountType.Demand: newAccount = new DemandAccount(sum, percentage) as T; break; case AccountType.Deposit: newAccount = new DepositAccount(sum, percentage, period) as T; break; default: throw new Exception("Error while creating account"); } newAccount.Opened += openStateHandler; newAccount.Closed += closeStateHandler; newAccount.Received += receiveStateHandler; newAccount.Withdrawed += withdrawStateHandler; newAccount.InfoShowing += showInfoStateHandler; accounts.Add(newAccount); }
// вызов событий private void CallEvent(AccountEventArgs e, AccountStateHandler handler) { if(e != null) handler?.Invoke(this, e); }
private void CallEvent(AccountEventArgs e, AccountStateHandler handler) { if (e != null) { handler?.Invoke(e); } }
public Bank(string name, AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler, AccountStateHandler closeAccountHandler, AccountStateHandler openAccountHandler) { this.Name = name; Added += addSumHandler; Withdrawed += withdrawSumHandler; Closed += closeAccountHandler; Opened += openAccountHandler; }
/// <summary> /// Базовый метод вызова событий /// </summary> /// <param name="args">Вспомогательный класс обработки событий</param> /// <param name="handler">Обработчик событий</param> private void CallEvent(AccountEventArgs args, AccountStateHandler handler) { if (args == null) { throw new Exception("При вызове определенного события, оно должно иметь содержание"); } else { handler?.Invoke(args); } }
public void Open(AccountType accountType, decimal sum, AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler, AccountStateHandler calculationHandler, AccountStateHandler closeAccoundHandler, AccountStateHandler openAccountHandler) { T newAccount = null; switch (accountType) { case AccountType.Ordinary: { newAccount = new DemandAccount(sum, 1) as T; break; } case AccountType.Deposit: { newAccount = new DepositAccount(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 i = 0; i < accounts.Length; i++) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length - 1] = newAccount; accounts = tempAccounts; } newAccount.Added += addSumHandler; newAccount.Withdrawed += withdrawSumHandler; newAccount.Opened += openAccountHandler; newAccount.Closed += closeAccoundHandler; newAccount.Calculated += calculationHandler; newAccount.Open(); }
// the method for creating of account public void Open(AccountType accountType, decimal sum, AccountStateHandler addSumHandler, AccountStateHandler takeSumHandler, AccountStateHandler calculationHandler, AccountStateHandler closeAcccountHandler, AccountStateHandler openAccountHandler ) { T newAccount = null; switch (accountType) { case AccountType.Ordinary: newAccount = new DemandAccount(sum, 1) as T; break; case AccountType.Deposit: newAccount = new DepositAccount(sum, 40) as T; break; } if (newAccount == null) { throw new Exception("Помилка створення рахунку"); } // add the new account to massif of accounts if (accounts == null) { accounts = new T[] { newAccount } } ; else { T[] tempAccounts = new T[accounts.Length + 1]; for (int i = 0; i < accounts.Length; i++) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length - 1] = newAccount; accounts = tempAccounts; } // setting up an account event handler newAccount.Added += addSumHandler; newAccount.Take += takeSumHandler; newAccount.Closed += closeAcccountHandler; newAccount.Opened += openAccountHandler; newAccount.Calculated += calculationHandler; newAccount.Open(); }
// метод создания счета 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 DepositAccount(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 i = 0; i < accounts.Length; i++) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length - 1] = newAccount; accounts = tempAccounts; } // установка обработчиков событий счета newAccount.Added += addSumHandler; newAccount.Withdrawed += withdrawSumHandler; newAccount.Closed += closeAccountHandler; newAccount.Opened += openAccountHandler; newAccount.Calculated += calculationHandler; newAccount.Open(); }
// метод створення рахунку public void Open(AccountType accountType, decimal sum, AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler, AccountStateHandler calculationHandler, AccountStateHandler closeAccountHandler, AccountStateHandler printAccountsHandler, AccountStateHandler openAccountHandler) { T newAccount = null; switch (accountType) { case AccountType.Ordinary: newAccount = new DemandAccount(sum, 1) as T; break; case AccountType.Deposit: newAccount = new DepositAccount(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 i = 0; i < accounts.Length; i++) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length - 1] = newAccount; accounts = tempAccounts; } // встановлення обробників подій рахунків newAccount.Added += addSumHandler; newAccount.Withdrawed += withdrawSumHandler; newAccount.Closed += closeAccountHandler; newAccount.Opened += openAccountHandler; newAccount.Calculated += calculationHandler; newAccount.Printed += printAccountsHandler; newAccount.Open(); }
// метод создания счета 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 DepositAccount(sum, 40) as T; break; } }
//creating an Account public void Open(AccountType accountType, decimal sum, AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler, AccountStateHandler calculateHandler, AccountStateHandler openAccountHandler, AccountStateHandler closeAccountHandler, AccountStateHandler displayAccountHandler) { T newAccount = null; switch (accountType) { case AccountType.Checking: newAccount = new CheckingAccount(sum) as T; break; case AccountType.Deposit: newAccount = new DepositAccount(sum, 25) as T; break; } if (newAccount == null) { Console.WriteLine("Account creation error."); } //add new Account to List<T> if (accounts == null) { accounts = new List <T>() { newAccount } } ; else { accounts.Add(newAccount); } //events handler newAccount.Added += addSumHandler; newAccount.Withdrawed += withdrawSumHandler; newAccount.Calculated += calculateHandler; newAccount.Opened += openAccountHandler; newAccount.Closed += closeAccountHandler; newAccount.Displayed += displayAccountHandler; if (accountType == AccountType.Checking) { newAccount.Calculated -= calculateHandler; } newAccount.Open(); }
// метод создания счета 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; //Такое приведение позволит нам избежать ошибок, например, если мы типизируем класс Bank не Account, а типом DepositAccount, то преобразование newAccount = new DemandAccount(sum, 1) as T вернет нам значение null. Дальше мы можем проверить полученное значение на null break; case AccountType.Deposit: newAccount = new DepositAccount(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 i = 0; i < accounts.Length; i++) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length - 1] = newAccount; accounts = tempAccounts; } // установка обработчиков событий счета newAccount.Added += addSumHandler; newAccount.Withdrawed += withdrawSumHandler; newAccount.Closed += closeAccountHandler; newAccount.Opened += openAccountHandler; newAccount.Calculated += calculationHandler; newAccount.Open(); }
public void Open(AccountType accountType, decimal sum, AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler, AccountStateHandler calculationHandler, AccountStateHandler closeAccountHandler, AccountStateHandler openAccountHandler)//create account method { T newAccount = null; switch (accountType) { case AccountType.Ordinary: newAccount = new DemandAccount(sum, 1) as T; break; case AccountType.Deposit: newAccount = new DepositAccount(sum, 40) as T; break; } if (newAccount == null) { throw new Exception("Ошибка создания счета"); } //add a new account to accounts array if (accounts == null) { accounts = new T[] { newAccount } } ; else { T[] tempAccounts = new T[accounts.Length + 1]; for (int i = 0; i < accounts.Length; i++) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length - 1] = newAccount; accounts = tempAccounts; } //setting the event handlers up newAccount.Added += addSumHandler; newAccount.Withdrawed += withdrawSumHandler; newAccount.Closed += closeAccountHandler; newAccount.Opened += openAccountHandler; newAccount.Calculated += calculationHandler; newAccount.Open(); }
public void Open(AccountType accountType, double sum, AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler, AccountStateHandler calculationHandler, AccountStateHandler closeAccountHandler, AccountStateHandler openAccountHandler, AccountStateHandler transferHandler) { T newAccount = null; switch (accountType) { case AccountType.Ordinary: newAccount = new DemandAccount(sum, 1) as T; break; case AccountType.Deposit: newAccount = new DepositAccount(sum, 40) as T; break; } if (newAccount == null) { throw new Exception("Error creating account"); } if (accounts == null) { accounts = new T[] { newAccount } } ; else { var tempAccounts = new T[accounts.Length + 1]; for (var i = 0; i < accounts.Length; i++) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length - 1] = newAccount; accounts = tempAccounts; } newAccount.Added += addSumHandler; newAccount.Withdrawed += withdrawSumHandler; newAccount.Closed += closeAccountHandler; newAccount.Opened += openAccountHandler; newAccount.Calculated += calculationHandler; newAccount.Transfered += transferHandler; newAccount.Open(); }
public void Open(AccountType accountType, decimal sum, AccountStateHandler add, AccountStateHandler withdraw, AccountStateHandler open, AccountStateHandler close, AccountStateHandler calculate) { T newAccount = null; switch (accountType) { case AccountType.Ordinary: newAccount = new DemandAccount(sum, 10) as T; break; case AccountType.Deposit: newAccount = new DepositAccount(sum, 20) as T; break; } if (newAccount == null) { throw new Exception("Error create account!"); } if (accounts == null) { accounts = new T[] { newAccount } } ; else { T[] tempAccounts = new T[accounts.Length + 1]; for (int i = 0; i < accounts.Length; ++i) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length] = newAccount; accounts = tempAccounts; } newAccount.Added += add; newAccount.Calculated += calculate; newAccount.Closed += close; newAccount.Opened += open; newAccount.WithDraw += withdraw; newAccount.Open(); }
/// <summary> /// Метод открытия счета в банке /// </summary> /// <param name="name">Имя клиента</param> /// <param name="surname">Фамилия клиента</param> /// <param name="sum">Начальная сумма</param> /// <param name="add">Событие добавления на счнт</param> /// <param name="withdraw">Событие снятия со счета</param> /// <param name="open">Событие открытия счета</param> /// <param name="close">Событие закрытия счета</param> public void OpenAccount(string name, string surname, decimal sum, AccountStateHandler add, AccountStateHandler withdraw, AccountStateHandler open, AccountStateHandler close, AccountStateHandler display) { #region Check input values if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("Имя не может быть пустым"); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("Фамилия не может быть пустой"); } if (sum < 0) { throw new ArgumentException("Cумма не может быть с отрицательным значением"); } #endregion int id = GenerateID(); while (!check) { check = true; foreach (KeyValuePair <int, Account> data in account_data) { if (data.Key == id) { check = false; id = GenerateID(); } } } Account new_account = new Account(name, surname, id, sum); new_account.Added += add; new_account.Withdrawed += withdraw; new_account.Opened += open; new_account.Closed += close; new_account.Displayed += display; if (!account_data.ContainsKey(id)) //при конструкции TryGetValue out new_account в 64 строке new_account является пустым, почему? { account_data.Add(id, new_account); new_account.Open(); } else { throw new Exception("Ошибка создания счета. Аккаунт с данным ID уже существует"); //TODO: Какое исключение применять } }
//Метод для создания счета public void Open ( AccountType accountType, AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler, AccountStateHandler calculationHandler, AccountStateHandler closeAccountHandler, AccountStateHandler openAccountHandler, decimal sum = 0, uint percentage = 0 ) { T account = null; switch (accountType) { case AccountType.DemandAccount: account = new DemandAccount(sum, percentage) as T; break; case AccountType.DepositAccount: account = new DepositAccount(sum, percentage) as T; break; default: break; } if (account == null) { throw new BankException("Ошибка создания счета!"); } //Добавление счета в БД accounts.Add(account); //Установка обработчиков событий account.Added += addSumHandler; account.Withdrawed += withdrawSumHandler; account.Calculated += calculationHandler; account.Closed += closeAccountHandler; account.Opened += openAccountHandler; account.Open(); }
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(); }
public void OpenAccount(AccountType type, decimal sum, AccountStateHandler openHandler, AccountStateHandler closeHandler, AccountStateHandler putHandler, AccountStateHandler withdrawHandler, AccountStateHandler transferHandler, AccountStateHandler changeTypeHandler) // open new account { T newAccount = default(T); switch (type) { case AccountType.Small: newAccount = new SmallAccount(sum) as T; break; case AccountType.Middle: newAccount = new MiddleAccount(sum) as T; break; case AccountType.Premium: newAccount = new PremiumAccount(sum) as T; break; } if (newAccount == null) { throw new NullReferenceException("Unreal to create an account of chosen type. Account is null object"); } _accounts.Add(newAccount); newAccount.OpenEvent += openHandler; newAccount.CloseEvent += closeHandler; newAccount.PutEvent += putHandler; newAccount.WithdrawEvent += withdrawHandler; newAccount.TransferEvent += transferHandler; newAccount.ChangeAccountTypeEvent += changeTypeHandler; Item item = new Item("opening", sum); newAccount.Opened(item); newAccount.OpenEvent -= openHandler; }
/* --- Method of Creating a New User Account --- */ public void Create(AccountType accountType, string name, AccountStateHandler takeBookHandler, AccountStateHandler returnBookHandler, AccountStateHandler createAccountHandler, AccountStateHandler deleteAccountHandler) { T newAccount = null; // Creating an Empty Account switch (accountType) { case AccountType.Student: newAccount = new StudentAccount(name) as T; // If Account for Student break; case AccountType.Teacher: newAccount = new TeacherAccount(name) as T; // If Account for Teacher break; } if (accounts == null) // If there are no Active User's Accounts in the Library { accounts = new T[] { newAccount } } ; // Creating a New Account List with New User's Account else { // Adding a New User Account to Accounts List T[] tempAccounts = new T[accounts.Length + 1]; for (int i = 0; i < accounts.Length; i++) { tempAccounts[i] = accounts[i]; } tempAccounts[tempAccounts.Length - 1] = newAccount; accounts = tempAccounts; } // Adding Account's Events Handlers newAccount.TakeBook += takeBookHandler; newAccount.ReturnBook += returnBookHandler; newAccount.CreateAccount += createAccountHandler; newAccount.DeleteAccount += deleteAccountHandler; newAccount.Create(); // Event of Creating a New Account }
public void RegisterHandler(AccountStateHandler del) { _del = del; }
// Скасування реєстрації делегата public void UnregisterHandlerVer2(AccountStateHandler callBackFunc) { _callBackFunc -= callBackFunc; // видаляємо делегат }
// Метод для реєстрації делегата Ver2 public void RegisterHandlerVer2(AccountStateHandler callBackFunc) { _callBackFunc += callBackFunc; // додаємо делегат }
// Метод для реєстрації делегата public void RegisterHandler(AccountStateHandler callBackFunc) { _callBackFunc = callBackFunc; }
public void UnregisterHandler(AccountStateHandler del) { Delegate mainDel = System.Delegate.Remove(del, _del); _del = mainDel as AccountStateHandler; }
public void RegisterHandler(AccountStateHandler del) { Delegate mainDel = System.Delegate.Combine(del, _del); _del = mainDel as AccountStateHandler; }