home *** CD-ROM | disk | FTP | other *** search
- #include "microlib.h"
-
- typedef struct {
- char deleted;
- char code[7];
- char descr[40];
- } REC;
-
- static int display_fields(REC *);
- static int prepare_fields(REC *);
- static int delete(D4DATA *, X4FILTER);
- static int edit(D4DATA *, REC *);
- static int append(D4DATA *, REC *cr);
-
- int professions()
- {
- REC *cr;
- int topics_wref; /* Window Reference. */
-
- int count, i; /* Counters. */
-
- int seek_val; /* Returned Values. */
- int read_val;
- int key_val;
-
- int code_len; /* Length of frequently used fields ... */
- int descr_len;
-
- char tmp_code[sizeof(cr->code) + 1]; /* Temp storage of CODE field entry (with NULL) */
- char tmp_descr[sizeof(cr->descr) + 1]; /* Temp storage of DESCR (with NULL) */
-
- F4FIELD *fields[3]; /* filtering... */
- F4FIELD *field_ptr;
-
- D4DATA *db_positions;
-
- X4FILTER filter;
- FILTER_INFO_BASIC info;
-
- /* Allocate memory for my record buffer */
- if ((cr = (REC *) malloc(sizeof(REC))) == NULL ) {
- w4display(mes[MT], mes[ME+1], (char *) 0);
- w4exit(1);
- }
-
- code_len = sizeof(cr->code);
- descr_len = sizeof(cr->descr);
-
- /* Define, activate and clear Data Entry screen. */
- topics_wref = w4define(7, 5, 12, 66);
- w4popup();
- w4memory();
- w4border(SINGLE, custom[MAIN_N]);
- w4title(0, 1, mes[MT_PROFESSIONS], custom[MAIN_N]);
- w4attribute(custom[MAIN_N]);
- w4activate(topics_wref);
- w4clear(0);
-
-
- /* Load screen from disk and get field coordinates */
- if (screen_file(screens(SCR_PROFESSIONS), 19, 78))
- w4exit(1);
- if (get_input_positions(screens(SCR_PROFESSIONS)))
- w4exit(1);
-
- /* Open Databases and select the proper Tags... */
- db_positions = d4open(&set, files(DBF_PROFESSIONS));
- d4tag_select(db_positions, d4tag(db_positions, "CODE_T"));
-
- g4attribute (custom[MAIN_I]); /* Set input attribute. */
-
- /* Main append, scan, edit and delete loop. */
- for(;;) { /* ==L1== */
-
- /* Blank my record buffer and display it. */
- memset(cr, (int) ' ', sizeof(REC));
-
- display_fields(cr);
-
- statline(mes[MS]);
- helpline(mes[MH]);
- g4delimiter("[]");
-
- /* Get code or any other user input. */
- read_val =0;
- while (read_val != ESC && read_val != F5 && read_val != RETURN\
- && read_val != TAB && read_val != F1) {
-
- g4(srow[1], scol[1], cr->code);
- g4picture("W999999");
- read_val = g4read();
- }
-
- /* If Function Keys */
- if (read_val == ESC)
- break; /* Out of ==L1== */
-
- if (read_val == F1) {
- help("CASE_QUERY");
- continue;
- }
-
- if (read_val == F5) {
- append(db_positions, cr);
- continue;
- }
-
- /* If ENTER was pressed and CODE field is blank... */
- if (!memcmp(cr->code + 1, space(code_len - 1), code_len - 1)) {
- statline(mes[MS+7]);
- helpline(mes[MH+22]);
- read_val = 0;
- while (read_val != RETURN && read_val != ESC && read_val != TAB ) {
- g4(srow[2], scol[2], cr->descr); g4width(descr_len, descr_len);
- read_val = g4read();
- if (read_val == F1)
- help("CASE_QUERY");
- }
-
- if (!memcmp(cr->descr, space(descr_len), descr_len))
- continue;
-
- memcpy(tmp_descr, cr->descr, descr_len);
- tmp_descr[descr_len] = '\0';
-
- d4tag_select(db_positions, d4tag(db_positions, "NAME"));
- seek_val = d4seek(db_positions, tmp_descr);
- d4tag_select(db_positions, d4tag(db_positions, "CODE_T"));
- d4unlock_index(db_positions);
- if (seek_val == r4eof || seek_val == r4after) {
- w4display("", mes[ME+2], (char *) 0);
- continue; /* ==L1== */
- }
- }
- else { /* If CODE field is not empty... */
- // Zerofill and show the entered CODE.
- zerofill(cr->code + 1, code_len - 1);
- w4attribute(custom[MAIN_I]);
- w4num(srow[1], scol[1], cr->code, code_len);
- w4attribute(custom[MAIN_N]);
-
- /* Copy code and add NULL. */
- memcpy(tmp_code, cr->code, code_len);
- tmp_code[code_len] = '\0';
-
- seek_val = d4seek(db_positions, (char *)&tmp_code);
- d4unlock_index(db_positions);
- if (seek_val == r4eof || seek_val == r4after) {
- w4display("", mes[ME+2], (char *) 0);
- continue; // ==L1==
- }
- }
-
- // If CODE or SURNAMEKEY was found display the record and let the
- // user to skip through the records, edit, delete, change to
- // the second screen or ask for help.
-
- memcpy(cr, (REC *) d4record(db_positions), sizeof(REC));
-
- helpline(mes[MH+33]); // Show new available keys.
- statline(mes[MS+8]);
-
- // Clear delimiters from CODE and SURNAME field
- w4num(srow[1], scol[1] -1, space(code_len +2), code_len +2);
- w4num(srow[2], scol[2] -1, space(descr_len +2), descr_len +2);
-
- display_fields(cr);
-
- for (;;) { /* ==L2== */
- key_val = g4char();
- if (key_val != PGUP && key_val != PGDN && key_val != ESC &&
- key_val != F1 && key_val != RETURN &&
- key_val != F2 && key_val != F3 && key_val != F6 &&
- key_val != F7 && key_val != F8 && key_val != F4)
- continue;
-
- if (key_val == PGUP) {
- if (d4skip(db_positions, -1L) == r4bof)
- d4bottom(db_positions);
- }
-
- if (key_val == PGDN) {
- if (d4skip(db_positions, 1L) == r4eof)
- d4top(db_positions);
- }
-
- if (key_val == F1) {
- help("CASE_ROLL");
- continue;
- }
-
- if (key_val == ESC)
- break; /* ==L2 ==*/
-
- if (key_val == F2) {
- edit(db_positions, cr);
- display_fields(cr);
- }
-
- if (key_val == RETURN) {
- display_fields(cr);
- }
-
- if (key_val == F6) {
- helpline(mes[MH+33]); /* Show new available keys. */
- statline(mes[MS+8]);
- key_val = RETURN;
- }
-
- if (key_val == F7) {
- helpline(mes[MH+33]); /* Show new available keys. */
- statline(mes[MS+8]);
- continue;
- }
-
- if (key_val == F4) {
- continue;
- }
-
- if (key_val == F8) {
- delete(db_positions, filter);
- }
-
- memcpy(cr, (REC *) d4record(db_positions), sizeof(REC));
- if (key_val != RETURN && key_val != F2) {
- display_fields(cr);
- }
- } /* ==L2== */
-
- } /* ==L1== */
-
- statline(mes[MS+2]);
- helpline(mes[MH+3]);
- d4close_all(&set);
-
- free(cr);
- w4deactivate(topics_wref);
- w4close(topics_wref);
- /* Return the menu item to be selected. */
- return (2);
- }
-
- /************************************************************************/
- /* Display Fields */
- /************************************************************************/
- static int display_fields(cr)
- REC *cr;
- {
- w4attribute(custom[MAIN_I]);
- w4num(srow[1], scol[1], cr->code, sizeof(cr->code));
- w4num(srow[2], scol[2], cr->descr, sizeof(cr->descr));
-
- w4attribute(custom[MAIN_N]);
-
- return (1);
- }
-
- /************************************************************************/
- /* Prepare Gets. */
- /************************************************************************/
- static int prepare_fields(cr)
- REC *cr;
- {
- w4attribute(custom[MAIN_I]);
- w4num(srow[1], scol[1], cr->code, sizeof(cr->code));
- w4attribute(custom[MAIN_N]);
-
- g4(srow[2], scol[2], cr->descr); g4width(40,40);
-
- return (1);
- }
-
- /************************************************************************/
- /* Append a record */
- /************************************************************************/
- static int append(dbfile, cr)
- D4DATA *dbfile;
- REC *cr;
- {
- REC *rec_buffer;
- D4DATA *dbcodes; /* File to get last code. */
- int count; /* Counter. */
- int read_val; /* Returned value. */
-
- char old_code[7];
- char tmp_code[7]; /* Temporary storage of CODE field */
- /* because when I clear my buffer I lose */
- /* the next available code. */
- int code_len; /* Length of frequently used fields ... */
- int descr_len;
- int someone_used_the_code;
-
- someone_used_the_code = FALSE;
- code_len = sizeof(cr->code);
-
- d4tag_select(dbfile , d4tag(dbfile, "CODE_T"));
-
- /* Main Append Loop (where next code number is given etc.). */
- for (;;) { /* ==L1== */
- /* Read the last code used from CODES file. */
- dbcodes = d4open(&set, files(DBF_CODES));
- d4tag_select(dbcodes, d4tag(dbcodes, "CODE_T"));
- d4lock_file(dbcodes);
- d4lock_index(dbcodes);
- if (d4seek(dbcodes, "W") != 0 ) {
- d4close_all(&set);
- w4display(mes[MT+1], mes[ME+9], (char *) 0);
- w4exit(1);
- }
- memcpy(cr->code, f4str(d4field(dbcodes, "CODE")), code_len);
- memcpy(old_code, cr->code, code_len);
- old_code[7]='\0';
- d4close(dbcodes);
-
- /* The character field is converted to numeric , */
- /* the value is increased by 1 and then the result */
- /* is converted again to character. */
- /* At the numeric-->character conversion I use a */
- /* negative length in order to "zerofill" the result. */
- c4ltoa(c4atol(cr->code+1, code_len-1) + 1, cr->code+1, -6);
-
- /* Save the next available code. */
- memcpy(tmp_code, cr->code, code_len);
- tmp_code[7]='\0';
-
- /* Show next available code, clear buffer, restore the next */
- /* available code. Show the screen file and prepare gets. */
-
- w4attribute(custom[MAIN_I]);
- w4num(srow[1], scol[1], cr->code, code_len);
- w4attribute(custom[MAIN_N]);
- memset(cr, (int) ' ', sizeof(REC));
- memcpy(cr->code, tmp_code, code_len);
-
- if (get_input_positions(screens(SCR_PROFESSIONS)))
- w4exit(1);
- prepare_fields(cr);
-
- /* Entry Loop */
- for (;;) {
- helpline(mes[MH+4]);
- statline(mes[MS+4]);
- read_val = g4read();
- switch (read_val) {
- case ESC :
- if (warning(mes[MH+6]))
- return(0);
- break;
-
- case F1 :
- help("CASE_APPEND");
- break;
-
- case F10 :
- dbcodes = d4open(&set, files(DBF_CODES));
- d4tag_select(dbcodes, d4tag(dbcodes, "CODE_T"));
- d4lock_file(dbcodes);
- d4lock_index(dbcodes);
- if( d4seek(dbcodes, old_code) != 0 ) {
- if( d4seek(dbcodes, "W") != 0 ) {
- d4close_all(&set);
- w4display(mes[MT+1], mes[ME+9], (char *) 0);
- w4exit(1);
- }
- memcpy(cr->code, f4str(d4field(dbcodes, "CODE")), code_len);
- c4ltoa(c4atol(cr->code+1, code_len-1) + 1, cr->code+1, -6);
- memcpy(tmp_code, cr->code, code_len);
- tmp_code[7]='\0';
- f4assign(d4field(dbcodes, "CODE"), tmp_code);
- d4close(dbcodes);
- someone_used_the_code = TRUE;
- }
- else { /* If CODE is still the same. */
- f4assign(d4field(dbcodes, "CODE"), tmp_code);
- d4close(dbcodes);
- }
-
- //for(count = 0; count <= descr_len -1; count ++)
- // cr->lname[count] = gtoupper(cr->lname[count]);
- rec_buffer = (REC *) d4record(dbfile);
- d4append_start(dbfile, 0);
- d4blank(dbfile);
- memcpy(rec_buffer, cr, sizeof(REC));
- d4append(dbfile);
- d4flush_all(dbfile);
- d4unlock_all_data(dbfile);
- d4unlock_index(dbfile);
- if (someone_used_the_code) {
- w4display("", mes[ME+10], mes[ME+11], tmp_code, (char *) 0);
- someone_used_the_code = FALSE;
- }
- if (screen_file(screens(SCR_PROFESSIONS), 19, 78))
- w4exit(1);
- return (1);
- default :
- prepare_fields(cr);
- break;
- }
- }
-
- } /* ==L1== */
- }
-
- /************************************************************************/
- /* Edit a record */
- /************************************************************************/
- static int edit(dbfile, cr)
- D4DATA *dbfile;
- REC *cr;
- {
- REC *rec_buffer;
- D4DATA *db_chistory;
- D4DATA *db_credit;
-
- int read_val; /* Returned Value. */
- int count; /* Counter. */
- //int descr_len; /* Length of frequently used field ... */
-
- //descr_len = sizeof(cr->descr);
-
- prepare_fields(cr);
-
- /* Main Edit Loop... */
- for (;;) { /* ==L1== */
- helpline(mes[MH+4]);
- statline(mes[MS+4]);
-
- read_val = g4read();
- if (read_val == ESC) {
- if (warning(mes[MH+17]))
- break;
- }
- else if (read_val == F1)
- help("CASE_EDIT");
-
- else if (read_val == F10) {
- /* If client not the same */
- //if (memcmp(tmp_client, cr->client, 7)) {
- // db_chistory = d4open(&set, files(27));
- // d4tag_select(db_chistory, d4tag(db_chistory, "CASE_T"));
- // /* If that person is found in a case do not delete the record */
- // if(d4seek(db_chistory, f4str(d4field(dbfile, "CODE"))) == 0) {
- // d4close(db_chistory);
- // w4display("", mes[ME+33], mes[ME+34], " ", mes[MH+16], (char*) 0);
- // prepare_fields(cr);
- // continue;
- // }
- // d4close(db_chistory);
- // db_credit = d4open(&set, files(30));
- // d4tag_select(db_credit, d4tag(db_credit, "CASE_T"));
- // /* If that person is found in a case do not delete the record */
- // if(d4seek(db_credit, f4str(d4field(dbfile, "CODE"))) == 0) {
- // d4close(db_credit);
- // w4display("", mes[ME+33], mes[ME+34], " ", mes[MH+16], (char*) 0);
- // prepare_fields(cr);
- // continue;
- // }
- // d4close(db_credit);
- // }
- if (warning(mes[MH+7])) {
- //for (count = 0; count <= descr_len -1; count ++)
- // cr->surnamekey[count] = gtoupper(cr->surname[count]);
- rec_buffer = (REC *) d4record(dbfile);
- d4blank(dbfile); /* Set "record changed" flag to true. */
- memcpy(rec_buffer, cr, sizeof(REC));
- d4flush_all(dbfile);
- d4unlock_all_data(dbfile);
- d4unlock_index(dbfile);
- break;
- }
- }
-
- prepare_fields(cr);
-
- } /* ==L1==*/
-
- helpline(mes[MH+33]);
- statline(mes[MS+8]);
-
- return (1);
- }
-
- /************************************************************************/
- /* Delete a record */
- /************************************************************************/
- static int delete(dbfile, filter)
- D4DATA *dbfile;
- X4FILTER filter;
- {
- D4DATA* db_persons;
-
- /* If that case is found in a chistory or credit DBF do not delete the record */
- // locate the supervisor code, if any, and blank it out
- // in the persons.dbf
- //db_persons = d4open(&set, files(27));
- //d4tag_select(db_persons, d4tag(db_persons, "CASE_T"));
- //if (d4seek(db_persons, f4str(d4field(dbfile, "CODE"))) == 0) {
- // d4close(db_pe);
- // w4display("", mes[ME+29], mes[ME+31], " ", mes[MH+16], (char*) 0);
- // return(0);
- //}
- //d4close(db_persons);
-
- if (warning(mes[MH+5])) {
-
- d4delete(dbfile);
- d4flush_all(dbfile);
- d4unlock_all_data(dbfile);
- d4unlock_index(dbfile);
- d4unlock_index(dbfile);
- }
-
- return (1);
- }
-