home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / isam / tut3 / empmaint.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  4.6 KB  |  243 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 print_report(void)
  29.     {
  30.     employee.set_idx("Employee Number");
  31.     employee.rew();
  32.  
  33.     while (employee.next() == IM_OK)
  34.     {
  35.     fprintf(stdprn, "%-5d  %-5s  %-20s  %-8ld  %1s  ", employee.emp_no,
  36.         employee.initials, employee.surname, employee.salary,
  37.         employee.dept);
  38.     if (dept_ok())
  39.         fprintf(stdprn, "%-30s\r\n", dept.dept_name);
  40.     else
  41.         fprintf(stdprn, "**INVALID DEPARTMENT**\l\n");
  42.     }
  43.     employee.set_idx("Name");
  44.     }
  45.  
  46. void pay_rise(void)
  47.     {
  48.     employee.rew();
  49.  
  50.     while (employee.next() == IM_OK)
  51.     {
  52.     if (dept_ok())
  53.         {
  54.         employee.salary += (employee.salary * dept.payrise) / 100;
  55.         employee.amend();
  56.         }
  57.     }
  58.     }
  59.  
  60. void draw_screen(void)
  61.     {
  62.     FSputs("emp_no", attrLEGEND, 3, 3);
  63.     FSputs("initials", attrLEGEND, 4, 1);
  64.     FSputs("surname", attrLEGEND, 5, 2);
  65.     FSputs("dept", attrLEGEND, 6, 5);
  66.     FSputs("salary", attrLEGEND, 7, 3);
  67.     }
  68.  
  69. void display_all(void)
  70.     {
  71.     FSclrbox(3, 10, 7, 79, attrSCREEN);
  72.     FSputi(employee.emp_no, attrINPUT, 3, 10);
  73.     FSputs(employee.initials, attrINPUT, 4, 10);
  74.     FSputs(employee.surname, attrINPUT, 5, 10);
  75.     FSputs(employee.dept, attrINPUT, 6, 10);
  76.     FSputl(employee.salary, attrINPUT, 7, 10);
  77.     display_dept_name();
  78.     }
  79.  
  80. int input_data(int is_index = 0)
  81.     {
  82.     for (int x = 0; x < 5 && x >= 0;)
  83.         {
  84.         int FSerror = 0;
  85.         switch(x)
  86.             {
  87.             case 0:
  88.                 if (is_index)
  89.                     {
  90.                     x++;
  91.                     break;
  92.                     }
  93.                 FSerror = FSinputi(employee.emp_no, attrINPUT, 3, 10);
  94.                 break;
  95.  
  96.             case 1:
  97.                 FSerror = FSinputs(employee.initials, attrINPUT, 4, 10, 5);
  98.                 break;
  99.  
  100.             case 2:
  101.                 FSerror = FSinputs(employee.surname, attrINPUT, 5, 10, 20);
  102.                 break;
  103.  
  104.             case 3:
  105.                 if (is_index)
  106.                     {
  107.                     x++;
  108.                     break;
  109.                     }
  110.                 FSerror = FSinputs(employee.dept, attrINPUT, 6, 10, 1);
  111.         if (!dept_ok() && FSerror != FS_CURSORUP &&
  112.             FSerror != FS_BACKSPACE && FSerror != FS_ESCAPE &&
  113.             FSerror != FS_PGUP)
  114.             {
  115.             FSerror = 0;
  116.             }
  117.         display_dept_name();
  118.                 break;
  119.  
  120.             case 4:
  121.                 if (is_index)
  122.                     {
  123.                     x++;
  124.                     break;
  125.                     }
  126.                 FSerror = FSinputl(employee.salary, attrINPUT, 7, 10);
  127.                 break;
  128.             }
  129.  
  130.         switch (FSerror)
  131.             {
  132.             case FS_ENTER:
  133.             case FS_CURSORDOWN:
  134.                 x++;
  135.                 break;
  136.  
  137.             case FS_CURSORUP:
  138.             case FS_BACKSPACE:
  139.                 x--;
  140.                 break;
  141.  
  142.         case FS_PGDN:
  143. //                x = 999; // Commented out so user can't skip dept validation!
  144.         x++;
  145.         break;
  146.  
  147.             case FS_ESCAPE:
  148.             case FS_PGUP:
  149.                 x = -1;
  150.                 break;
  151.             }
  152.         }
  153.     if (x < 0)
  154.     return IM_ERROR;
  155.     return IM_OK;
  156.     }
  157.  
  158. int main(void)
  159.     {
  160.     static char *menopts[] = { "^Insert", "^Amend", "^Delete", "^Find",
  161.     "^Next", "^Prev", "^Report", "Pa^y Rise", "E^xit", NULL };
  162.     FSinit();
  163.     FSclrscr(attrSCREEN);
  164.     draw_screen();
  165.     employee.rew();
  166.     employee.clear_buf();
  167.     display_all();
  168.     FStitle("EMPLOYEE FILE MAINTENANCE", attrTITLE, 0);
  169.     for (;;)
  170.         {
  171.         switch (FSbarmenu(22, FS_CENTRE, 2, menopts, attrBMNORM, attrBMHIGH, attrBMHOTK))
  172.             {
  173.             case 0: // Insert
  174.                 employee.clear_buf();
  175.                 display_all();
  176.         if (input_data() == IM_OK)
  177.                     employee.insert();
  178.                 else
  179.                     employee.rew();
  180.                 break;
  181.  
  182.             case 1: // Amend
  183.         if (employee.retrieve() == IM_ERROR)
  184.                     break;
  185.                 display_all();
  186.         if (input_data() == IM_OK)
  187.                     employee.amend();
  188.                 break;
  189.  
  190.             case 2: // Delete
  191.                 employee.erase();
  192.                 employee.clear_buf();
  193.                 display_all();
  194.                 break;
  195.  
  196.             case 3: // Find
  197.                 employee.clear_buf();
  198.                 display_all();
  199.         if (input_data(1) == IM_OK)
  200.                     {
  201.             if (employee.find() == IM_ERROR)
  202.             if (employee.retrieve() == IM_ERROR)
  203.                 if (employee.prev() == IM_ERROR)
  204.                                 employee.clear_buf();
  205.                     display_all();
  206.                     }
  207.                 else
  208.                     {
  209.                     employee.clear_buf();
  210.                     display_all();
  211.                     }
  212.                 break;
  213.  
  214.             case 4: // Next
  215.         if (employee.next() == IM_ERROR)
  216.                     employee.prev();
  217.                 display_all();
  218.                 break;
  219.  
  220.             case 5: // Prev
  221.         if (employee.prev() == IM_ERROR)
  222.                     employee.next();
  223.                 display_all();
  224.                 break;
  225.  
  226.         case  6: // Report
  227.         print_report();
  228.         break;
  229.  
  230.         case 7: // Pay Rise
  231.         pay_rise();
  232.         break;
  233.  
  234.         case 8: // Exit
  235.             case -1: // <ESCAPE> Pressed
  236.                 return 0;
  237.  
  238.             }
  239.         }
  240.     return 0;
  241.     }
  242.  
  243.