home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / kdbf / example / testrest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  22.9 KB  |  882 lines

  1. /****************************************************************************
  2. *                                                                           
  3. * FILE: TESTREST.CPP
  4. *
  5. * DESCRIPTION:  This program demonstrates how to use the restaurant        
  6. *               classes for the C++ Database Framework. 
  7. *            
  8. *               
  9. *
  10. ****************************************************************************/
  11.  
  12. // Increase the stack size. For Microsoft C++, stack size is set through
  13. // the linker option /STACK. If you use the supplied makefile, REST.MAK,
  14. // the stack size will be set to 8K.
  15.  
  16. #ifndef _MSC_VER
  17. extern unsigned _stklen = 8192U;
  18. #endif
  19.  
  20. #include  <iostream.h>
  21. #include  <conio.h>
  22. #include  <stdio.h>
  23. #include  <string.h>
  24. #include  <stdlib.h>
  25. #ifdef _MSC_VER
  26. #include  <malloc.h>
  27. #include  <graph.h>
  28. #else
  29. #include  <except.h>
  30. #include  <new.h>
  31. #include  <alloc.h>
  32. #include  <cstring.h>
  33. #endif
  34. #include  <ctype.h>
  35. #include "demo.h"
  36.  
  37. #ifdef _MSC_VER
  38.  
  39. void clrscr()
  40. {
  41.         _clearscreen(_GWINDOW);
  42.         _settextposition(0,0);
  43. }
  44.  
  45. #else
  46.  
  47. /****************************************************************************
  48. *
  49. * FUNCTION: term_func
  50. *
  51. * DESCRIPTION: Function which is called if an exception is not handled.
  52. *
  53. *
  54. ****************************************************************************/
  55.  
  56. void term_func(void)
  57. {
  58.      cout << "This exception went unhandled:" << endl;
  59.      cout << "  Name: " << __throwExceptionName << endl;
  60.        // The following information is only valid if the
  61.        // -xp (Enable exception location Information)
  62.        // compiler switch was set. Under Options|Project|
  63.        // C++ Options in the IDE.
  64.      cout << "  FileName: " << __throwFileName << endl;
  65.      cout << "  LineNumber: " << __throwLineNumber << endl;
  66.      exit(3);
  67. }
  68.  
  69. #endif
  70.  
  71. int myMain(void);
  72.  
  73. /****************************************************************************
  74. *
  75. * FUNCTION: showFavoriteOptions
  76. *
  77. * DESCRIPTION: Menu for selecting operations on the favoriteTable object.
  78. *
  79. *
  80. ****************************************************************************/
  81.  
  82. void showFavoriteOptions()
  83. {
  84.   clrscr();
  85.   cout << "+-------------------------------------------------------------+\n";
  86.   cout << "|               FAVORITE RESTAURANTS MENU                     |\n";
  87.   cout << "|                                                             |\n";
  88.   cout << "|        [9]   Previous Record     [7]   First Record         |\n";
  89.   cout << "|        [3]   Next Record         [1]   Last Record          |\n";
  90.   cout << "|                                                             |\n";     
  91.   cout << "|      [M]  Menu                 [X]  Exit to Main Menu       |\n";
  92.   cout << "+-------------------------------------------------------------+\n";
  93.   cout << "\n\n";
  94.   cout.flush();
  95. }
  96.  
  97.  
  98.  
  99. /****************************************************************************
  100. *                                                                           
  101. * FUNCTION: showSearchOptions
  102. *
  103. * DESCRIPTION: menu for selecting search conditions on the mainTable object.     
  104. *        
  105. *            
  106. *               
  107. *
  108. ****************************************************************************/
  109. void showSearchOptions()
  110. {
  111.   clrscr();
  112.  
  113.   cout << "+-------------------------------------------------------------+\n";
  114.   cout << "|                       SEARCH MENU                           |\n";     
  115.   cout << "|                                                             |\n";     
  116.   cout << "|      [C]  Locate by City/Type  [R]  Locate by Rating/Type   |\n";
  117.   cout << "|                                                             |\n";
  118.   cout << "|                Press any other key to exit.                 |\n";     
  119.   cout << "+-------------------------------------------------------------+\n";
  120.   cout << "\n\n";
  121.   cout.flush();
  122. }
  123.  
  124.  
  125.  
  126. /****************************************************************************
  127. *                                                                           
  128. * FUNCTION: showMainOptions
  129. *
  130. * DESCRIPTION: Menu for selecting operations on the mainTable object.     
  131. *        
  132. *
  133. ****************************************************************************/
  134. void showMainOptions()
  135. {
  136.   clrscr();
  137.  
  138.   cout << "+-------------------------------------------------------------+\n";
  139.   cout << "|                        MAIN MENU                            |\n";     
  140.   cout << "|                                                             |\n";     
  141.   cout << "|         [9]  Previous Record     [7]   First Record         |\n";
  142.   cout << "|         [3]  Next Record         [1]   Last Record          |\n";
  143.   cout << "|                                                             |\n";
  144.   cout << "|      [M]  Menu                                              |\n";
  145.   cout << "|      [F]  Find a Restaurant                                 |\n";
  146.   cout << "|      [R]  Enter a review                                    |\n";
  147.   cout << "|      [C]  Copy to Favorite Restaurant table                 |\n";
  148.   cout << "|      [V]  View Favorite Restaurants                         |\n";
  149.   cout << "|      [X]  Exit to DOS                                       |\n";
  150.   cout << "+-------------------------------------------------------------+\n";
  151.   cout.flush();
  152.  
  153. }
  154.  
  155.  
  156. /****************************************************************************
  157. *                                                                           
  158. * FUNCTION: errorMsg 
  159. *
  160. * DESCRIPTION: Displays an error message and error code.     
  161. *        
  162. *
  163. ****************************************************************************/
  164.  
  165. void errorMsg(char *message, int errorCode)
  166. {
  167.   cout << "\n\n" << message << errorCode << "\n";
  168.   cout.flush();
  169. }
  170.  
  171. /****************************************************************************
  172. *                                                                           
  173. * FUNCTION:  showFavoriteMenu
  174. *
  175. * DESCRIPTION: Shows the entire Menu memo field for the favoriteTable object
  176. *              and then waits for a user response to continue.
  177. *            
  178. *
  179. ****************************************************************************/
  180.  
  181. void showFavoriteMenu(FavoriteRestaurant &favoriteTable)
  182. {
  183.   long sizeOfMenu;    
  184.   long menuOffset;    
  185.   unsigned int bytesRead; 
  186.   char buffer [BLOB_COPY_LEN + 1];    
  187.  
  188.   //
  189.   // Determine the size of the Menu memo field.
  190.   //
  191.   sizeOfMenu = favoriteTable.sizeOfMenuBlob();
  192.  
  193.   clrscr();
  194.  
  195.   cout << "Here is the menu:\n";
  196.   cout.flush();
  197.  
  198.   //
  199.   //  Read and then display BLOB_COPY_LEN bytes until the entire 
  200.   //  memo is read.
  201.   //
  202.   for(menuOffset = 0; menuOffset < sizeOfMenu; 
  203.       menuOffset += BLOB_COPY_LEN)
  204.   {
  205.     favoriteTable.getMenu(buffer, BLOB_COPY_LEN + 1, menuOffset, bytesRead);
  206.  
  207.     //
  208.     // Check if memo data was read. 
  209.     //
  210.     if(bytesRead > 0)
  211.     {
  212.       cout << buffer;
  213.       cout.flush();
  214.     }
  215.   }
  216.   //
  217.   //  Wait for the user to continue.
  218.   //
  219.   cout << "\n\n PRESS ANY KEY TO CONTINUE\n";
  220.   cout.flush();
  221.   getch();
  222.   clrscr();
  223. }
  224.  
  225.  
  226. /****************************************************************************
  227. *                                                                           
  228. * FUNCTION:  showFavoriteRecord
  229. *
  230. * DESCRIPTION: Shows all field values of the current record for the 
  231. *              favoriteTable object except for contents of memo fields.
  232. *              
  233. *
  234. ****************************************************************************/
  235.  
  236. void showFavoriteRecord(FavoriteRestaurant &favoriteTable)
  237. {
  238.   Retcode retVal;
  239.  
  240.   //
  241.   // Get the record from the Favorite table and show the field values.
  242.   //
  243.   retVal = favoriteTable.getRecord();
  244.   if(retVal == PXSUCCESS)
  245.   {
  246.     cout << "NAME:    " << favoriteTable.name << "\n";
  247.     cout.flush();
  248.     cout << "TYPE:    " << favoriteTable.type << "\n";
  249.     cout.flush();
  250.   }
  251.   else
  252.   {
  253.     errorMsg("Error getting favorite record: ",(int)retVal);
  254.   }  
  255.  
  256. }
  257.  
  258. /****************************************************************************
  259. *                                                                           
  260. * FUNCTION:  viewFavoriteTable
  261. *
  262. * DESCRIPTION: Shows all field values of the current record for the 
  263. *              favoriteTable object except for memo fields, displays the
  264. *              the favoriteTable options menu, then waits for user 
  265. *              response to selections and handles the request. 
  266. *
  267. ****************************************************************************/
  268.  
  269. void viewFavoriteTable(FavoriteRestaurant &favoriteTable)
  270. {
  271.   int done;
  272.   int keyPress ;
  273.  
  274.   //
  275.   // Process user input to the new menu options.
  276.   //
  277.   done = FALSE;
  278.   while(!done)
  279.   {
  280.     //
  281.     // Show the menu options and display a record from the table.
  282.     //
  283.     showFavoriteOptions();
  284.     showFavoriteRecord(favoriteTable);
  285.  
  286.     //
  287.     // Accept user input.
  288.     //
  289.     int origKey = getch();
  290.     keyPress = toupper(origKey);
  291.  
  292.     clrscr();
  293.  
  294.     //
  295.     // Handle the user's request.
  296.     //
  297.     switch(keyPress)
  298.     {
  299.       #ifdef _MSC_VER
  300.       case 0:
  301.       case 0xE0:
  302.       #else
  303.       case 0:
  304.       #endif
  305.         //
  306.         // Check for PgUp, PgDn, Home, and End keys.
  307.         //
  308.         keyPress = getch();
  309.  
  310.         switch(keyPress)
  311.         {
  312.           case 73:                // PgUp key.
  313.             favoriteTable.up();
  314.             break;
  315.  
  316.           case 81:                // PgDn key.
  317.             favoriteTable.down();
  318.             break;
  319.  
  320.           case 71:                // Home key.
  321.             favoriteTable.home();
  322.             break;
  323.  
  324.           case 79:                // End key.
  325.             favoriteTable.end();
  326.             break;
  327.         }
  328.         break;
  329.  
  330.       case 57:                // PgUp key.
  331.         favoriteTable.up();
  332.         break;
  333.  
  334.       case 51:                // PgDn key.
  335.         favoriteTable.down();
  336.         break;
  337.  
  338.       case 55:                // Home key.
  339.         favoriteTable.home();
  340.         break;
  341.  
  342.       case 49:
  343.         favoriteTable.end();
  344.         break;
  345.  
  346.       case 'X':
  347.         done = TRUE;
  348.         break;
  349.  
  350.       case 'M': 
  351.         showFavoriteMenu(favoriteTable);
  352.         break;
  353.     }
  354.   }
  355. }
  356.  
  357. /****************************************************************************
  358. *                                                                           
  359. * FUNCTION: copyMainToFavorite 
  360. *
  361. * DESCRIPTION: Copies the current record of the mainTable object,
  362. *              including BLOB fields, to the favoriteTable object.
  363. *            
  364. *
  365. ****************************************************************************/
  366.  
  367. void copyMainToFavorite(MainRestaurant &mainTable, 
  368.   FavoriteRestaurant &favoriteTable)
  369. {
  370.   Retcode retVal;
  371.  
  372.   //
  373.   // Copy the current mainTable record and append it to favoriteTable.
  374.   //
  375.   retVal = mainTable.copyToFavorite(favoriteTable);
  376.   if( retVal != PXSUCCESS)
  377.   {
  378.     errorMsg("Record was not copied to favorite table: ",retVal);
  379.     cout << "\n\n PRESS ANY KEY TO CONTINUE\n";
  380.     cout.flush();
  381.     getch();
  382.   }
  383. }
  384.  
  385. /****************************************************************************
  386. *                                                                           
  387. * FUNCTION:  searchMainTable
  388. *
  389. * DESCRIPTION: Shows the search method options menu, allows the user to
  390. *              select an option and processes the request, reporting an
  391. *              error if the search failed.
  392. *               
  393. *
  394. ****************************************************************************/
  395. void searchMainTable(MainRestaurant &mainTable)
  396. {
  397.   Retcode retVal;
  398.   int     keyPress;
  399.   short   rating;
  400.   char    temp_buffer[5];
  401.   char    city[MAX_CITY_LEN + 1];
  402.   char    type[MAX_TYPE_LEN + 1];
  403.  
  404.     //
  405.     // In case, search is not executed. 
  406.     //
  407.     retVal = PXSUCCESS;
  408.  
  409.     //
  410.     // Show the search options menu and wait for user input.
  411.     //
  412.     showSearchOptions();
  413.     keyPress = toupper(getch());
  414.  
  415.     //
  416.     // Handle the user's request.
  417.     //
  418.     switch(keyPress) 
  419.     {
  420.       case 'C': 
  421.         //
  422.         // Get the user input.
  423.         //
  424.         cout << "City to find: ";
  425.         cout.flush();
  426.         cin.getline(city, sizeof(city));
  427.  
  428.         cout << "\nType to find: ";
  429.         cout.flush();
  430.         cin.getline(type, sizeof(type));
  431.  
  432.         //
  433.         // Attempt to find a match.
  434.         //
  435.         retVal = mainTable.findCityType(city, type, pxSearchFirst);
  436.         break;
  437.  
  438.       case 'R': 
  439.         //
  440.         // Get the user input.
  441.         //
  442.         cout << "Rating to find: ";
  443.         cout.flush();
  444.         cin.getline(temp_buffer, sizeof(temp_buffer));
  445.         rating = atoi(temp_buffer);
  446.  
  447.         cout << "\nType to find: ";
  448.         cout.flush();
  449.         cin.getline(type, sizeof(type));
  450.  
  451.         //
  452.         // Attempt to find a match.
  453.         //
  454.         retVal = mainTable.findRatingType(rating, type, pxSearchFirst);
  455.         break;
  456.     } 
  457.     //
  458.     // If a search was attempted, check if it was successful.
  459.     //
  460.     if(retVal != PXSUCCESS)
  461.     {
  462.       errorMsg("\nNo match found! Error code: ", retVal);
  463.       cout << "\n\nPRESS ANY KEY TO CONTINUE";
  464.       cout.flush();
  465.       getch();
  466.     }
  467.     clrscr();
  468. }
  469.  
  470. /****************************************************************************
  471. *                                                                           
  472. * FUNCTION: showMainReview
  473. *
  474. * DESCRIPTION: Shows the entire Review memo field for the mainTable object     
  475. *              and then processes the user's response.
  476. *            
  477. *
  478. ****************************************************************************/
  479.  
  480. void showMainReview(MainRestaurant &mainTable)
  481. {
  482.   long sizeOfReview;    
  483.   long reviewOffset;    
  484.   unsigned int  bytesRead; 
  485.   char buffer [BLOB_COPY_LEN + 1];    
  486.  
  487.   //
  488.   // Find the size of the Review memo field.
  489.   //
  490.   sizeOfReview = mainTable.sizeOfReviewBlob();
  491.  
  492.   clrscr();
  493.   cout << "Here is the complete review:\n\n";
  494.   cout.flush();
  495.  
  496.   //
  497.   //  Read and display up to BLOB_COPY_LEN + 1 bytes until the entire 
  498.   //  memo is read.
  499.   //
  500.   for(reviewOffset = 0; reviewOffset < sizeOfReview; 
  501.     reviewOffset += BLOB_COPY_LEN)
  502.   {
  503.     mainTable.getReview(buffer, BLOB_COPY_LEN + 1, reviewOffset, bytesRead);
  504.  
  505.     //
  506.     // Check if any memo data was read.
  507.     //
  508.     if(bytesRead > 0)
  509.     {
  510.       cout << buffer;
  511.       cout.flush();
  512.     }
  513.   }
  514.   //
  515.   //  Wait for the user to press any key. 
  516.   //
  517.   cout << "\n\nPRESS ANY KEY TO CONTINUE";
  518.   cout.flush();
  519.   getch();
  520.   clrscr();
  521. }
  522.  
  523. /****************************************************************************
  524. *                                                                           
  525. * FUNCTION: showMainMenu
  526. *
  527. * DESCRIPTION: shows the entire Menu memo field for the mainTable object     
  528. *              and then processes the user's response.
  529. *            
  530. *
  531. ****************************************************************************/
  532.  
  533. void showMainMenu(MainRestaurant &mainTable)
  534. {
  535.   long sizeOfMenu;    
  536.   long menuOffset;    
  537.   unsigned int bytesRead; 
  538.   char buffer [BLOB_COPY_LEN + 1];    
  539.  
  540.   //
  541.   // Find the size of the Menu memo field.
  542.   //
  543.   sizeOfMenu = mainTable.sizeOfMenuBlob();
  544.  
  545.   clrscr();
  546.   cout << "\n\nHere is the menu:\n";
  547.   cout.flush();
  548.  
  549.   //
  550.   //  Read up to BLOB_COPY_LEN + 1 bytes until the entire memo is read.
  551.   //
  552.   for(menuOffset = 0; menuOffset < sizeOfMenu; menuOffset += BLOB_COPY_LEN)
  553.   {
  554.     mainTable.getMenu(buffer, BLOB_COPY_LEN + 1, menuOffset, bytesRead);
  555.  
  556.     //
  557.     // Check if any memo data was read.
  558.     //
  559.     if(bytesRead > 0)
  560.     {
  561.       cout << buffer;
  562.       cout.flush();
  563.     }
  564.   }
  565.   //
  566.   //  Wait for the user to press any key.
  567.   //
  568.   cout << "\n\nPRESS ANY KEY TO CONTINUE";
  569.   cout.flush();
  570.   getch();
  571.   clrscr();
  572. }
  573.  
  574. /****************************************************************************
  575. *                                                                           
  576. * FUNCTION: showMainRecord 
  577. *
  578. * DESCRIPTION: Shows the current record for the mainTable object, including     
  579. *              the header portion of the Review memo field. 
  580. *           
  581. *
  582. ****************************************************************************/
  583.  
  584. void showMainRecord(MainRestaurant &mainTable)
  585. {
  586.   Retcode retVal;
  587.   int  bytesRead;
  588.  
  589.   //
  590.   // A buffer used to store the header of the Review BLOB.
  591.   //
  592.   char quickReviewBuffer[MAX_REVIEW_SIZE + 1];
  593.  
  594.   //
  595.   // Get the record from the main table.
  596.   //
  597.   retVal = mainTable.getRecord();
  598.   if(retVal == PXSUCCESS)
  599.   {
  600.     //
  601.     // For now, display a small portion of the current restaurant's review.
  602.     //
  603.     retVal = mainTable.getQuickReview(quickReviewBuffer, MAX_REVIEW_SIZE + 1,
  604.       bytesRead);
  605.  
  606.     //
  607.     //  If OK, show the field values for this record.
  608.     //
  609.     if(retVal == PXSUCCESS)
  610.     {
  611.       cout << "NAME:    " << mainTable.name      << "\n";
  612.       cout << "STREET:  " << mainTable.street    << "\n";
  613.       cout << "CITY:    " << mainTable.city      << "\n";
  614.       cout << "STATE:   " << mainTable.state     << "\n";
  615.       cout << "ZIP:     " << mainTable.zip       << "\n";
  616.       cout << "PHONE:   " << mainTable.telephone << "\n";
  617.       cout << "TYPE:    " << mainTable.type      << "\n";
  618.       cout << "RATING:  " << mainTable.rating    << "\n";
  619.       cout << "QUICK REVIEW:\n\n";
  620.       cout << quickReviewBuffer;
  621.       cout.flush();
  622.     }
  623.     else
  624.     {
  625.       errorMsg("Error getting quick review: ",(int)retVal);
  626.     }
  627.   }
  628.   else
  629.   {
  630.     errorMsg("Error getting record: ",(int)retVal);
  631.   }
  632. }
  633.  
  634. /****************************************************************************
  635. *
  636. * FUNCTION:  MAIN
  637. *
  638. * DESCRIPTION: Initializes all objects and opens database tables.
  639. *              Processes user request for selection of main menu
  640. *              options while displaying the menu options and the
  641. *              current record of the mainTable object.
  642. *
  643. ****************************************************************************/
  644. int main(void)
  645. {
  646. #ifndef _MSC_VER
  647.  
  648.   // Set the terminate function - called if an exception is not handled.
  649.   set_terminate(term_func);
  650.  
  651.   try
  652.   {
  653.     myMain();
  654.   }
  655.   catch(xalloc one)
  656.   {
  657.     cout << "Allocation failed in main" << endl;
  658.     cout << (one.why()).c_str() << endl;
  659.     cout << "  Name: " << __throwExceptionName << endl;
  660.          // The following information is only valid if the
  661.          // -xp (Enable exception location Information)
  662.          // compiler switch was set. Under Options|Project|
  663.          // C++ Options in the IDE.
  664.     cout << "  FileName: " << __throwFileName << endl;
  665.     cout << "  LineNumber: " << __throwLineNumber << endl;
  666.   }
  667.   catch(...)
  668.   {
  669.     cout << "Unhandled exception" << endl ;
  670.   }
  671. #endif
  672.  
  673.   return 0;
  674. }
  675. /****************************************************************************
  676. *
  677. * FUNCTION:  myMain
  678. *
  679. * DESCRIPTION: Initializes all objects and opens database tables.
  680. *              Processes user request for selection of main menu
  681. *              options while displaying the menu options and the
  682. *              current record of the mainTable object.
  683. *
  684. ****************************************************************************/
  685. int myMain(void)
  686. {
  687.   #if   defined(_MSC_VER) && !defined(WINDOWS)
  688.   _setvideomode(_TEXTC80);
  689.   #endif
  690.  
  691.   Retcode retVal;
  692.  
  693.   //
  694.   //  The objects in the application are initialized here.
  695.   //
  696. #ifndef WINDOWS
  697.   BEngine eng(pxNet);
  698. #else
  699.   BEngine eng(pxWin);
  700. #endif
  701.  
  702.   if (eng.lastError != PXSUCCESS)
  703.   {
  704.     errorMsg(eng.getErrorMessage(eng.lastError), eng.lastError);
  705.     return -1;
  706.   }
  707.  
  708.   BDatabase db(&eng);
  709.   if (db.lastError != PXSUCCESS)
  710.   {
  711.     errorMsg(eng.getErrorMessage(db.lastError), db.lastError);
  712.     return -1;
  713.   }
  714.  
  715.   MainRestaurant mainTable(&db);
  716.   if (mainTable.lastError != PXSUCCESS)
  717.   {
  718.     errorMsg(eng.getErrorMessage(mainTable.lastError), mainTable.lastError);
  719.     return -1;
  720.   }
  721.   FavoriteRestaurant favoriteTable(&db);
  722.   if (favoriteTable.lastError != PXSUCCESS)
  723.   {
  724.     errorMsg(eng.getErrorMessage(favoriteTable.lastError), favoriteTable.lastError);
  725.     return -1;
  726.   }
  727.   //
  728.   //  Declaration of local variables.
  729.   //
  730.   int keyPress;
  731.   int done;
  732.  
  733.   clrscr();
  734.  
  735.   //
  736.   //  Open the main table containing all the restaurant reviews.
  737.  
  738.   //  (i.e. PXTblOpen() )
  739.   //
  740.   retVal = mainTable.open("EATS");
  741.   if(retVal != PXSUCCESS)
  742.   {
  743.     //
  744.     // If a fatal application error occurs, return early.
  745.     //
  746.     errorMsg(eng.getErrorMessage(retVal), retVal);
  747.     return(-1);
  748.   }
  749.   //
  750.   //  Open the Favorite table containing all of the user's favorite 
  751.   //  restaurant menus. 
  752.   //
  753.   retVal = favoriteTable.open("FAVEATS");
  754.   if(retVal != PXSUCCESS)
  755.   {
  756.     //
  757.     // If a fatal application error occurs, clean up and return.
  758.     //
  759.     mainTable.close();
  760.     errorMsg(eng.getErrorMessage(retVal), retVal);
  761.     return(-1);
  762.   }
  763.  
  764.   //
  765.   // Move to the first record.
  766.   //
  767.   mainTable.home();
  768.   favoriteTable.home();
  769.  
  770.   //
  771.   // Process user input and selection of menu options.
  772.   //
  773.   done = FALSE;
  774.   while(!done)
  775.   {
  776.     //
  777.     // Display the main menu options and a main table record.
  778.     //
  779.     showMainOptions();
  780.     showMainRecord(mainTable);
  781.  
  782.     //
  783.     // Accept user input.
  784.     //
  785.     int origKey = getch();
  786.     keyPress = toupper(origKey);
  787.  
  788.     //
  789.     // Handle the user's request.
  790.     //
  791.     switch(keyPress)
  792.     {
  793.       #ifdef _MSC_VER
  794.       case 0xE0:
  795.       case 0:
  796.       #else
  797.       case 0:
  798.       #endif
  799.  
  800.         //
  801.         // Check for PgUp, PgDn, Home, and End keys.
  802.         //
  803.         keyPress = getch();
  804.  
  805.         switch(keyPress)
  806.         {
  807.           case 73:            // PgUp key.
  808.             mainTable.up();
  809.             break;
  810.  
  811.           case 81:            // PgDn key.
  812.             mainTable.down();
  813.             break;
  814.  
  815.           case 71:            // Home key.
  816.             mainTable.home();
  817.             break;
  818.  
  819.           case 79:            // End key.
  820.             mainTable.end();
  821.             break;
  822.         }
  823.         break;
  824.  
  825.       case 57:
  826.         mainTable.up();
  827.         break;
  828.  
  829.       case 51:            // PgDn key.
  830.         mainTable.down();
  831.         break;
  832.  
  833.       case 55:
  834.         mainTable.home();
  835.         break;
  836.  
  837.       case 49:
  838.         mainTable.end();
  839.         break;
  840.  
  841.       case 'X':
  842.         done = TRUE;
  843.         break;
  844.  
  845.  
  846.       case 'R':
  847.         showMainReview(mainTable);
  848.         break;
  849.  
  850.       case 'M':
  851.         showMainMenu(mainTable);
  852.         break;
  853.  
  854.       case 'C':
  855.         copyMainToFavorite(mainTable, favoriteTable);
  856.         break;
  857.  
  858.       case 'F':
  859.         searchMainTable(mainTable);
  860.         break;
  861.  
  862.       case 'V':
  863.         viewFavoriteTable(favoriteTable);
  864.         break;
  865.  
  866.     }
  867.   }
  868.   //
  869.   // Application ended. Close tables and return. 
  870.   //
  871.   mainTable.close();
  872.   favoriteTable.close();
  873.   return(PXSUCCESS);
  874. }
  875.  
  876.     
  877.  
  878.  
  879.  
  880.            
  881.  
  882.