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

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