/************************************************** Module: User Interface **************************************************/ /* include statements */ #include #include #include #include #include "constants.h" #include "screen_output.h" #include "check_balance.h" #include "deposit.h" #include "transfer.h" #include "getch.h" #include "withdraw.h" #include "database.h" #include "user_interface.h" /* functions */ int usr_Interface(char *cardNumber) { int exit_condition = 0; do { io_DrawTopLine(); printf ("ABM User Interface\n\n"); printf ("d - Deposit Cash\n"); printf ("k - Deposit Cheque\n"); printf ("w - Withdraw\n"); printf ("b - Check Balance\n"); printf ("t - Transfer Funds\n"); printf ("c - cancel (return card)\n"); io_DrawBottomLine(); switch(getch()) { case 'd': tr_Deposit(cardNumber,0); break; case 'k': tr_Deposit(cardNumber,1); break; case 'w': tr_Withdraw(cardNumber); break; case 'b': tr_CheckBalance(cardNumber); break; case 't': tr_TransferFunds(cardNumber); break; case 'c': exit_condition = 1; break; default : {/* invalid input */} } } while(exit_condition != 1); return 0; } int usr_GetCardPIN(char *cardNumber, char *PIN) { int exit_condition = 0; int PIN_position = 0; int warn_invalid_PIN = 0; int correct_value_entered = 0; char PINlocal[PIN_LENGTH+1]; char ch; PINlocal[PIN_position] = '\0'; do { io_DrawTopLine(); printf ("Enter PIN number (%d digits):\n\n", PIN_LENGTH); printf ("e - enter\n"); printf ("b - backspace\n"); printf ("c - cancel\n"); if (warn_invalid_PIN == 1) { printf ("PIN entered must be %d digits\n", PIN_LENGTH); warn_invalid_PIN = 0; } io_DrawMidLine(); printf ("PIN#: %s\n", PINlocal); io_DrawBottomLine(); ch = getch(); if (isdigit(ch)) { PINlocal[PIN_position] = ch; PIN_position++; } else if (ch == 'c') { exit_condition = 1; } else if (ch == 'e') { if (PIN_position == PIN_LENGTH) { /* verify full PIN given */ /* PIN length okay */ exit_condition = 1; correct_value_entered = 1; } else { /* reset PIN to blank and warn user */ PIN_position = 0; warn_invalid_PIN = 1; } } else if (ch == 'b') { if (PIN_position >= 1) { PIN_position--; } } /* PIN length cannot be > PIN_LENGTH digits */ if (PIN_position > PIN_LENGTH) { PIN_position = PIN_LENGTH; } PINlocal[PIN_position] = '\0'; } while (exit_condition != 1); if (DEBUG_ON == 1) { printf ("PIN entered =[%s]\n", PINlocal); printf ("Press any key to continue...\n"); getch(); } if (correct_value_entered == 1) { strcpy(PIN, PINlocal); return 0; /* valid PIN */ } else { return 1; /* invalid PIN */ } } int usr_GetCardNumber(char *cardNumber) { int exit_condition = 0; int ID_position = 0; int warn_invalid_ID = 0; int correct_value_entered = 0; char cardNumberLocal[CARD_NUMBER_LENGTH+1]; char ch; cardNumberLocal[ID_position] = '\0'; do { io_DrawTopLine(); printf ("Enter Card Number (%d digits):\n\n", CARD_NUMBER_LENGTH); printf ("e - enter\n"); printf ("b - backspace\n"); printf ("c - cancel\n"); if (warn_invalid_ID == 1) { printf ("Card number must be %d digits\n", CARD_NUMBER_LENGTH); warn_invalid_ID = 0; } io_DrawMidLine(); printf ("Card#: %s\n", cardNumberLocal); io_DrawBottomLine(); ch = getch(); if (isdigit(ch)) { cardNumberLocal[ID_position] = ch; ID_position++; } else if (ch == 'c') { exit_condition = 1; } else if (ch == 'e') { if (ID_position == CARD_NUMBER_LENGTH) { /* verify full card number given */ /* card number length okay */ exit_condition = 1; correct_value_entered = 1; } else { /* reset value to zero and warn user */ ID_position = 0; warn_invalid_ID = 1; } } else if (ch == 'b') { if (ID_position >= 1) { ID_position--; } } /* ID length cannot be > CARD_NUMBER_LENGTH digits */ if (ID_position > CARD_NUMBER_LENGTH) { ID_position = CARD_NUMBER_LENGTH; } cardNumberLocal[ID_position] = '\0'; } while (exit_condition != 1); if (DEBUG_ON == 1) { printf ("CardNumber entered =[%s]\n", cardNumberLocal); printf ("Press any key to continue...\n"); getch(); } if (correct_value_entered == 1) { strcpy(cardNumber,cardNumberLocal); return 0; } else { return 1; } }