Beispiel #1
0
        /*
         * When users presses an amount to withdraw
         * Passes in the amount getting withdrawed
         */
        private void withdrawInstructions(int amount)
        {
            // if statement needed for the semaphore or Mutex
            int balance = activeAccount.getBalance();

            if (dataRace.Checked == false && SemaRadio.Checked == true)
            {
                Console.WriteLine("Sema");
                activeAccount.GetSemaphore().WaitOne();
            }
            else if (dataRace.Checked == false && MutexRadio.Checked == true)
            {
                Console.WriteLine("mutex");
                mutex.WaitOne();
            }

            if (activeAccount.decrementBalance(amount))
            {
                atmManager.log("Successfully withdrawn £" + amount + ".");
                MessageBox.Show("Thank you for withdrawing £" + amount + " \nPlease collect your money");
                withdraw          = true;
                DisplayInput.Text = "";
            }
            else
            {
                atmManager.log("Insufficient balance to withdraw.");
                MessageBox.Show("Insufficent balance withdrawal thing please select another option");
            }

            if (dataRace.Checked == false && SemaRadio.Checked == true)
            {
                Console.WriteLine("Sema");
                activeAccount.GetSemaphore().Release();
            }

            else if (dataRace.Checked == false && MutexRadio.Checked == true)
            {
                Console.WriteLine("mutex");
                mutex.ReleaseMutex();
            }
        }
Beispiel #2
0
        // When green enter button is pressed
        private void enterBtn_Click(object sender, EventArgs e)
        {
            if (loginTextbox.Text == "")
            {
                wrongInputLbl.Text = "Ivalid input, Please try again";
            }
            else if (state == 1) // Account Number State
            {
                activeAccount     = findAccount(Int32.Parse(loginTextbox.Text));
                loginTextbox.Text = "";

                if (activeAccount != null) // If account number successful
                {
                    state = 2;             // PIN State
                    display();
                }
                else
                {
                    wrongInputLbl.Text = "Wrong Account Number";
                }
            }
            else if (state == 2)                                            // PIN State
            {
                if (activeAccount.checkPin(Int32.Parse(loginTextbox.Text))) // If PIN correct
                {
                    state = 3;                                              // Main Menu State
                    display();
                    incorrectPIN = 0;
                }
                else
                {
                    incorrectPIN++;
                    wrongInputLbl.Text = "Wrong PIN";
                }
                loginTextbox.Text = "";
            }
            else if (state == 6) // Choose Amount State
            {
                if (usingSemaphore)
                {
                    activeAccount.accessed.WaitOne();
                }
                if (activeAccount.decrementBalance(Int32.Parse(loginTextbox.Text), usingSemaphore))
                {
                    state = 5;
                }
                else
                {
                    state = 7;
                }

                if (usingSemaphore)
                {
                    activeAccount.accessed.Release();
                }
                display();
                loginTextbox.Text = "";
            }

            if (incorrectPIN >= 3) // If the PIN is incorrect 3 times deactivate the acoount.
            {
                activeAccount.destroyAccount();
                state = 1;
                display();
                incorrectPIN       = 0;
                wrongInputLbl.Text = "PIN wrong 3 times. Account deactivated.";
            }
        }