home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / isam / tut1 / empmaint.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-07  |  3.3 KB  |  175 lines

  1.  
  2. #include <fscreen.h>
  3. #include <attrdefs.h>
  4.  
  5. #include "EMPLOYEE.H"
  6.  
  7. dfEMPLOYEE employee;
  8.  
  9. void draw_screen(void)
  10.     {
  11.     FSputs("emp_no", attrLEGEND, 3, 3);
  12.     FSputs("initials", attrLEGEND, 4, 1);
  13.     FSputs("surname", attrLEGEND, 5, 2);
  14.     FSputs("dept", attrLEGEND, 6, 5);
  15.     FSputs("salary", attrLEGEND, 7, 3);
  16.     }
  17.  
  18. void display_all(void)
  19.     {
  20.     FSclrbox(3, 10, 7, 79, attrSCREEN);
  21.     FSputi(employee.emp_no, attrINPUT, 3, 10);
  22.     FSputs(employee.initials, attrINPUT, 4, 10);
  23.     FSputs(employee.surname, attrINPUT, 5, 10);
  24.     FSputs(employee.dept, attrINPUT, 6, 10);
  25.     FSputl(employee.salary, attrINPUT, 7, 10);
  26.     }
  27.  
  28. int input_data(int is_index = 0)
  29.     {
  30.     for (int x = 0; x < 5 && x >= 0;)
  31.         {
  32.         int FSerror = 0;
  33.         switch(x)
  34.             {
  35.             case 0:
  36.                 if (is_index)
  37.                     {
  38.                     x++;
  39.                     break;
  40.                     }
  41.                 FSerror = FSinputi(employee.emp_no, attrINPUT, 3, 10);
  42.                 break;
  43.  
  44.             case 1:
  45.                 FSerror = FSinputs(employee.initials, attrINPUT, 4, 10, 5);
  46.                 break;
  47.  
  48.             case 2:
  49.                 FSerror = FSinputs(employee.surname, attrINPUT, 5, 10, 20);
  50.                 break;
  51.  
  52.             case 3:
  53.                 if (is_index)
  54.                     {
  55.                     x++;
  56.                     break;
  57.                     }
  58.                 FSerror = FSinputs(employee.dept, attrINPUT, 6, 10, 1);
  59.                 break;
  60.  
  61.             case 4:
  62.                 if (is_index)
  63.                     {
  64.                     x++;
  65.                     break;
  66.                     }
  67.                 FSerror = FSinputl(employee.salary, attrINPUT, 7, 10);
  68.                 break;
  69.             }
  70.  
  71.         switch (FSerror)
  72.             {
  73.             case FS_ENTER:
  74.             case FS_CURSORDOWN:
  75.                 x++;
  76.                 break;
  77.  
  78.             case FS_CURSORUP:
  79.             case FS_BACKSPACE:
  80.                 x--;
  81.                 break;
  82.  
  83.             case FS_PGDN:
  84.                 x = 999;
  85.                 break;
  86.  
  87.             case FS_ESCAPE:
  88.             case FS_PGUP:
  89.                 x = -1;
  90.                 break;
  91.             }
  92.         }
  93.     if (x < 0)
  94.         return IM_ERROR;
  95.     return IM_OK;
  96.     }
  97.  
  98. int main(void)
  99.     {
  100.     static char *menopts[] = { "^Insert", "^Amend", "^Delete", "^Find",
  101.         "^Next", "^Prev", "E^xit", NULL };
  102.     FSinit();
  103.     FSclrscr(attrSCREEN);
  104.     draw_screen();
  105.     employee.rew();
  106.     employee.clear_buf();
  107.     display_all();
  108.     FStitle("EMPLOYEE FILE MAINTENANCE", attrTITLE, 0);
  109.     for (;;)
  110.         {
  111.         switch (FSbarmenu(22, FS_CENTRE, 2, menopts, attrBMNORM, attrBMHIGH, attrBMHOTK))
  112.             {
  113.             case 0: // Insert
  114.                 employee.clear_buf();
  115.                 display_all();
  116.                 if (input_data() == IM_OK)
  117.                     employee.insert();
  118.                 else
  119.                     employee.rew();
  120.                 break;
  121.  
  122.             case 1: // Amend
  123.                 if (employee.retrieve() == IM_ERROR)
  124.                     break;
  125.                 display_all();
  126.                 if (input_data() == IM_OK)
  127.                     employee.amend();
  128.                 break;
  129.  
  130.             case 2: // Delete
  131.                 employee.erase();
  132.                 employee.clear_buf();
  133.                 display_all();
  134.                 break;
  135.  
  136.             case 3: // Find
  137.                 employee.clear_buf();
  138.                 display_all();
  139.                 if (input_data(1) == IM_OK)
  140.                     {
  141.                     if (employee.find() == IM_ERROR)
  142.                         if (employee.retrieve() == IM_ERROR)
  143.                             if (employee.prev() == IM_ERROR)
  144.                                 employee.clear_buf();
  145.                     display_all();
  146.                     }
  147.                 else
  148.                     {
  149.                     employee.clear_buf();
  150.                     display_all();
  151.                     }
  152.                 break;
  153.  
  154.             case 4: // Next
  155.                 if (employee.next() == IM_ERROR)
  156.                     employee.prev();
  157.                 display_all();
  158.                 break;
  159.  
  160.             case 5: // Prev
  161.                 if (employee.prev() == IM_ERROR)
  162.                     employee.next();
  163.                 display_all();
  164.                 break;
  165.  
  166.             case  6: // Exit
  167.             case -1: // <ESCAPE> Pressed
  168.                 return 0;
  169.  
  170.             }
  171.         }
  172.     return 0;
  173.     }
  174.  
  175.