home *** CD-ROM | disk | FTP | other *** search
/ Games 1995 to 2000 / Games.iso / SexTetris / THECASE.C < prev   
Encoding:
C/C++ Source or Header  |  1993-09-16  |  24.6 KB  |  777 lines

  1. /*****************************************************************************/
  2. /*  THECASE.C                                                                */
  3. /*****************************************************************************/
  4. #include "microlib.h"
  5.  
  6.     typedef struct {
  7.         char deleted;
  8.         char code[7];
  9.         char surname[20];
  10.         char group[4];
  11.         char surnamekey[20];
  12.         char startdate[8];
  13.         char cascateg[4];
  14.         char procedure[4];
  15.         char client[7];
  16.         char opponent[7];
  17.         char employee[7];
  18.         char o_lawyer[7];
  19.         char judge[7];
  20.         char court[4];
  21.         char cl_status[1];
  22.         char casstat[4];
  23.         char notes1[50];
  24.         char notes2[50];
  25.         char notes3[50];
  26.         } REC;
  27.  
  28. int thecase()
  29. {
  30.     REC *cr;
  31.     int case_wref;        /* Window Reference. */
  32.  
  33.     int count, i;            /* Counters. */
  34.  
  35.     int seek_val;            /* Returned Values. */
  36.     int read_val;
  37.     int key_val;
  38.  
  39.     int code_len;            /* Length of frequently used fields ... */
  40.     int surn_len;
  41.  
  42.     char *slash_p;            /* Pointer of slash "/" character in string. */
  43.  
  44.     char tmp_code[8];        /* Temporary storage of CODE field entry (with NULL) */
  45.     char tmp_surname[21];/* Temporary storage of SURNAMEKEY (with NULL) */
  46.  
  47.     F4FIELD *fields[3];            /* filtering... */
  48.  
  49.     D4DATA *db_case;
  50.     D4DATA *db_client;
  51.     D4DATA *db_oppo;
  52.  
  53.     X4FILTER filter;
  54.     FILTER_INFO_BASIC info;
  55.  
  56.  
  57.     /* Allocate memory for my record buffer                        */
  58.     if( (cr = (REC *) malloc(sizeof(REC))) == NULL ) {
  59.         w4display(mes[MT], mes[ME+1], (char *) 0);
  60.         w4exit(1);
  61.         }
  62.  
  63.     code_len = sizeof(cr->code);
  64.     surn_len = sizeof(cr->surnamekey);
  65.  
  66.     /* Define, activate and clear Data Entry screen.    */
  67.     case_wref = w4define(1, 0, 22, 79);
  68.     w4popup();
  69.     w4memory();
  70.     w4border(SINGLE, custom[MAIN_N]);
  71.     w4title(0, 1, mes[MT+13], custom[MAIN_N]);
  72.     w4attribute(custom[MAIN_N]);
  73.     w4activate(case_wref);
  74.     w4clear(0);
  75.  
  76.  
  77.     /* Load screen from disk and get field coordinates */
  78.     if(screen_file(screens(13), 19, 78))      /* O_LAWYER.SC */
  79.         w4exit(1);
  80.     if(get_input_positions(screens(13)))
  81.         w4exit(1);
  82.  
  83.  
  84.     /* Open Databases and select the proper Tags...                 */
  85.     if( search_code[0] != 'T' )
  86.         db_case       = d4open(&set, files(19) );        /* CASE.DBF       */
  87.     else
  88.         db_case        = gl_dbfile;
  89.  
  90.     db_client    = d4open(&set, files(1)  );        /* CLIENT.DBF   */
  91.     db_oppo        = d4open(&set, files(8)  );        /* OPPONENT.DBF */
  92.  
  93.  
  94.     d4tag_select(db_client,  d4tag(db_client,   "CODE_T"));
  95.     d4tag_select(db_oppo,    d4tag(db_oppo,     "CODE_T"));
  96.  
  97.     if( search_code[0] != 'T' ) {
  98.         /* Show only The Cases */
  99.         info.field1 = d4field(db_case, "CODE");
  100.         info.field2 = d4field(db_case, "SURNAMEKEY");
  101.         strcpy(info.find_info1, "T");
  102.         info.compare_len1 = 1;
  103.         info.compare_len2 = 0;
  104.         x4init(&filter, db_case, filter_basicfiles, &info);
  105.         }
  106.  
  107.     g4attribute (custom[MAIN_I]);        /* Set input attribute.        */
  108.  
  109.     /* Main append, scan, edit and delete loop.            */
  110.     for(;;) {                                        /* ==L1==    */
  111.         /* Blank my record buffer and display it.                    */
  112.         memset(cr, (int) ' ', sizeof(REC));
  113.  
  114.         display_fields(cr);
  115.  
  116.         statline(mes[MS]);
  117.         helpline(mes[MH]);
  118.         g4delimiter("[]");
  119.         w4num_att(srow[4],scol[4]-1, "[                    ]",\
  120.                                                                 22, custom[MAIN_N]);
  121.  
  122.         /* Get code or any other user input.                    */
  123.         read_val =0;
  124.         while(read_val != ESC && read_val != F5 && read_val != RETURN\
  125.                      && read_val != TAB && read_val != F1) {
  126.             if(search_code[0] != 'T') {
  127.                 g4(srow[1], scol[1], cr->code); g4picture("T999999");
  128.                 read_val = g4read();
  129.                 }
  130.             else {
  131.                 memcpy(cr->code, search_code, 7);
  132.                 read_val = RETURN;
  133.                 }
  134.             }
  135.         /* If Function Keys                */
  136.         if(read_val == ESC)
  137.             break;    /* Out of ==L1==    */
  138.         if(read_val == F1) {
  139.             help("CASE_QUERY");
  140.             continue;
  141.             }
  142.         if(read_val == F5) {
  143.             append(db_case, cr);
  144.             continue;
  145.             }
  146.  
  147.         /* If ENTER was pressed and CODE field is blank...    */
  148.         if(! memcmp(cr->code+1, space(code_len-1),code_len-1)) {
  149.             statline(mes[MS+7]);
  150.             helpline(mes[MH+22]);
  151.             read_val = 0;
  152.             while(read_val !=RETURN && read_val !=ESC && read_val !=TAB ) {
  153.                 g4(srow[4], scol[4], cr->surnamekey); g4width(surn_len, surn_len);
  154.                 read_val = g4read();
  155.                 if(read_val == F1)
  156.                     help("CASE_QUERY");
  157.                 }
  158.             if( !memcmp(cr->surnamekey, space(surn_len), surn_len))
  159.                 continue;
  160.             for(count=0; count<=surn_len -1; count ++)
  161.                 cr->surnamekey[count] = gtoupper(cr->surnamekey[count]);
  162.  
  163.             d4tag_select(db_case , d4tag(db_case, "SURNAMEKEY_T"));
  164.             memcpy(tmp_surname, cr->surnamekey, surn_len);
  165.             tmp_surname[surn_len] = '\0';
  166.  
  167.             if((slash_p= (char *) memchr(tmp_surname, CUT_KEY,surn_len)) !=NULL){
  168.                 *slash_p = ' ';
  169.                 c4trim_n(tmp_surname, surn_len+1);
  170.                 }
  171.  
  172.             seek_val = x4seek(&filter, tmp_surname);
  173.             d4unlock_index(db_case);
  174.             if(seek_val == r4after || seek_val == r4eof) {
  175.                 w4display("", mes[ME+2], (char *) 0);
  176.                 continue;
  177.                 }
  178.             else {    /* If found ... */
  179.                 info.field1 = d4field(db_case, "CODE");
  180.                 info.field2 = d4field(db_case, "SURNAMEKEY");
  181.                 strcpy(info.find_info1, "T");
  182.                 strcpy(info.find_info2, tmp_surname);
  183.                 info.compare_len1 = 1;
  184.                 info.compare_len2 = strlen(info.find_info2);
  185.                 if(info.compare_len2 > f4len(info.field2))
  186.                     info.compare_len2 = f4len(info.field2);
  187.                 x4init(&filter, db_case, filter_basicfiles, &info);
  188.  
  189.                 if(x4skip(&filter, 1) != 3) {
  190.                     x4top(&filter);
  191.                     d4unlock_index(db_case);
  192.                     fields[0] = d4field(db_case,"CODE");
  193.                     fields[1] = d4field(db_case,"SURNAME");
  194.                     fields[2] = d4field(db_case,"CL_STATUS");
  195.                     browse(5, 3, 14, mes[MT+3], db_case, filter, fields, 3);
  196.                     }
  197.                 else
  198.                     x4top(&filter);
  199.  
  200.                 d4unlock_index(db_case);
  201.                 /* Return to the previous filter. */
  202.                 /* Show only Clients Companies */
  203.                 info.field1 = d4field(db_case, "CODE");
  204.                 info.field2 = d4field(db_case, "SURNAMEKEY");
  205.                 strcpy(info.find_info1, "T");
  206.                 info.compare_len1 = 1;
  207.                 info.compare_len2 = 0;
  208.                 x4init(&filter, db_case, filter_basicfiles, &info);
  209.                 } /*==if found==*/
  210.             }
  211.         else {        /* If CODE field is not empty...        */
  212.             /* Zerofill and show the entered CODE. */
  213.             zerofill(cr->code+1, code_len-1);
  214.             w4attribute(custom[MAIN_I]);
  215.             w4num(srow[1], scol[1], cr->code, code_len);
  216.             w4attribute(custom[MAIN_N]);
  217.  
  218.             if( search_code[0] != 'T') {
  219.                 /* Select the correct TAG and seek for the CODE. */
  220.                 d4tag_select(db_case , d4tag(db_case, "CODE_T"));
  221.                 }
  222.  
  223.             /* Copy code and add NULL. */
  224.             memcpy(tmp_code, cr->code, code_len);
  225.             tmp_code[code_len] = '\0';
  226.  
  227.             if( search_code[0] != 'T')
  228.                 seek_val = x4seek(&filter, tmp_code);
  229.             else
  230.                 seek_val = x4seek(&gl_filter, tmp_code);
  231.             d4unlock_index(db_case);
  232.             if (seek_val == r4eof || seek_val == r4after) {
  233.                 w4display("", mes[ME+2], (char *) 0);
  234.                 continue; /* ==L1== */
  235.                 }
  236.             }
  237.         /* If CODE or SURNAMEKEY was found display the record and let the */
  238.         /* user to skip through the records, edit, delete, change to      */
  239.         /* the second screen or ask for help.                             */
  240.  
  241.         memcpy(cr, (REC *) d4record(db_case), sizeof(REC));
  242.  
  243.         helpline(mes[MH+33]);    /* Show new available keys. */
  244.         statline(mes[MS+8]);
  245.  
  246.         /* Clear delimiters from CODE and SURNAME field */
  247.         w4num(srow[1], scol[1] -1, space(code_len +2), code_len +2);
  248.         w4num(srow[4], scol[4] -1, space(surn_len +2), surn_len +2);
  249.  
  250.         display_fields(cr); /* First time. */
  251.         drel(srow[8],  scol[8]  + 9, db_case, "CLIENT",    db_client,   "SURNAME");
  252.         drel(srow[10], scol[10] + 9, db_case, "OPPONENT",  db_oppo,     "SURNAME");
  253.         display_relations(db_case, db_client, db_oppo);
  254.  
  255.         for(;;) {    /* ==L2== */
  256.             key_val = g4char();
  257.             if(key_val != PGUP && key_val != PGDN && key_val != ESC &&
  258.                 key_val != F1 && key_val != RETURN &&
  259.                 key_val != F2 && key_val != F3 && key_val != F6 &&
  260.                 key_val != F7 && key_val != F8 && key_val != F4)
  261.                 continue;
  262.  
  263.             if(key_val == PGUP) {
  264.                 if( search_code[0] != 'T') {
  265.                     if(x4skip(&filter, -1) == r4bof)
  266.                         x4bottom(&filter);
  267.                     }
  268.                 else {
  269.                     if(x4skip(&gl_filter, -1) == r4bof)
  270.                         x4bottom(&gl_filter);
  271.                     }
  272.                 }
  273.             if(key_val == PGDN) {
  274.                 if( search_code[0] != 'T') {
  275.                     if(x4skip(&filter, 1) == r4eof)
  276.                         x4top(&filter);
  277.                     }
  278.                 else {
  279.                     if(x4skip(&gl_filter, 1) == r4eof)
  280.                         x4top(&gl_filter);
  281.                     }
  282.                 }
  283.             if(key_val == F1) {
  284.                 help("CASE_ROLL");
  285.                 continue;
  286.                 }
  287.             if(key_val == ESC) {
  288.                 if(screen_file(screens(13), 19, 78))      /* O_LAWYER.SC */
  289.                     w4exit(1);
  290.                 break; /* ==L2 ==*/
  291.                 }
  292.             if(key_val == F2) {
  293.                 display_relations(db_case, db_client, db_oppo);
  294.                 edit(db_case, cr);
  295.                 display_fields(cr);
  296.                 drel(srow[8],  scol[8]  + 9, db_case, "CLIENT",    db_client,   "SURNAME");
  297.                 drel(srow[10], scol[10] + 9, db_case, "OPPONENT",  db_oppo,     "SURNAME");
  298.                 display_relations(db_case, db_client, db_oppo);
  299.                 }
  300.             if(key_val == RETURN) {
  301.                 display_relations(db_case, db_client, db_oppo);
  302.                 }
  303.             if(key_val == F6) {
  304.                 strcpy(tmp_code,f4str(d4field(db_case, "CODE")));
  305.                 kw(srow[17], scol[17], 9, tmp_code );
  306.                 helpline(mes[MH+33]);    /* Show new available keys. */
  307.                 statline(mes[MS+8]);
  308.                 key_val = RETURN;
  309.                 }
  310.             if(key_val == F7) {
  311.                 strcpy(tmp_code,f4str(d4field(db_case, "CODE")));
  312.                 actions(tmp_code);
  313.                 if(get_input_positions(screens(13)))
  314.                     w4exit(1);
  315.                 helpline(mes[MH+33]);    /* Show new available keys. */
  316.                 statline(mes[MS+8]);
  317.                 continue;
  318.                 }
  319.             if(key_val == F4) {
  320.                 strcpy(tmp_code,f4str(d4field(db_case, "CODE")));
  321.                 caseeco(tmp_code);
  322.                 if(get_input_positions(screens(13)))
  323.                     w4exit(1);
  324.                 helpline(mes[MH+33]);    /* Show new available keys. */
  325.                 statline(mes[MS+8]);
  326.                 continue;
  327.                 }
  328.             if(key_val == F8) {
  329.                 if( search_code[0] != 'T')
  330.                     delete(db_case, filter);
  331.                 else
  332.                     delete(db_case, gl_filter);
  333.                 }
  334.             d4unlock_index(db_case);
  335.             memcpy(cr, (REC *) d4record(db_case), sizeof(REC));
  336.             if(key_val != RETURN && key_val != F2) {
  337.                 display_fields(cr);
  338.                 drel(srow[8],  scol[8]  + 9, db_case, "CLIENT",    db_client,   "SURNAME");
  339.                 drel(srow[10], scol[10] + 9, db_case, "OPPONENT",  db_oppo,     "SURNAME");
  340.                 }
  341.             }    /* ==L2==  */
  342.         if( search_code[0] == 'T')
  343.             break;
  344.         }            /* ==L1==    */
  345.  
  346.  
  347.     if( search_code[0] != 'T') {
  348.         statline(mes[MS+2]);
  349.         helpline(mes[MH+3]);
  350.         d4close_all(&set);
  351.         }
  352.     else {
  353.         d4close(db_client);        /* CLIENT.DBF   */
  354.         d4close(db_oppo);            /* OPPONENT.DBF */
  355.         }
  356.     free(cr);
  357.     w4deactivate(case_wref);
  358.     w4close(case_wref);
  359.     /* Return the menu item to be selected. */
  360.     return(2);
  361. }
  362.  
  363. /************************************************************************/
  364. /* Append a record                                                      */
  365. /************************************************************************/
  366. static int append(dbfile, cr)
  367. D4DATA *dbfile;
  368. REC *cr;
  369. {
  370.     REC *rec_buffer;
  371.     D4DATA *dbcodes;                /* File to get last code.                 */
  372.     int count;                        /* Counter.    */
  373.     int read_val;                    /* Returned value. */
  374.  
  375.     char old_code[7];
  376.     char tmp_code[7];                /* Temporary storage of CODE field            */
  377.                                         /* because when I clear my buffer I lose  */
  378.                                         /* the next available code.                    */
  379.     int code_len;                    /* Length of frequently used fields ...    */
  380.     int surn_len;
  381.     int someone_used_the_code;
  382.  
  383.     someone_used_the_code = FALSE;
  384.     code_len = sizeof(cr->code);
  385.     surn_len = sizeof(cr->surnamekey);
  386.  
  387.     d4tag_select(dbfile , d4tag(dbfile, "CODE_T"));
  388.  
  389.     /* Main Append Loop (where next code number is given etc.). */
  390.     for(;;) {    /* ==L1== */
  391.         /* Read the last code used from CODES file.            */
  392.         dbcodes = d4open(&set, files(5));
  393.         d4tag_select(dbcodes, d4tag(dbcodes, "CODE_T"));
  394.         d4lock_file(dbcodes);
  395.         d4lock_index(dbcodes);
  396.         if( d4seek(dbcodes, "T") != 0 ) {
  397.             d4close_all(&set);
  398.             w4display(mes[MT+1], mes[ME+9], (char *) 0);
  399.             w4exit(1);
  400.             }
  401.         memcpy(cr->code, f4str(d4field(dbcodes, "CODE")), code_len);
  402.         memcpy(old_code, cr->code, code_len);
  403.         old_code[7]='\0';
  404.         d4close(dbcodes);
  405.  
  406.         /*    The character field is converted to numeric ,        */
  407.         /* the value is increased by 1 and then the result        */
  408.         /* is converted again to character.                            */
  409.         /* At the numeric-->character conversion I use a        */
  410.         /* negative length in order to "zerofill" the result. */
  411.         c4ltoa(c4atol(cr->code+1, code_len-1) + 1, cr->code+1, -6);
  412.  
  413.         /* Save the next available code.     */
  414.         memcpy(tmp_code, cr->code, code_len);
  415.         tmp_code[7]='\0';
  416.  
  417.         /* Show next available code, clear buffer, restore the next */
  418.         /* available code. Show the screen file and prepare gets.   */
  419.  
  420.         w4attribute(custom[MAIN_I]);
  421.         w4num(srow[1], scol[1], cr->code, code_len);
  422.         w4attribute(custom[MAIN_N]);
  423.         memset(cr, (int) ' ', sizeof(REC));
  424.         memcpy(cr->code, tmp_code, code_len);
  425.  
  426.         if(get_input_positions(screens(13)))
  427.             w4exit(1);
  428.         prepare_fields(cr);
  429.  
  430.         /* Entry Loop    */
  431.         for(;;) {    /* ==L2== */
  432.             helpline(mes[MH+4]);
  433.             statline(mes[MS+4]);
  434.             read_val = g4read();
  435.  
  436.             if(read_val == ESC) {
  437.                 if(warning(mes[MH+6])) {
  438.                     if(screen_file(screens(13), 19, 78))
  439.                         w4exit(1);
  440.                     return(0);
  441.                     }
  442.                 }
  443.  
  444.             else if(read_val == F1)
  445.                 help("CASE_APPEND");
  446.  
  447.             else if (read_val == F10) {
  448.                 if(! memcmp(cr->client, space(7), 7)) {
  449.                     w4display("", mes[ME+32], mes[MH+16], (char *)0);
  450.                     }
  451.                 else if(! memcmp(cr->employee, space(7), 7)) {
  452.                     w4display("", mes[ME+32], mes[MH+16], (char *)0);
  453.                     }
  454.                 else if( warning(mes[MH+7])) {
  455.                     /* Update codes file. */
  456.                     dbcodes = d4open(&set, files(5));
  457.                     d4tag_select(dbcodes, d4tag(dbcodes, "CODE_T"));
  458.                     d4lock_file(dbcodes);
  459.                     d4lock_index(dbcodes);
  460.                     if( d4seek(dbcodes, old_code) != 0 ) {
  461.                         if( d4seek(dbcodes, "T") != 0 ) {
  462.                             d4close_all(&set);
  463.                             w4display(mes[MT+1], mes[ME+9], (char *) 0);
  464.                             w4exit(1);
  465.                             }
  466.                         memcpy(cr->code, f4str(d4field(dbcodes, "CODE")), code_len);
  467.                         c4ltoa(c4atol(cr->code+1, code_len-1) + 1, cr->code+1, -6);
  468.                         memcpy(tmp_code, cr->code, code_len);
  469.                         tmp_code[7]='\0';
  470.                         f4assign(d4field(dbcodes, "CODE"), tmp_code);
  471. #ifndef SOL_DEMO
  472.                         memcpy(&chksn[33], tmp_code, 7);
  473.                         update_solchk();
  474. #endif
  475.                         d4close(dbcodes);
  476.                         someone_used_the_code = TRUE;
  477.                         }
  478.                     else { /* If CODE is still the same. */
  479.                         f4assign(d4field(dbcodes, "CODE"), tmp_code);
  480. #ifndef SOL_DEMO
  481.                         memcpy(&chksn[33], tmp_code, 7);
  482.                         update_solchk();
  483. #endif
  484.                         d4close(dbcodes);
  485.                         }
  486.  
  487.                     for(count=0; count<= surn_len -1; count ++)
  488.                         cr->surnamekey[count] = gtoupper(cr->surname[count]);
  489.                     rec_buffer = (REC *) d4record(dbfile);
  490.                     d4append_start(dbfile, 0);
  491.                     d4blank(dbfile);
  492.                     memcpy(rec_buffer, cr, sizeof(REC));
  493.                     d4append(dbfile);
  494.                     d4flush_all(dbfile);
  495.                     d4unlock_all_data(dbfile);
  496.                     d4unlock_index(dbfile);
  497.                     if(someone_used_the_code) {
  498.                         w4display("", mes[ME+10], mes[ME+11], tmp_code, (char *) 0);
  499.                         someone_used_the_code = FALSE;
  500.                         }
  501.                     if(screen_file(screens(13), 19, 78))
  502.                         w4exit(1);
  503.                     break;
  504.                     } /* ==If warning== */
  505.                 } /*== IF F10 ==*/
  506.             prepare_fields(cr);
  507.             } /* ==L2== */
  508.         }    /* ==L1== */
  509.     }
  510.  
  511.  
  512. /************************************************************************/
  513. /* Edit a record                                                        */
  514. /************************************************************************/
  515. static int edit(dbfile, cr)
  516. D4DATA *dbfile;
  517. REC *cr;
  518. {
  519.     REC *rec_buffer;
  520.     D4DATA *db_chistory;
  521.     D4DATA *db_credit;
  522.  
  523.     int read_val;        /* Returned Value. */
  524.     int count;            /* Counter.          */
  525.     int surn_len;        /* Length of frequently used field ...    */
  526.  
  527.     char tmp_client[7+1];
  528.  
  529.     memcpy(tmp_client, cr->client, 7);
  530.     tmp_client[7] = '\0';
  531.  
  532.     surn_len = sizeof(cr->surnamekey);
  533.  
  534.     prepare_fields(cr);
  535.  
  536.     /* Main Edit Loop...                    */
  537.     for(;;) {                /* ==L1==    */
  538.         helpline(mes[MH+4]);
  539.         statline(mes[MS+4]);
  540.  
  541.             read_val = g4read();
  542.  
  543.         if(read_val == ESC) {
  544.             if(warning(mes[MH+17]))
  545.                 break;
  546.             }
  547.         else if(read_val == F1)
  548.             help("CASE_EDIT");
  549.  
  550.         else if(read_val == F10) {
  551.             /* If client not the same */
  552.             if(memcmp(tmp_client, cr->client, 7)) {
  553.                 db_chistory = d4open(&set, files(27));
  554.                 d4tag_select(db_chistory, d4tag(db_chistory, "CASE_T"));
  555.                 /* If that person is found in a case do not delete the record */
  556.                 if(d4seek(db_chistory, f4str(d4field(dbfile, "CODE"))) == 0) {
  557.                     d4close(db_chistory);
  558.                     w4display("", mes[ME+33], mes[ME+34], " ", mes[MH+16], (char*) 0);
  559.                     prepare_fields(cr);
  560.                     continue;
  561.                     }
  562.                 d4close(db_chistory);
  563.                 db_credit = d4open(&set, files(30));
  564.                 d4tag_select(db_credit, d4tag(db_credit, "CASE_T"));
  565.                 /* If that person is found in a case do not delete the record */
  566.                 if(d4seek(db_credit, f4str(d4field(dbfile, "CODE"))) == 0) {
  567.                     d4close(db_credit);
  568.                     w4display("", mes[ME+33], mes[ME+34], " ", mes[MH+16], (char*) 0);
  569.                     prepare_fields(cr);
  570.                     continue;
  571.                     }
  572.                 d4close(db_credit);
  573.                 }
  574.             if( warning(mes[MH+7])) {
  575.                 for(count=0; count<= surn_len -1; count ++)
  576.                     cr->surnamekey[count] = gtoupper(cr->surname[count]);
  577.                 rec_buffer = (REC *) d4record(dbfile);
  578.                 d4blank(dbfile); /* Set "record changed" flag to true. */
  579.                 memcpy(rec_buffer, cr, sizeof(REC));
  580.                 d4flush_all(dbfile);
  581.                 d4unlock_all_data(dbfile);
  582.                 d4unlock_index(dbfile);
  583.                 break;
  584.                 }
  585.             }
  586.         prepare_fields(cr);
  587.         } /* ==L1==*/
  588.     if(screen_file(screens(13), 19, 78))
  589.         w4exit(1);
  590.     helpline(mes[MH+33]);
  591.     statline(mes[MS+8]);
  592.     }
  593.  
  594.  
  595. /************************************************************************/
  596. /* Delete a record                                                      */
  597. /************************************************************************/
  598. static int delete(dbfile, filter)
  599. D4DATA *dbfile;
  600. X4FILTER filter;
  601. {
  602.     D4DATA*    db_chistory;
  603.     D4DATA*    db_credit;
  604.     D4DATA*    db_kwcasdoc;
  605.  
  606.     /* If that case is found in a chistory or credit DBF do not delete the record */
  607.     db_chistory = d4open(&set, files(27));
  608.     d4tag_select(db_chistory, d4tag(db_chistory, "CASE_T"));
  609.     if(d4seek(db_chistory, f4str(d4field(dbfile, "CODE"))) == 0) {
  610.         d4close(db_chistory);
  611.         w4display("", mes[ME+29], mes[ME+31], " ", mes[MH+16], (char*) 0);
  612.         return(0);
  613.         }
  614.     d4close(db_chistory);
  615.  
  616.     db_credit = d4open(&set, files(30));
  617.     d4tag_select(db_credit, d4tag(db_credit, "CASE_T"));
  618.     if(d4seek(db_credit, f4str(d4field(dbfile, "CODE"))) == 0) {
  619.         d4close(db_credit);
  620.         w4display("", mes[ME+29], mes[ME+31], " ", mes[MH+16], (char*) 0);
  621.         return(0);
  622.         }
  623.     d4close(db_credit);
  624.  
  625.     if(warning(mes[MH+5])) {
  626.         db_kwcasdoc = d4open(&set, files(25));
  627.         d4tag_select(db_kwcasdoc, d4tag(db_kwcasdoc, "CODE_T"));
  628.  
  629.         while(d4seek(db_kwcasdoc, f4str(d4field(dbfile, "CODE"))) == 0) {
  630.             d4delete(db_kwcasdoc);
  631.             d4flush_all(db_kwcasdoc);
  632.             d4unlock_all_data(db_kwcasdoc);
  633.             d4unlock_index(db_kwcasdoc);
  634.             }
  635.         d4close(db_kwcasdoc);
  636.  
  637.         d4delete(dbfile);
  638.         d4flush_all(dbfile);
  639.         d4unlock_all_data(dbfile);
  640.         d4unlock_index(dbfile);
  641.         x4top(&filter);
  642.         d4unlock_index(dbfile);
  643.         }
  644.     }
  645.  
  646. /************************************************************************/
  647. /* Display Relations.                                                   */
  648. /************************************************************************/
  649. static display_relations(db_case)
  650. D4DATA *db_case;
  651. {
  652.     D4DATA *db_group;
  653.     D4DATA *db_court;
  654.     D4DATA *db_cascateg;
  655.     D4DATA *db_procedure;
  656.     D4DATA *db_casstat;
  657.     D4DATA *db_employee;
  658.     D4DATA *db_lawyer;
  659.     D4DATA *db_judge;
  660.  
  661.     db_group    = d4open(&set, files(20) );        /* CASGROUP.DBF */
  662.     db_court    = d4open(&set, files(12) );        /* COURT.DBF     */
  663.     db_cascateg = d4open(&set, files(22) );        /* CASCATEG.DBF */
  664.     db_procedure= d4open(&set, files(24) );      /* PROCED.DBF   */
  665.     d4tag_select(db_group,     d4tag(db_group,      "GROUP_T"));
  666.     d4tag_select(db_cascateg,d4tag(db_cascateg, "CASCATEG_T"));
  667.     d4tag_select(db_procedure,d4tag(db_procedure, "PROCEDURE_T"));
  668.     drel(srow[2],  scol[2]  + 6, db_case, "GROUP",     db_group,    "DESC");
  669.     drel(srow[13], scol[13] + 6, db_case, "COURT",     db_court,    "DESC");
  670.     drel(srow[5],  scol[5]  + 6, db_case, "CASCATEG",  db_cascateg, "DESC");
  671.     drel(srow[16], scol[16] + 6, db_case, "PROCEDURE", db_procedure,"DESC");
  672.     d4close(db_group);        /* CASGROUP.DBF */
  673.     d4close(db_court);        /* COURT.DBF     */
  674.     d4close(db_cascateg);    /* CASCATEG.DBF */
  675.     d4close(db_procedure);  /* PROCED.DBF   */
  676.  
  677.     db_casstat  = d4open(&set, files(21) );        /* CASSTAT.DBF  */
  678.     db_employee = d4open(&set, files(18) );        /* EMPLOYEE.DBF */
  679.     db_lawyer    = d4open(&set, files(14) );        /* O_LAWYER.DBF */
  680.     db_judge        = d4open(&set, files(10) );        /* JUDGE.DBF     */
  681.     d4tag_select(db_casstat, d4tag(db_casstat,  "CASSTAT_T"));
  682.     d4tag_select(db_employee,d4tag(db_employee, "CODE_T"));
  683.     d4tag_select(db_lawyer,  d4tag(db_lawyer,   "CODE_T"));
  684.     d4tag_select(db_judge,   d4tag(db_judge,    "CODE_T"));
  685.     drel(srow[14], scol[14] + 6, db_case, "CASSTAT",   db_casstat,  "DESC");
  686.     drel(srow[9],  scol[9]  + 9, db_case, "EMPLOYEE",  db_employee, "SURNAME");
  687.     drel(srow[11], scol[11] + 9, db_case, "O_LAWYER",  db_lawyer,   "SURNAME");
  688.     drel(srow[12], scol[12] + 9, db_case, "JUDGE",     db_judge,    "SURNAME");
  689.     d4close(db_casstat);        /* CASSTAT.DBF  */
  690.     d4close(db_employee);    /* EMPLOYEE.DBF */
  691.     d4close(db_lawyer);        /* O_LAWYER.DBF */
  692.     d4close(db_judge);        /* JUDGE.DBF     */
  693.     }
  694.  
  695. /************************************************************************/
  696. /* Display Fields                                                       */
  697. /************************************************************************/
  698. static display_fields(cr)
  699. REC *cr;
  700. {
  701.         char    result_ptr[9];    /* Temporary storage of a4format() conversion. */
  702.  
  703.         w4attribute(custom[MAIN_I]);
  704.         w4num(srow[1], scol[1], cr->code,7);
  705.         w4num(srow[2], scol[2], cr->group, 4);
  706.             w4num(srow[2], scol[2] + 6, space(10), 10); /* Clear relation field. */
  707.         w4num(srow[4], scol[4], cr->surname, 20);
  708.         w4num(srow[5], scol[5], cr->cascateg, 4);
  709.             w4num(srow[5], scol[5] + 6, space(20), 20); /* Clear relation field. */
  710.         w4num(srow[16], scol[16], cr->procedure, 4);
  711.             w4num(srow[16], scol[16] + 6, space(30), 30); /* Clear relation field. */
  712.         a4format(cr->startdate, result_ptr, "DD/MM/YY");
  713.             w4num(srow[6], scol[6], result_ptr, 8);
  714.         w4num(srow[7], scol[7], cr->cl_status, 1);
  715.         w4num(srow[8], scol[8], cr->client, 7);
  716.             w4num(srow[8], scol[8] + 9, space(50), 50); /* Clear relation field. */
  717.         w4num(srow[9], scol[9], cr->employee, 7);
  718.             w4num(srow[9], scol[9] + 9, space(20), 20); /* Clear relation field. */
  719.         w4num(srow[10], scol[10], cr->opponent, 7);
  720.             w4num(srow[10], scol[10] + 9, space(50), 50); /* Clear relation field. */
  721.         w4num(srow[11], scol[11], cr->o_lawyer, 7);
  722.             w4num(srow[11], scol[11] + 9, space(20), 20); /* Clear relation field. */
  723.         w4num(srow[12], scol[12], cr->judge, 7);
  724.             w4num(srow[12], scol[12] + 9, space(20), 20); /* Clear relation field. */
  725.         w4num(srow[13], scol[13], cr->court, 4);
  726.             w4num(srow[13], scol[13] + 6, space(40), 40); /* Clear relation field. */
  727.         w4num(srow[14], scol[14], cr->casstat, 4);
  728.             w4num(srow[14], scol[14] + 6, space(20), 20); /* Clear relation field. */
  729.         w4num(srow[15], scol[15], cr->notes1, 50);
  730.         w4num(srow[18], scol[18], cr->notes2, 50);
  731.         w4num(srow[19], scol[19], cr->notes3, 50);
  732.  
  733.         w4attribute(custom[MAIN_N]);
  734. }
  735.  
  736.  
  737. /************************************************************************/
  738. /* Prepare Gets.                                                        */
  739. /************************************************************************/
  740. static prepare_fields(cr)
  741. REC *cr;
  742. {
  743.         w4attribute(custom[MAIN_I]);
  744.         w4num(srow[1], scol[1], cr->code,7);
  745.         w4attribute(custom[MAIN_N]);
  746.  
  747.         g4(srow[2], scol[2], cr->group); g4width(4, 4);
  748.             g4call( gfb_help, 20 );
  749.         g4(srow[4], scol[4], cr->surname); g4width(20,20);
  750.         g4date(srow[6], scol[6], cr->startdate); g4picture("DD/MM/YY");
  751.         g4(srow[5], scol[5], cr->cascateg); g4width(4,4);
  752.             g4call( gfb_help, 22);
  753.         g4(srow[16], scol[16], cr->procedure); g4width(4,4);
  754.             g4call( gfb_help, 24);
  755.         g4(srow[14], scol[14], cr->casstat); g4width(4,4);
  756.             g4call( gfb_help, 21 );
  757.         g4(srow[13], scol[13], cr->court); g4width(4,4);
  758.             g4call( gfb_help, 12);
  759.         g4(srow[7], scol[7], cr->cl_status); g4width(1,1);
  760.             g4call( gcl_status, 0 );
  761.         g4(srow[8], scol[8], cr->client);g4width(7,7);
  762.             g4call( gfmaster_help, 1);
  763.         g4(srow[9], scol[9], cr->employee); g4width(7,7);
  764.             g4call( gfmaster_help, 18);
  765.         g4(srow[10], scol[10], cr->opponent);   g4width(7,7);
  766.             g4call( gfmaster_help, 8);
  767.         g4(srow[11], scol[11], cr->o_lawyer);g4width(7,7);
  768.             g4call( gfmaster_help, 14);
  769.         g4(srow[12], scol[12], cr->judge); g4width(7,7);
  770.             g4call( gfmaster_help, 10);
  771.         g4(srow[15], scol[15], cr->notes1); g4width(50,50);
  772.         g4(srow[18], scol[18], cr->notes2); g4width(50,50);
  773.         g4(srow[19], scol[19], cr->notes3); g4width(50,50);
  774.  
  775. }
  776.  
  777.