/******************************************************** MAC BANK ABM simulation software Software Engineering 3K04 2005 *********************************************************/ /************************************************** Module: Main **************************************************/ /* include statements */ #include #include #include #include #include "constants.h" #include "screen_output.h" #include "user_interface.h" #include "operator_interface.h" #include "main_.h" #include "getch.h" #include "database.h" /* static locals */ static long int abm_cash_level = INITIAL_CASH; char cashIsUnderTenThousandDollars = 0; /* main routine */ int main(void) { /*-------------------------------------------------------------- * main() * * Description: synchonizes all functions, program starts and ends here * * Module: m_main - main * * Arguments: * none * * Return values: * 0 - no errors * 1 - couldn't open database input file * 2 - other error *--------------------------------------------------------------*/ int exit_condition = 0; char cardNumber[CARD_NUMBER_LENGTH+1]; char PIN[PIN_LENGTH+1]; switch(db_InitDatabase(DATABASE_FILENAME)) { /* load the data base into memory */ case 0: /* successful database load */ break; case 1: printf ("couldn't open database file\n"); return 1; break; case 2: printf ("database error encountered\n"); return 2; break; } do { io_DrawTopLine(); printf ("ABM simulation\n\n"); printf ("s - swipe card\n"); printf ("k - insert operator key\n"); printf ("i - increment day\n"); printf ("c - cancel\n"); io_DrawBottomLine(); switch(getch()) { case 's': if (usr_GetCardNumber(cardNumber)!=0) break; if (usr_GetCardPIN(cardNumber, PIN)!=0) break; if (DEBUG_ON == 1) { printf ("CardNumber received by main:[%s]\n", cardNumber); printf ("PIN received by main:[%s]\n", PIN); printf ("Press any key to continue...\n"); getch(); } switch (db_ValidateCardNumberAndPIN(cardNumber,PIN)) { case 0: usr_Interface(cardNumber); break; case 1: io_DrawTopLine(); printf ("Invalid card number\n"); printf ("Press any key to continue...\n"); io_DrawBottomLine(); getch(); break; case 2: io_DrawTopLine(); printf ("Card number exists, but invalid PIN\n"); printf ("Press any key to continue...\n"); io_DrawBottomLine(); getch(); break; case 3: io_DrawTopLine(); printf ("Card locked out (disabled)\n"); printf ("Press any key to continue...\n"); io_DrawBottomLine(); getch(); break; case 4: io_DrawTopLine(); printf ("Other error\n"); printf ("Press any key to continue...\n"); io_DrawBottomLine(); getch(); break; } break; case 'k': opr_OperatorInterface(); break; case 'i': switch (m_increment_day()) case 0: io_DrawTopLine(); printf ("Day Successfully incremented\n"); printf ("Press any key to continue...\n"); io_DrawBottomLine(); getch(); break; case 1: io_DrawTopLine(); printf ("Error: Day not incremented\n"); printf ("Press any key to continue...\n"); io_DrawBottomLine(); getch(); break; break; case 'c' : exit_condition = 1; break; default : {/* invalid input */} } //printf ("money in abm = %d\n", abm_cash_level); //printf ("x - exit\nany key to continue\n"); } while (exit_condition != 1); printf ("GOODBYE\n"); return 0; } /* functions */ long int m_ReadABMCashLevel() { if (abm_cash_level >= 0) { return abm_cash_level; } else { return -1; } } char m_WriteABMCashLevel(long int new_cash_level) { if (new_cash_level < MIN_CASH_IN_ABM) { cashIsUnderTenThousandDollars = 1; } else { cashIsUnderTenThousandDollars = 0; } if (new_cash_level >= 0) { abm_cash_level = new_cash_level; return 0; } else { return 1; } } char m_increment_day() { // CALL TO DATABASE TO INCREMENT DAY //call database rollup function db_NewDayRollup(); //if successful return 0 return 0; //if unsuccessful return 1 return 1; }