示例#1
0
        public void PrintAccountDetails(int idx)
        {
            AccountDetailsViewModel ad = AccountDetails;

            Console.WriteLine("=== [{0}] Account Details ===", (idx + 1));
            Console.WriteLine("Account Name: " + AccountName);
            Console.WriteLine("Acct Type: " + ad.Type.ToString());
            Console.WriteLine("Acct ID:   " + ad.AccountId);
            Console.WriteLine("Balance: " + AccountBalance());
        }
示例#2
0
        private void AcctListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int idx = (sender as ListView).SelectedIndex;
            AccountDetailsViewModel details = Bank.GetDetailsByIndex(idx);

            if (details != null)
            {
                Vm.ActiveAccountName = details.AccountName;
            }
            acctDetailsPanel.Visibility = Visibility.Hidden;
        }
示例#3
0
        public AccountDetailsViewModel AccountDetailsByAccountId(string id)
        {
            AccountDetailsViewModel ret = null;
            var item = accountDetails.AccountDetailsList.ToLookup(x => x.AccountId == id);

            foreach (var p in item[true])
            {
                ret = p;
            }
            return(ret);
        }
 public void Add(AccountDetailsViewModel item)
 {
     try
     {
         AccountDetailsList.Add(item);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#5
0
        public AccountDetailsViewModel GetDetailsByIndex(int idx)
        {
            AccountDetailsViewModel details = null;

            try
            {
                details = accountDetails.AccountDetailsList[idx];
            }
            catch (Exception e)
            {
                throw new BankingException("Details not found at IDX: " + idx);
            }
            return(details);
        }
示例#6
0
        public AccountDetailsViewModel[] GetDetailsByName(string name)
        {
            AccountDetailsViewModel[] ret = null;
            var item = accountDetails.AccountDetailsList.ToLookup(x => x.AccountName == name);
            var t    = item[true];

            if (t.Count() > 0)
            {
                ret = new AccountDetailsViewModel[t.Count()];
                foreach (var p in t.Select((x, i) => new { x, i }))
                {
                    ret[p.i] = p.x;
                }
            }
            return(ret);
        }
示例#7
0
 private void DepositButton_Click(object sender, RoutedEventArgs e)
 {
     Vm.ErrorString = String.Empty;
     try
     {
         string name = acctTextBox.Text;
         string id   = "0";
         float  amt  = (float)Convert.ToDouble(entryTextBox.Text);
         int    idx  = acctListView.SelectedIndex;
         AccountDetailsViewModel details = Bank.GetDetailsByIndex(idx);
         id = details.AccountId;
         Bank.PerformAction(id, name, "deposit", amt);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Vm.ErrorString = ex.Message;
     }
 }
示例#8
0
        public MessageData GetData()
        {
            MessageData             data = new MessageData();
            AccountDetailsViewModel vm   = _bank.AccountDetailsByAccountId(accountId);

            if (vm != null)
            {
                AccountDetailsModel model = new AccountDetailsModel();
                model.accountBalance = vm.Balance;
                model.accountId      = vm.AccountId;
                model.accountName    = vm.AccountName;
                model.accountType    = vm.Type;
                model.addBtn         = vm.AddBtn;
                data.id      = MsgType;
                data.name    = "AccountDetails";
                data.message = model;
            }
            return(data);
        }
示例#9
0
        private void DetailsButton_Click(object sender, RoutedEventArgs e)
        {
            string name = acctTextBox.Text;
            int    idx  = acctListView.SelectedIndex;

            try
            {
                AccountDetailsViewModel vm = Bank.GetDetailsByIndex(idx);
                if (vm != null)
                {
                    acctDetailsGrid.DataContext = vm;
                    acctDetailsPanel.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Vm.ErrorString = ex.Message;
            }
        }
示例#10
0
        private void InterestButton_Click(object sender, RoutedEventArgs e)
        {
            //AcctListView_SelectionChanged(acctListView, null);
            int idx = acctListView.SelectedIndex;

            try
            {
                AccountDetailsViewModel vm = BankControlForm.Bank.GetDetailsByIndex(idx);
                if (vm != null)
                {
                    float interest = (vm.Type == AccountType.INTEREST_CHECKING ? Bank.CheckingInterest : Bank.SavingsInterest);
                    Bank.PerformAction(vm.AccountId, Vm.ActiveAccountName, "accrue", interest);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Vm.ErrorString = ex.Message;
            }
        }
示例#11
0
        public override int Display(Bank bank)
        {
            if (bank == null)
            {
                return(1);
            }

            string      entry    = String.Empty;
            string      name     = String.Empty;
            string      acctId   = Bank.InitialID;
            float       amt      = 0F;
            float       balance  = 0F;
            AccountType acctType = AccountType.UNINIT;

            Console.Write("Enter a name: ");
            entry = Console.ReadLine();
            name  = entry;
            while ((String.Compare(entry, "quit", true) != 0) && (String.Compare(entry, "q", true) != 0))
            {
                Console.WriteLine("Account for {0}. Balance: [{1}]" + Environment.NewLine, name, balance);
                Console.WriteLine("What would you like to do? Type:");
                Console.WriteLine("[o]pen - Open/Create a new account.");
                Console.WriteLine("[d]eposit - Deposit entered amount into an Account.");
                Console.WriteLine("[w]ithdraw - Withdraw entered amount from an Account.");
                Console.WriteLine("[b]alance - Print out the balance of an Account.");
                Console.WriteLine("[a]ccrue -- Accrue interest on the Account.");
                Console.WriteLine("[s]witch - Switch to a named Account.");
                Console.WriteLine("[p]rint - Print out details of an Account.");
                Console.WriteLine("[du]mp -- Dump details of all Accounts");
                Console.WriteLine("[q]uit - Quit the program.");
                Console.Write("====> ");
                entry = Console.ReadLine();
                try
                {
                    switch (entry)
                    {
                    case "open":
                    case "o":
                        Console.WriteLine("Opening an Account. What Type? [s]imple, [i]nterest or [sa]vings");
                        string type = Console.ReadLine();
                        Console.Write("Initial Deposit? ");
                        entry  = Console.ReadLine();
                        amt    = (float)Convert.ToDouble(entry);
                        acctId = bank.GetNewAcctId();
                        string cmd = "uninit";
                        if (type == "s")
                        {
                            acctType = AccountType.SIMPLE_CHECKING;
                            cmd      = "deposit";
                        }
                        else if (type == "i")
                        {
                            acctType = AccountType.INTEREST_CHECKING;
                            cmd      = "accrue";
                        }
                        else if (type == "sa")
                        {
                            acctType = AccountType.SAVINGS;
                            cmd      = "accrue";
                        }
                        else
                        {
                            Console.WriteLine("Undefined action: " + type + ". Type one of [s] or [i].");
                        }
                        try
                        {
                            balance = bank.PerformAction(acctId, name, cmd, amt, acctType, true);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                        break;

                    case "deposit":
                    case "d":
                        Console.Write("How much do you want to deposit? ");
                        entry = Console.ReadLine();
                        amt   = (float)Convert.ToDouble(entry);
                        try
                        {
                            balance = bank.PerformAction(acctId, name, "deposit", amt);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                        break;

                    case "withdraw":
                    case "w":
                        Console.Write("How much do you want to withdraw? Balance: [" + balance + "] ");
                        entry = Console.ReadLine();
                        amt   = (float)Convert.ToDouble(entry);
                        try
                        {
                            balance = bank.PerformAction(acctId, name, "withdraw", amt);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                        break;

                    case "balance":
                    case "b":
                        try
                        {
                            Console.WriteLine("Balance is: " + bank.PerformAction(acctId, name, "balance", amt));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                        break;

                    case "accrue":
                    case "a":
                        AccountDetailsViewModel details = bank.AccountDetailsByAccountId(acctId);
                        float defaultInterest           = ((details.Type == AccountType.INTEREST_CHECKING) ? bank.CheckingInterest : bank.SavingsInterest);
                        Console.WriteLine("Accruing interest on Account: Default is {0}%", (defaultInterest * 100.0F));
                        Console.WriteLine("Do you want to change it? [y] or [n]");
                        float interest = defaultInterest;
                        entry = Console.ReadLine();
                        if (entry == "y")
                        {
                            Console.Write("Enter a percent value: ");
                            entry    = Console.ReadLine();
                            interest = (float)(Convert.ToDouble(entry) / 100.0D);
                            Console.WriteLine("Interest changed to: [{0}]", (interest * 100.0F));
                        }
                        try
                        {
                            balance = bank.PerformAction(acctId, name, "accrue", interest);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                        break;

                    case "switch":
                    case "s":
                        Console.Write("Enter the Account Name to Switch to: ");
                        name = Console.ReadLine();
                        amt  = 0;
                        try
                        {
                            AccountDetailsViewModel[] vm = bank.GetDetailsByName(name);
                            string choice = String.Empty;
                            if (vm.Count() > 1)
                            {
                                Console.Write("Which Acct? ");
                                foreach (var v in vm.Select((x, i) => new { x, i }))
                                {
                                    Console.Write("[{0}]: {1} - {2} ; ", v.i, v.x.AccountId, v.x.Type.ToString());
                                }
                                Console.Write(Environment.NewLine + "Choose One: ==> ");
                                choice = Console.ReadLine();
                            }
                            int chosenIdx = 0;
                            if (!String.IsNullOrEmpty(choice))
                            {
                                chosenIdx = Convert.ToInt32(choice);
                            }
                            string id = "0";
                            if (vm != null)
                            {
                                id = vm[chosenIdx].AccountId;
                            }
                            acctId  = id;
                            balance = bank.PerformAction(acctId, name, "balance", 0);
                        }
                        catch (Exception e)
                        {
                            balance = 0;
                            Console.WriteLine(e.Message);
                        }
                        break;

                    case "print":
                    case "p":
                        Console.WriteLine(bank.PerformAction(acctId, name, "print", amt));
                        break;

                    case "dump":
                    case "du":
                        bank.DumpAccounts();
                        break;

                    case "quit":
                    case "q":
                        Console.WriteLine("Exiting...");
                        break;

                    default:
                        Console.WriteLine("Undefined action: " + entry + ". Type one of [balance], [withdraw] or [deposit].");
                        break;
                    }
                }
                catch (MethodSelector.AccountNotFoundException ae)
                {
                    Console.WriteLine(ae.Message);
                    balance = 0;
                }
                catch (MethodSelector.BankingException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Open an Account by Typing \'open\'");
                }
            }
            Console.Write("...Goodbye. Hit ENTER to Exit.");
            Console.ReadLine();

            return(0);
        }