home *** CD-ROM | disk | FTP | other *** search
- #include "microlib.h"
-
- typedef struct {
- char deleted;
- char code[7];
- char name[20];
- char division[20];
- char address[20];
- char zip[20];
- char city[20];
- char country[20];
- char topic[20];
- char supervisor[7];
- char phone1[20];
- char phone2[20];
- char fax[20];
- } REC;
-
- T4TAG_INFO fx_tag[] = {
- { "CODE_T", "CODE", ".NOT. DELETED()", 0, 0 },
- { 0, 0, 0, 0, 0 },
- };
-
- void update_solchk(void);
-
- static display_fields(REC *);
- static prepare_fields(REC *);
- static int delete(D4DATA *, X4FILTER);
- static int edit(D4DATA *, REC *);
- static int append(D4DATA *, REC *cr);
-
- int input()
- {
- REC *cr;
- int case_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 surn_len;
-
- char *slash_p; /* Pointer of slash "/" character in string. */
-
- char tmp_code[8]; /* Temporary storage of CODE field entry (with NULL) */
- char tmp_surname[21]; /* Temporary storage of SURNAMEKEY (with NULL) */
-
- F4FIELD *fields[3]; /* filtering... */
- F4FIELD *field_ptr;
-
- D4DATA *db_organizations;
-
- 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);
- surn_len = sizeof(cr->name);
-
- /* Define, activate and clear Data Entry screen. */
- case_wref = w4define(1, 0, 22, 79);
- w4popup();
- w4memory();
- w4border(SINGLE, custom[MAIN_N]);
- w4title(0, 1, mes[MT+13], custom[MAIN_N]);
- w4attribute(custom[MAIN_N]);
- w4activate(case_wref);
- w4clear(0);
-
-
- /* Load screen from disk and get field coordinates */
- if (screen_file(screens(SCR_ORGANIZATIONS), 19, 78))
- w4exit(1);
- if (get_input_positions(screens(SCR_ORGANIZATIONS)))
- w4exit(1);
-
-
- /* Open Databases and select the proper Tags... */
- db_organizations = d4open(&set, files(DBF_ORGANIZATIONS));
- d4tag_select(db_organizations, d4tag(db_organizations, "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("U999999");
- 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_organizations, 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->name); g4width(surn_len, surn_len);
- read_val = g4read();
- if(read_val == F1)
- help("CASE_QUERY");
- }
-
- if (!memcmp(cr->name, space(surn_len), surn_len))
- continue;
-
- memcpy(tmp_surname, cr->name, surn_len);
- tmp_surname[surn_len] = '\0';
-
- if((slash_p= (char *) memchr(tmp_surname, CUT_KEY,surn_len)) !=NULL){
- *slash_p = ' ';
- c4trim_n(tmp_surname, surn_len+1);
- }
-
- seek_val = x4seek(&filter, tmp_surname);
- d4unlock_index(db_organizations);
- if (seek_val == r4after || seek_val == r4eof) {
- w4display("", mes[ME+2], (char *) 0);
- continue;
- }
- else { // If found ...
- //info.field1 = d4field(db_case, "CODE");
- //info.field2 = d4field(db_case, "SURNAMEKEY");
- strcpy(info.find_info1, "U");
- strcpy(info.find_info2, tmp_surname);
- info.compare_len1 = 1;
- info.compare_len2 = strlen(info.find_info2);
- if(info.compare_len2 > f4len(info.field2))
- info.compare_len2 = f4len(info.field2);
-
- //x4init(&filter, db_case, filter_basicfiles, &info);
-
- //if(x4skip(&filter, 1) != 3) {
- // x4top(&filter);
- //d4unlock_index(db_case);
- //fields[0] = d4field(db_case,"CODE");
- //fields[1] = d4field(db_case,"SURNAME");
- //fields[2] = d4field(db_case,"CL_STATUS");
- //browse(5, 3, 14, mes[MT+3], db_case, filter, fields, 3);
- }
- //else
- //x4top(&filter);
-
- //d4unlock_index(db_case);
- // Return to the previous filter.
- // Show only Clients Companies
- //info.field1 = d4field(db_case, "CODE");
- //info.field2 = d4field(db_case, "SURNAMEKEY");
- strcpy(info.find_info1, "U");
- info.compare_len1 = 1;
- info.compare_len2 = 0;
- //x4init(&filter, db_case, filter_basicfiles, &info);
- } //*==if found==
-
- 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_organizations, (char *)&tmp_code);
-
- d4unlock_index(db_organizations);
- 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_organizations), 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(surn_len +2), surn_len +2);
-
- display_fields(cr); // First time.
-
- 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_organizations, -1L) == r4bof)
- d4bottom(db_organizations);
- }
-
- if (key_val == PGDN) {
- if (d4skip(db_organizations, 1L) == r4eof)
- d4top(db_organizations);
- }
-
- if (key_val == F1) {
- help("CASE_ROLL");
- continue;
- }
-
- if (key_val == ESC)
- break; /* ==L2 ==*/
-
- if (key_val == F2) {
- edit(db_organizations, 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) {
- //if (search_code[0] != 'T')
- // delete(db_case, filter);
- //else
- // delete(db_case, gl_filter);
- }
-
- //d4unlock_index(db_case);
- memcpy(cr, (REC *) d4record(db_organizations), 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(case_wref);
- w4close(case_wref);
- /* Return the menu item to be selected. */
- return (2);
- }
-
- /************************************************************************/
- /* Display Fields */
- /************************************************************************/
- static 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->name, sizeof(cr->name));
- w4num(srow[3], scol[3], cr->division, sizeof(cr->division));
- w4num(srow[4], scol[3], cr->address, sizeof(cr->address));
- w4num(srow[5], scol[3], cr->zip, sizeof(cr->zip));
- w4num(srow[6], scol[3], cr->city, sizeof(cr->city));
- w4num(srow[7], scol[3], cr->country, sizeof(cr->country));
- w4num(srow[8], scol[3], cr->topic, sizeof(cr->topic));
- w4num(srow[9], scol[3], cr->supervisor, sizeof(cr->supervisor));
- w4num(srow[10], scol[10], cr->phone1, sizeof(cr->phone1));
- w4num(srow[11], scol[11], cr->phone2, sizeof(cr->phone2));
- w4num(srow[12], scol[12], cr->fax, sizeof(cr->fax));
-
- w4attribute(custom[MAIN_N]);
-
- return (1);
- }
-
- /************************************************************************/
- /* Prepare Gets. */
- /************************************************************************/
- static 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->name); g4width(20,20);
- g4(srow[3], scol[3], cr->division); g4width(20,20);
- g4(srow[4], scol[3], cr->address); g4width(20,20);
- g4(srow[5], scol[3], cr->zip); g4width(20,20);
- g4(srow[6], scol[3], cr->city); g4width(20,20);
- g4(srow[7], scol[3], cr->country); g4width(20,20);
- g4(srow[8], scol[3], cr->topic); g4width(20,20);
- g4(srow[9], scol[3], cr->supervisor); g4width(07,07);
- g4(srow[10], scol[10], cr->phone1); g4width(20,20);
- g4(srow[11], scol[11], cr->phone2); g4width(20,20);
- g4(srow[12], scol[12], cr->fax); g4width(20,20);
-
- 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 surn_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(5));
- d4tag_select(dbcodes, d4tag(dbcodes, "CODE_T"));
- d4lock_file(dbcodes);
- d4lock_index(dbcodes);
- if( d4seek(dbcodes, "U") != 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_ORGANIZATIONS)))
- w4exit(1);
- prepare_fields(cr);
-
- /* Entry Loop */
- /*
- for(;;) { // ==L2==
- helpline(mes[MH+4]);
- statline(mes[MS+4]);
- read_val = g4read();
-
- if(read_val == ESC) {
- //if(warning(mes[MH+6])) {
- // if(screen_file(screens(SCR_ORGANIZATIONS), 19, 78))
- // w4exit(1);
- // return(0);
- // }
- }
-
- else if(read_val == F1)
- help("CASE_APPEND");
-
- else if (read_val == F10) {
- } //== IF F10 ==
- prepare_fields(cr);
- } // ==L2==
- */
-
- for (;;) {
- helpline(mes[MH+4]);
- statline(mes[MS+4]);
- read_val = g4read();
- switch (read_val) {
- case ESC :
- return (1);
- case F1 :
- help("CASE_APPEND");
- break;
- case F10 :
-
- dbcodes = d4open(&set, files(5));
- d4tag_select(dbcodes, d4tag(dbcodes, "CODE_T"));
- d4lock_file(dbcodes);
- d4lock_index(dbcodes);
- if( d4seek(dbcodes, old_code) != 0 ) {
- if( d4seek(dbcodes, "U") != 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);
- #ifndef SOL_DEMO
- memcpy(&chksn[33], tmp_code, 7);
- update_solchk();
- #endif
- d4close(dbcodes);
- someone_used_the_code = TRUE;
- }
- else { /* If CODE is still the same. */
- f4assign(d4field(dbcodes, "CODE"), tmp_code);
- #ifndef SOL_DEMO
- memcpy(&chksn[33], tmp_code, 7);
- update_solchk();
- #endif
- d4close(dbcodes);
- }
-
- //for(count = 0; count <= surn_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_ORGANIZATIONS), 19, 78))
- w4exit(1);
- break;
- 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 surn_len; /* Length of frequently used field ... */
-
- //surn_len = sizeof(cr->name);
-
- 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 <= surn_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==*/
- //if(screen_file(screens(13), 19, 78))
- // w4exit(1);
- helpline(mes[MH+33]);
- statline(mes[MS+8]);
-
- return (1);
- }
-
-
- /************************************************************************/
- /* Delete a record */
- /************************************************************************/
- static int delete(dbfile, filter)
- D4DATA *dbfile;
- X4FILTER filter;
- {
- D4DATA* db_chistory;
- D4DATA* db_credit;
- D4DATA* db_kwcasdoc;
-
- /* If that case is found in a chistory or credit DBF do not delete the record */
- db_chistory = d4open(&set, files(27));
- d4tag_select(db_chistory, d4tag(db_chistory, "CASE_T"));
- if(d4seek(db_chistory, f4str(d4field(dbfile, "CODE"))) == 0) {
- d4close(db_chistory);
- w4display("", mes[ME+29], mes[ME+31], " ", mes[MH+16], (char*) 0);
- return(0);
- }
- d4close(db_chistory);
-
- db_credit = d4open(&set, files(30));
- d4tag_select(db_credit, d4tag(db_credit, "CASE_T"));
- if(d4seek(db_credit, f4str(d4field(dbfile, "CODE"))) == 0) {
- d4close(db_credit);
- w4display("", mes[ME+29], mes[ME+31], " ", mes[MH+16], (char*) 0);
- return(0);
- }
- d4close(db_credit);
-
- if (warning(mes[MH+5])) {
- db_kwcasdoc = d4open(&set, files(25));
- d4tag_select(db_kwcasdoc, d4tag(db_kwcasdoc, "CODE_T"));
-
- while (d4seek(db_kwcasdoc, f4str(d4field(dbfile, "CODE"))) == 0) {
- d4delete(db_kwcasdoc);
- d4flush_all(db_kwcasdoc);
- d4unlock_all_data(db_kwcasdoc);
- d4unlock_index(db_kwcasdoc);
- }
- d4close(db_kwcasdoc);
-
- d4delete(dbfile);
- d4flush_all(dbfile);
- d4unlock_all_data(dbfile);
- d4unlock_index(dbfile);
- x4top(&filter);
- d4unlock_index(dbfile);
- }
-
- return (1);
- }
-