Пример #1
0
        //Function for fishing a row out of the database
        //Takes in the neccesary data to perform a linq query

        public static Account FindAccount(int pin, String name, Bank_Name bank, AccountType type)
        {
            using (var context = new AccountManagerContext())
            {
                Account account;
                switch (type)
                {
                case AccountType.Checking:
                    account = context.CheckingAccounts.Where(s => s.PinNumber == pin && s.AccountHolder == name && s.BankName == bank).FirstOrDefault <CheckingAccount>();
                    break;

                case AccountType.Savings:
                    account = context.SavingsAccounts.Where(s => s.PinNumber == pin && s.AccountHolder == name && s.BankName == bank).FirstOrDefault <SavingsAccount>();
                    break;

                case AccountType.Business:
                    account = context.BusinessAccounts.Where(s => s.PinNumber == pin && s.AccountHolder == name && s.BankName == bank).FirstOrDefault <BusinessAccount>();
                    break;

                default:
                    account = null;
                    break;
                }
                return(account);
            }
        }
Пример #2
0
        public static bool CreateAccount(int pin, String name, String businessName, Bank_Name bank)
        {
            Mutex mutex = new Mutex();

            mutex.WaitOne();
            using (var context = new AccountManagerContext())
            {
                if (!VerifyPin(pin))
                {
                    return(false);
                }

                if (FindAccount(pin, name, bank, AccountType.Business) != null)
                {
                    return(false);
                }

                BusinessAccount account = new BusinessAccount
                {
                    PinNumber       = pin,
                    AccountHolder   = name,
                    BankName        = bank,
                    BusinessName    = businessName,
                    Balance         = 0,
                    AccountOpenDate = DateTime.Parse(DateTime.Today.ToString())
                };

                context.BusinessAccounts.Add(account);
                context.SaveChanges();
            }
            mutex.ReleaseMutex();

            return(true);
        }
Пример #3
0
        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            //Gets the user input and parses it into a float while also performing integrity testing

            bool        success = int.TryParse(PinInput.GetLineText(0), out int pin);
            string      name    = HolderNameInput.GetLineText(0);
            Bank_Name   bank    = AccountManagerServices.ParseBankName(BankNameInput.GetLineText(0));
            AccountType type    = AccountManagerServices.ParseAccountType(AccountTypeInput.GetLineText(0));

            //Failure State actions

            if (!success)
            {
                MessageBox.Show("Invalid Pin Number");
                return;
            }

            if (bank == 0)
            {
                MessageBox.Show("Invalid bank name (specific banks may not be supported)");
                return;
            }

            if (type == 0)
            {
                MessageBox.Show("Invalid account type.");
                return;
            }

            Account account = AccountManagerServices.FindAccount(pin, name, bank, type);

            if (account == null)
            {
                MessageBox.Show("Account not found");
                return;
            }

            //This window appears can appear before or after the main window
            //Thusly the Application class function may return null
            //In that case a new instance of the main window will be created

            MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();

            if (mainWindow == null)
            {
                MainWindow window = new MainWindow(ref account);
                AccountManagerServices.ShowAccountDetails(account, window);
                window.Show();
            }
            else
            {
                AccountManagerServices.ShowAccountDetails(account, mainWindow);
                mainWindow.Show();
            }

            Close();
        }
Пример #4
0
        private void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            //Gets the user input and parses it into a float while also performing integrity testing

            bool        success_pin            = int.TryParse(PinInput.GetLineText(0), out int pin);
            bool        success_transferAmount = float.TryParse(TransferAmountInput.GetLineText(0), out float transferAmount);
            string      name = HolderNameInput.GetLineText(0);
            Bank_Name   bank = AccountManagerServices.ParseBankName(BankNameInput.GetLineText(0));
            AccountType type = AccountManagerServices.ParseAccountType(AccountTypeInput.GetLineText(0));

            //Failure State actions

            if (!success_pin)
            {
                MessageBox.Show("Invalid Pin Number");
                return;
            }

            if (bank == 0)
            {
                MessageBox.Show("Invalid bank name (specific banks may not be supported)");
                return;
            }

            if (type == 0)
            {
                MessageBox.Show("Invalid account type.");
                return;
            }

            Account receivingAccount = AccountManagerServices.FindAccount(pin, name, bank, type);

            if (receivingAccount == null)
            {
                MessageBox.Show("Account not found");
                return;
            }

            bool complete = AccountManagerServices.TransferMoney(account, receivingAccount, transferAmount);

            //Gets a reference to the main window and updates the output

            if (complete)
            {
                MessageBox.Show("Transaction Completed. Your first account balance is $" + account.Balance + Environment.NewLine + "Your second account balnace is $" + receivingAccount.Balance);
                MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();
                AccountManagerServices.ShowAccountDetails(account, mainWindow);
                Close();
            }
        }
Пример #5
0
        public static string ParseNameOfBank(Bank_Name name)
        {
            string bankName;

            if (name == 0)
            {
                return(null);
            }

            switch (name)
            {
            case Bank_Name.BOA:
                bankName = "Bank of America";
                break;

            case Bank_Name.Morgan:
                bankName = "Morgan Stanley";
                break;

            case Bank_Name.Capitol:
                bankName = "Capitol One";
                break;

            case Bank_Name.Goldman:
                bankName = "Goldman Sachs";
                break;

            case Bank_Name.TD:
                bankName = "TD Bank";
                break;

            case Bank_Name.Chase:
                bankName = "Chase";
                break;

            case Bank_Name.HSBC:
                bankName = "HSBC";
                break;

            default:
                bankName = null;
                break;
            }
            return(bankName);
        }
Пример #6
0
        protected void insertdata()
        {
            Bank_Name object1 = new Bank_Name();

            object1.AccountNo            = (TextBoxAccountNo.Text);
            object1.Bank_Name1           = TextBoxBankName.Text;
            object1.Bank_Name_Notes      = TextBoxNote.Text;
            object1.DateOfOpen           = Convert.ToDateTime(datepicker.Text);
            object1.IsDisable            = false;
            object1.Loation              = TextBoxLocation.Text;
            object1.PersonInCharge       = TextBoxPersonInCharge.Text;
            object1.Phone                = TextBoxPhone.Text;
            object1.Phone_PersonInCharge = TextBoxPhonePIC.Text;
            object1.RecTime              = DateTime.Now;
            object1.UserId               = Convert.ToInt32(Session["userid"]);


            DB.Bank_Names.InsertOnSubmit(object1);
            DB.SubmitChanges();
        }
Пример #7
0
        //Since storing an Enum is less costly than storing a varchar,
        //so I decided to just have Enum conversion operations rather than storing than bank name with every row,
        //may decide otherwise in the future.

        public static Bank_Name ParseBankName(string bankName)
        {
            bankName = bankName.Trim();
            Bank_Name name = 0;

            switch (bankName)
            {
            case "Bank of America":
                name = Bank_Name.BOA;
                break;

            case "Morgan Stanely":
                name = Bank_Name.Morgan;
                break;

            case "Capitol One":
                name = Bank_Name.Capitol;
                break;

            case "Goldman Sachs":
                name = Bank_Name.Goldman;
                break;

            case "TD Bank":
                name = Bank_Name.TD;
                break;

            case "Chase":
                name = Bank_Name.Chase;
                break;

            case "HSBC":
                name = Bank_Name.HSBC;
                break;

            default:
                return(name);
            }
            return(name);
        }
Пример #8
0
        /*
         *
         * Overloaded functions for creating accounts
         * These methods were just for quick testing, a user creating a bank account from an application would be strange from a real world perspective
         *
         */


        public static bool CreateAccount(int pin, float monthlyTransfer, String name, Bank_Name bank)
        {
            Mutex mutex = new Mutex();

            mutex.WaitOne();
            using (var context = new AccountManagerContext())
            {
                if (!VerifyPin(pin))
                {
                    return(false);
                }

                if (FindAccount(pin, name, bank, AccountType.Checking) != null)
                {
                    return(false);
                }

                CheckingAccount account = new CheckingAccount
                {
                    PinNumber             = pin,
                    AccountHolder         = name,
                    BankName              = bank,
                    Balance               = 0,
                    AccountOpenDate       = DateTime.Parse(DateTime.Today.ToString()),
                    MonthlyTransferAmount = monthlyTransfer,
                };

                context.CheckingAccounts.Add(account);
                context.SaveChanges();
            }
            mutex.ReleaseMutex();

            return(true);
        }