home *** CD-ROM | disk | FTP | other *** search
-
- #include <fscreen.h>
- #include <attrdefs.h>
-
- #include "EMPLOYEE.H"
- #include "DEPT.H"
-
- dfEMPLOYEE employee;
- dfDEPT dept;
-
- int dept_ok(void)
- {
- strcpy(dept.dept_code, employee.dept);
- if (dept.find() == IM_OK)
- return 1;
- return 0;
- }
-
- void display_dept_name(void)
- {
- FSclrbox(6, 13, 6, 53, attrSCREEN);
- if (dept_ok())
- FSputs(dept.dept_name, attrINPUT, 6, 13);
- else
- FSputs("**INVALID DEPARTMENT**", attrINPUT, 6, 13);
- }
-
- void print_report(void)
- {
- employee.set_idx("Employee Number");
- employee.rew();
-
- while (employee.next() == IM_OK)
- {
- fprintf(stdprn, "%-5d %-5s %-20s %-8ld %1s ", employee.emp_no,
- employee.initials, employee.surname, employee.salary,
- employee.dept);
- if (dept_ok())
- fprintf(stdprn, "%-30s\r\n", dept.dept_name);
- else
- fprintf(stdprn, "**INVALID DEPARTMENT**\l\n");
- }
- employee.set_idx("Name");
- }
-
- void pay_rise(void)
- {
- employee.rew();
-
- while (employee.next() == IM_OK)
- {
- if (dept_ok())
- {
- employee.salary += (employee.salary * dept.payrise) / 100;
- employee.amend();
- }
- }
- }
-
- void draw_screen(void)
- {
- FSputs("emp_no", attrLEGEND, 3, 3);
- FSputs("initials", attrLEGEND, 4, 1);
- FSputs("surname", attrLEGEND, 5, 2);
- FSputs("dept", attrLEGEND, 6, 5);
- FSputs("salary", attrLEGEND, 7, 3);
- }
-
- void display_all(void)
- {
- FSclrbox(3, 10, 7, 79, attrSCREEN);
- FSputi(employee.emp_no, attrINPUT, 3, 10);
- FSputs(employee.initials, attrINPUT, 4, 10);
- FSputs(employee.surname, attrINPUT, 5, 10);
- FSputs(employee.dept, attrINPUT, 6, 10);
- FSputl(employee.salary, attrINPUT, 7, 10);
- display_dept_name();
- }
-
- int input_data(int is_index = 0)
- {
- for (int x = 0; x < 5 && x >= 0;)
- {
- int FSerror = 0;
- switch(x)
- {
- case 0:
- if (is_index)
- {
- x++;
- break;
- }
- FSerror = FSinputi(employee.emp_no, attrINPUT, 3, 10);
- break;
-
- case 1:
- FSerror = FSinputs(employee.initials, attrINPUT, 4, 10, 5);
- break;
-
- case 2:
- FSerror = FSinputs(employee.surname, attrINPUT, 5, 10, 20);
- break;
-
- case 3:
- if (is_index)
- {
- x++;
- break;
- }
- FSerror = FSinputs(employee.dept, attrINPUT, 6, 10, 1);
- if (!dept_ok() && FSerror != FS_CURSORUP &&
- FSerror != FS_BACKSPACE && FSerror != FS_ESCAPE &&
- FSerror != FS_PGUP)
- {
- FSerror = 0;
- }
- display_dept_name();
- break;
-
- case 4:
- if (is_index)
- {
- x++;
- break;
- }
- FSerror = FSinputl(employee.salary, attrINPUT, 7, 10);
- break;
- }
-
- switch (FSerror)
- {
- case FS_ENTER:
- case FS_CURSORDOWN:
- x++;
- break;
-
- case FS_CURSORUP:
- case FS_BACKSPACE:
- x--;
- break;
-
- case FS_PGDN:
- // x = 999; // Commented out so user can't skip dept validation!
- x++;
- break;
-
- case FS_ESCAPE:
- case FS_PGUP:
- x = -1;
- break;
- }
- }
- if (x < 0)
- return IM_ERROR;
- return IM_OK;
- }
-
- int main(void)
- {
- static char *menopts[] = { "^Insert", "^Amend", "^Delete", "^Find",
- "^Next", "^Prev", "^Report", "Pa^y Rise", "E^xit", NULL };
- FSinit();
- FSclrscr(attrSCREEN);
- draw_screen();
- employee.rew();
- employee.clear_buf();
- display_all();
- FStitle("EMPLOYEE FILE MAINTENANCE", attrTITLE, 0);
- for (;;)
- {
- switch (FSbarmenu(22, FS_CENTRE, 2, menopts, attrBMNORM, attrBMHIGH, attrBMHOTK))
- {
- case 0: // Insert
- employee.clear_buf();
- display_all();
- if (input_data() == IM_OK)
- employee.insert();
- else
- employee.rew();
- break;
-
- case 1: // Amend
- if (employee.retrieve() == IM_ERROR)
- break;
- display_all();
- if (input_data() == IM_OK)
- employee.amend();
- break;
-
- case 2: // Delete
- employee.erase();
- employee.clear_buf();
- display_all();
- break;
-
- case 3: // Find
- employee.clear_buf();
- display_all();
- if (input_data(1) == IM_OK)
- {
- if (employee.find() == IM_ERROR)
- if (employee.retrieve() == IM_ERROR)
- if (employee.prev() == IM_ERROR)
- employee.clear_buf();
- display_all();
- }
- else
- {
- employee.clear_buf();
- display_all();
- }
- break;
-
- case 4: // Next
- if (employee.next() == IM_ERROR)
- employee.prev();
- display_all();
- break;
-
- case 5: // Prev
- if (employee.prev() == IM_ERROR)
- employee.next();
- display_all();
- break;
-
- case 6: // Report
- print_report();
- break;
-
- case 7: // Pay Rise
- pay_rise();
- break;
-
- case 8: // Exit
- case -1: // <ESCAPE> Pressed
- return 0;
-
- }
- }
- return 0;
- }
-
-