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

  1. #include "microlib.h"
  2.  
  3. typedef struct {
  4.     char deleted;
  5.     char code[7];
  6.     char name[20];
  7.     char division[20];
  8.     char address[20];
  9.     char zip[20];
  10.     char city[20];
  11.     char country[20];
  12.     char topic[20];
  13.     char supervisor[7];
  14.     char phone1[20];
  15.     char phone2[20];
  16.     char fax[20];
  17.     } REC;
  18.  
  19. T4TAG_INFO  fx_tag[] = {
  20.     {   "CODE_T", "CODE",         ".NOT. DELETED()",  0,     0   },
  21.     {   0, 0, 0, 0, 0 },
  22.     };
  23.  
  24. void update_solchk(void);
  25.  
  26. static display_fields(REC *);
  27. static prepare_fields(REC *);
  28. static int delete(D4DATA *, X4FILTER);
  29. static int edit(D4DATA *, REC *);
  30. static int append(D4DATA *, REC *cr);
  31.  
  32. int input()
  33. {
  34.     REC *cr;
  35.     int case_wref;      /* Window Reference. */
  36.  
  37.     int count, i;           /* Counters. */
  38.  
  39.     int seek_val;           /* Returned Values. */
  40.     int read_val;
  41.     int key_val;
  42.  
  43.     int code_len;           /* Length of frequently used fields ... */
  44.     int surn_len;
  45.  
  46.     char *slash_p;          /* Pointer of slash "/" character in string. */
  47.  
  48.     char tmp_code[8];       /* Temporary storage of CODE field entry (with NULL) */
  49.     char tmp_surname[21];  /* Temporary storage of SURNAMEKEY (with NULL) */
  50.  
  51.     F4FIELD *fields[3];         /* filtering... */
  52.     F4FIELD *field_ptr;
  53.  
  54.     D4DATA *db_organizations;
  55.  
  56.     X4FILTER filter;
  57.     FILTER_INFO_BASIC info;
  58.  
  59.     /* Allocate memory for my record buffer                     */
  60.     if ((cr = (REC *) malloc(sizeof(REC))) == NULL ) {
  61.         w4display(mes[MT], mes[ME+1], (char *) 0);
  62.         w4exit(1);
  63.     }
  64.  
  65.     code_len = sizeof(cr->code);
  66.     surn_len = sizeof(cr->name);
  67.  
  68.     /* Define, activate and clear Data Entry screen.    */
  69.     case_wref = w4define(1, 0, 22, 79);
  70.     w4popup();
  71.     w4memory();
  72.     w4border(SINGLE, custom[MAIN_N]);
  73.     w4title(0, 1, mes[MT+13], custom[MAIN_N]);
  74.     w4attribute(custom[MAIN_N]);
  75.     w4activate(case_wref);
  76.     w4clear(0);
  77.  
  78.  
  79.     /* Load screen from disk and get field coordinates */
  80.     if (screen_file(screens(SCR_ORGANIZATIONS), 19, 78))
  81.         w4exit(1);
  82.     if (get_input_positions(screens(SCR_ORGANIZATIONS)))
  83.         w4exit(1);
  84.  
  85.  
  86.     /* Open Databases and select the proper Tags... */
  87.     db_organizations = d4open(&set, files(DBF_ORGANIZATIONS));
  88.     d4tag_select(db_organizations, d4tag(db_organizations, "CODE_T"));
  89.  
  90.     g4attribute (custom[MAIN_I]);       /* Set input attribute.     */
  91.  
  92.     /* Main append, scan, edit and delete loop.         */
  93.     for(;;) {                                       /* ==L1==   */
  94.  
  95.         /* Blank my record buffer and display it.                   */
  96.         memset(cr, (int) ' ', sizeof(REC));
  97.  
  98.         display_fields(cr);
  99.  
  100.         statline(mes[MS]);
  101.         helpline(mes[MH]);
  102.         g4delimiter("[]");
  103.  
  104.         /* Get code or any other user input.                    */
  105.         read_val =0;
  106.         while (read_val != ESC && read_val != F5 && read_val != RETURN\
  107.                                && read_val != TAB && read_val != F1) {
  108.  
  109.             g4(srow[1], scol[1], cr->code);
  110.             g4picture("U999999");
  111.             read_val = g4read();
  112.         }
  113.  
  114.         /* If Function Keys             */
  115.         if (read_val == ESC)
  116.             break;  /* Out of ==L1==    */
  117.  
  118.         if (read_val == F1) {
  119.             help("CASE_QUERY");
  120.             continue;
  121.         }
  122.  
  123.         if (read_val == F5) {
  124.             append(db_organizations, cr);
  125.             continue;
  126.         }
  127.  
  128.         /* If ENTER was pressed and CODE field is blank...  */
  129.         if (!memcmp(cr->code+1, space(code_len-1),code_len-1)) {
  130.             statline(mes[MS+7]);
  131.             helpline(mes[MH+22]);
  132.             read_val = 0;
  133.             while (read_val !=RETURN && read_val !=ESC && read_val !=TAB ) {
  134.                 g4(srow[2], scol[2], cr->name); g4width(surn_len, surn_len);
  135.                 read_val = g4read();
  136.                 if(read_val == F1)
  137.                     help("CASE_QUERY");
  138.             }
  139.  
  140.             if (!memcmp(cr->name, space(surn_len), surn_len))
  141.                 continue;
  142.  
  143.             memcpy(tmp_surname, cr->name, surn_len);
  144.             tmp_surname[surn_len] = '\0';
  145.  
  146.             if((slash_p= (char *) memchr(tmp_surname, CUT_KEY,surn_len)) !=NULL){
  147.                 *slash_p = ' ';
  148.                 c4trim_n(tmp_surname, surn_len+1);
  149.             }
  150.  
  151.             seek_val = x4seek(&filter, tmp_surname);
  152.             d4unlock_index(db_organizations);
  153.             if (seek_val == r4after || seek_val == r4eof) {
  154.                 w4display("", mes[ME+2], (char *) 0);
  155.                 continue;
  156.             }
  157.             else {  // If found ...
  158.                 //info.field1 = d4field(db_case, "CODE");
  159.                 //info.field2 = d4field(db_case, "SURNAMEKEY");
  160.                 strcpy(info.find_info1, "U");
  161.                 strcpy(info.find_info2, tmp_surname);
  162.                 info.compare_len1 = 1;
  163.                 info.compare_len2 = strlen(info.find_info2);
  164.                 if(info.compare_len2 > f4len(info.field2))
  165.                     info.compare_len2 = f4len(info.field2);
  166.  
  167.                 //x4init(&filter, db_case, filter_basicfiles, &info);
  168.  
  169.                 //if(x4skip(&filter, 1) != 3) {
  170.                 //    x4top(&filter);
  171.                     //d4unlock_index(db_case);
  172.                     //fields[0] = d4field(db_case,"CODE");
  173.                     //fields[1] = d4field(db_case,"SURNAME");
  174.                     //fields[2] = d4field(db_case,"CL_STATUS");
  175.                     //browse(5, 3, 14, mes[MT+3], db_case, filter, fields, 3);
  176.                     }
  177.                 //else
  178.                     //x4top(&filter);
  179.  
  180.                 //d4unlock_index(db_case);
  181.                 // Return to the previous filter.
  182.                 // Show only Clients Companies
  183.                 //info.field1 = d4field(db_case, "CODE");
  184.                 //info.field2 = d4field(db_case, "SURNAMEKEY");
  185.                 strcpy(info.find_info1, "U");
  186.                 info.compare_len1 = 1;
  187.                 info.compare_len2 = 0;
  188.                 //x4init(&filter, db_case, filter_basicfiles, &info);
  189.             } //*==if found==
  190.  
  191.         else {      /* If CODE field is not empty...        */
  192.             // Zerofill and show the entered CODE.
  193.             zerofill(cr->code+1, code_len-1);
  194.             w4attribute(custom[MAIN_I]);
  195.             w4num(srow[1], scol[1], cr->code, code_len);
  196.             w4attribute(custom[MAIN_N]);
  197.  
  198.             /* Copy code and add NULL. */
  199.             memcpy(tmp_code, cr->code, code_len);
  200.             tmp_code[code_len] = '\0';
  201.  
  202.             seek_val = d4seek(db_organizations, (char *)&tmp_code);
  203.  
  204.             d4unlock_index(db_organizations);
  205.             if (seek_val == r4eof || seek_val == r4after) {
  206.                 w4display("", mes[ME+2], (char *) 0);
  207.                 continue; // ==L1==
  208.             }
  209.         }
  210.  
  211.         // If CODE or SURNAMEKEY was found display the record and let the
  212.         // user to skip through the records, edit, delete, change to
  213.         // the second screen or ask for help.
  214.  
  215.         memcpy(cr, (REC *) d4record(db_organizations), sizeof(REC));
  216.  
  217.         helpline(mes[MH+33]);   // Show new available keys.
  218.         statline(mes[MS+8]);
  219.  
  220.         // Clear delimiters from CODE and SURNAME field
  221.         w4num(srow[1], scol[1] -1, space(code_len +2), code_len +2);
  222.         w4num(srow[2], scol[2] -1, space(surn_len +2), surn_len +2);
  223.  
  224.         display_fields(cr); // First time.
  225.  
  226.         for(;;) {   /* ==L2== */
  227.             key_val = g4char();
  228.             if (key_val != PGUP && key_val != PGDN && key_val != ESC &&
  229.                 key_val != F1 && key_val != RETURN &&
  230.                 key_val != F2 && key_val != F3 && key_val != F6 &&
  231.                 key_val != F7 && key_val != F8 && key_val != F4)
  232.                 continue;
  233.  
  234.             if (key_val == PGUP) {
  235.                 if (d4skip(db_organizations, -1L) == r4bof)
  236.                     d4bottom(db_organizations);
  237.             }
  238.  
  239.             if (key_val == PGDN) {
  240.                 if (d4skip(db_organizations, 1L) == r4eof)
  241.                     d4top(db_organizations);
  242.             }
  243.  
  244.             if (key_val == F1) {
  245.                 help("CASE_ROLL");
  246.                 continue;
  247.             }
  248.  
  249.             if (key_val == ESC)
  250.                 break; /* ==L2 ==*/
  251.  
  252.             if (key_val == F2) {
  253.                 edit(db_organizations, cr);
  254.                 display_fields(cr);
  255.             }
  256.  
  257.             if (key_val == RETURN) {
  258.                 display_fields(cr);
  259.             }
  260.  
  261.             if (key_val == F6) {
  262.                 helpline(mes[MH+33]);   /* Show new available keys. */
  263.                 statline(mes[MS+8]);
  264.                 key_val = RETURN;
  265.             }
  266.  
  267.             if (key_val == F7) {
  268.                 helpline(mes[MH+33]);   /* Show new available keys. */
  269.                 statline(mes[MS+8]);
  270.                 continue;
  271.             }
  272.  
  273.             if (key_val == F4) {
  274.                 continue;
  275.             }
  276.  
  277.             if (key_val == F8) {
  278.                 //if (search_code[0] != 'T')
  279.                 //    delete(db_case, filter);
  280.                 //else
  281.                 //    delete(db_case, gl_filter);
  282.             }
  283.  
  284.             //d4unlock_index(db_case);
  285.             memcpy(cr, (REC *) d4record(db_organizations), sizeof(REC));
  286.             if (key_val != RETURN && key_val != F2) {
  287.                 display_fields(cr);
  288.             }
  289.         }   /* ==L2==  */
  290.  
  291.     }           /* ==L1==   */
  292.  
  293.     statline(mes[MS+2]);
  294.     helpline(mes[MH+3]);
  295.     d4close_all(&set);
  296.  
  297.     free(cr);
  298.     w4deactivate(case_wref);
  299.     w4close(case_wref);
  300.     /* Return the menu item to be selected. */
  301.     return (2);
  302. }
  303.  
  304. /************************************************************************/
  305. /* Display Fields                                                       */
  306. /************************************************************************/
  307. static display_fields(cr)
  308. REC *cr;
  309. {
  310.     w4attribute(custom[MAIN_I]);
  311.     w4num(srow[1],  scol[1],  cr->code,       sizeof(cr->code));
  312.     w4num(srow[2],  scol[2],  cr->name,       sizeof(cr->name));
  313.     w4num(srow[3],  scol[3],  cr->division,   sizeof(cr->division));
  314.     w4num(srow[4],  scol[3],  cr->address,    sizeof(cr->address));
  315.     w4num(srow[5],  scol[3],  cr->zip,        sizeof(cr->zip));
  316.     w4num(srow[6],  scol[3],  cr->city,       sizeof(cr->city));
  317.     w4num(srow[7],  scol[3],  cr->country,    sizeof(cr->country));
  318.     w4num(srow[8],  scol[3],  cr->topic,      sizeof(cr->topic));
  319.     w4num(srow[9],  scol[3],  cr->supervisor, sizeof(cr->supervisor));
  320.     w4num(srow[10], scol[10], cr->phone1,     sizeof(cr->phone1));
  321.     w4num(srow[11], scol[11], cr->phone2,     sizeof(cr->phone2));
  322.     w4num(srow[12], scol[12], cr->fax,        sizeof(cr->fax));
  323.  
  324.     w4attribute(custom[MAIN_N]);
  325.  
  326.     return (1);
  327. }
  328.  
  329. /************************************************************************/
  330. /* Prepare Gets.                                                        */
  331. /************************************************************************/
  332. static prepare_fields(cr)
  333. REC *cr;
  334. {
  335.     w4attribute(custom[MAIN_I]);
  336.     w4num(srow[1], scol[1], cr->code, sizeof(cr->code));
  337.     w4attribute(custom[MAIN_N]);
  338.  
  339.     g4(srow[2],  scol[2],  cr->name);       g4width(20,20);
  340.     g4(srow[3],  scol[3],  cr->division);   g4width(20,20);
  341.     g4(srow[4],  scol[3],  cr->address);    g4width(20,20);
  342.     g4(srow[5],  scol[3],  cr->zip);        g4width(20,20);
  343.     g4(srow[6],  scol[3],  cr->city);       g4width(20,20);
  344.     g4(srow[7],  scol[3],  cr->country);    g4width(20,20);
  345.     g4(srow[8],  scol[3],  cr->topic);      g4width(20,20);
  346.     g4(srow[9],  scol[3],  cr->supervisor); g4width(07,07);
  347.     g4(srow[10], scol[10], cr->phone1);     g4width(20,20);
  348.     g4(srow[11], scol[11], cr->phone2);     g4width(20,20);
  349.     g4(srow[12], scol[12], cr->fax);        g4width(20,20);
  350.  
  351.     return (1);
  352. }
  353.  
  354. /************************************************************************/
  355. /* Append a record                                                      */
  356. /************************************************************************/
  357. static int append(dbfile, cr)
  358. D4DATA *dbfile;
  359. REC *cr;
  360. {
  361.     REC *rec_buffer;
  362.     D4DATA *dbcodes;                /* File to get last code.                */
  363.     int count;                      /* Counter.                              */
  364.     int read_val;                   /* Returned value.                       */
  365.  
  366.     char old_code[7];
  367.     char tmp_code[7];               /* Temporary storage of CODE field       */
  368.                                     /* because when I clear my buffer I lose */
  369.                                     /* the next available code.              */
  370.     int code_len;                   /* Length of frequently used fields ...  */
  371.     int surn_len;
  372.     int someone_used_the_code;
  373.  
  374.     someone_used_the_code = FALSE;
  375.     code_len = sizeof(cr->code);
  376.  
  377.     d4tag_select(dbfile , d4tag(dbfile, "CODE_T"));
  378.  
  379.     /* Main Append Loop (where next code number is given etc.). */
  380.     for(;;) {   /* ==L1== */
  381.         /* Read the last code used from CODES file.         */
  382.         dbcodes = d4open(&set, files(5));
  383.         d4tag_select(dbcodes, d4tag(dbcodes, "CODE_T"));
  384.         d4lock_file(dbcodes);
  385.         d4lock_index(dbcodes);
  386.         if( d4seek(dbcodes, "U") != 0 ) {
  387.             d4close_all(&set);
  388.             w4display(mes[MT+1], mes[ME+9], (char *) 0);
  389.             w4exit(1);
  390.         }
  391.         memcpy(cr->code, f4str(d4field(dbcodes, "CODE")), code_len);
  392.         memcpy(old_code, cr->code, code_len);
  393.         old_code[7]='\0';
  394.         d4close(dbcodes);
  395.  
  396.         /*  The character field is converted to numeric ,       */
  397.         /* the value is increased by 1 and then the result      */
  398.         /* is converted again to character.                         */
  399.         /* At the numeric-->character conversion I use a        */
  400.         /* negative length in order to "zerofill" the result. */
  401.         c4ltoa(c4atol(cr->code+1, code_len-1) + 1, cr->code+1, -6);
  402.  
  403.         /* Save the next available code.    */
  404.         memcpy(tmp_code, cr->code, code_len);
  405.         tmp_code[7]='\0';
  406.  
  407.         /* Show next available code, clear buffer, restore the next */
  408.         /* available code. Show the screen file and prepare gets.   */
  409.  
  410.         w4attribute(custom[MAIN_I]);
  411.         w4num(srow[1], scol[1], cr->code, code_len);
  412.         w4attribute(custom[MAIN_N]);
  413.         memset(cr, (int) ' ', sizeof(REC));
  414.         memcpy(cr->code, tmp_code, code_len);
  415.  
  416.         if(get_input_positions(screens(SCR_ORGANIZATIONS)))
  417.             w4exit(1);
  418.         prepare_fields(cr);
  419.  
  420.         /* Entry Loop   */
  421.         /*
  422.         for(;;) {   // ==L2==
  423.             helpline(mes[MH+4]);
  424.             statline(mes[MS+4]);
  425.             read_val = g4read();
  426.  
  427.             if(read_val == ESC) {
  428.                 //if(warning(mes[MH+6])) {
  429.                 //    if(screen_file(screens(SCR_ORGANIZATIONS), 19, 78))
  430.                 //        w4exit(1);
  431.                 //    return(0);
  432.                 //    }
  433.                 }
  434.  
  435.             else if(read_val == F1)
  436.                 help("CASE_APPEND");
  437.  
  438.             else if (read_val == F10) {
  439.                 } //== IF F10 ==
  440.             prepare_fields(cr);
  441.             } // ==L2==
  442.         */
  443.  
  444.         for (;;) {
  445.             helpline(mes[MH+4]);
  446.             statline(mes[MS+4]);
  447.             read_val = g4read();
  448.             switch (read_val) {
  449.                 case ESC :
  450.                     return (1);
  451.                 case F1 :
  452.                     help("CASE_APPEND");
  453.                     break;
  454.                 case F10 :
  455.  
  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, "U") != 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->lname[count] = gtoupper(cr->lname[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(SCR_ORGANIZATIONS), 19, 78))
  502.                         w4exit(1);
  503.                     break;
  504.                 default :
  505.                     prepare_fields(cr);
  506.                     break;
  507.             }
  508.         }
  509.  
  510.     }   /* ==L1== */
  511. }
  512.  
  513.  
  514. /************************************************************************/
  515. /* Edit a record                                                        */
  516. /************************************************************************/
  517. static int edit(dbfile, cr)
  518. D4DATA *dbfile;
  519. REC *cr;
  520. {
  521.     REC *rec_buffer;
  522.     D4DATA *db_chistory;
  523.     D4DATA *db_credit;
  524.  
  525.     int read_val;       /* Returned Value. */
  526.     int count;          /* Counter.          */
  527.     //int surn_len;       /* Length of frequently used field ...  */
  528.  
  529.     //surn_len = sizeof(cr->name);
  530.  
  531.     prepare_fields(cr);
  532.  
  533.     /* Main Edit Loop...                    */
  534.     for(;;) {               /* ==L1==   */
  535.         helpline(mes[MH+4]);
  536.         statline(mes[MS+4]);
  537.  
  538.         read_val = g4read();
  539.         if (read_val == ESC) {
  540.             if(warning(mes[MH+17]))
  541.                 break;
  542.             }
  543.         else if (read_val == F1)
  544.             help("CASE_EDIT");
  545.  
  546.         else if (read_val == F10) {
  547.             /* If client not the same */
  548.             //if (memcmp(tmp_client, cr->client, 7)) {
  549.             //    db_chistory = d4open(&set, files(27));
  550.             //    d4tag_select(db_chistory, d4tag(db_chistory, "CASE_T"));
  551.             //    /* If that person is found in a case do not delete the record */
  552.             //    if(d4seek(db_chistory, f4str(d4field(dbfile, "CODE"))) == 0) {
  553.             //        d4close(db_chistory);
  554.             //        w4display("", mes[ME+33], mes[ME+34], " ", mes[MH+16], (char*) 0);
  555.             //        prepare_fields(cr);
  556.             //        continue;
  557.             //        }
  558.             //    d4close(db_chistory);
  559.             //    db_credit = d4open(&set, files(30));
  560.             //    d4tag_select(db_credit, d4tag(db_credit, "CASE_T"));
  561.             //    /* If that person is found in a case do not delete the record */
  562.             //    if(d4seek(db_credit, f4str(d4field(dbfile, "CODE"))) == 0) {
  563.             //        d4close(db_credit);
  564.             //        w4display("", mes[ME+33], mes[ME+34], " ", mes[MH+16], (char*) 0);
  565.             //        prepare_fields(cr);
  566.             //        continue;
  567.             //        }
  568.             //    d4close(db_credit);
  569.             //    }
  570.             if( warning(mes[MH+7])) {
  571.                 //for (count = 0; count <= surn_len -1; count ++)
  572.                 //    cr->surnamekey[count] = gtoupper(cr->surname[count]);
  573.                 rec_buffer = (REC *) d4record(dbfile);
  574.                 d4blank(dbfile); /* Set "record changed" flag to true. */
  575.                 memcpy(rec_buffer, cr, sizeof(REC));
  576.                 d4flush_all(dbfile);
  577.                 d4unlock_all_data(dbfile);
  578.                 d4unlock_index(dbfile);
  579.                 break;
  580.                 }
  581.             }
  582.  
  583.         prepare_fields(cr);
  584.         } /* ==L1==*/
  585.     //if(screen_file(screens(13), 19, 78))
  586.     //    w4exit(1);
  587.     helpline(mes[MH+33]);
  588.     statline(mes[MS+8]);
  589.  
  590.     return (1);
  591. }
  592.  
  593.  
  594. /************************************************************************/
  595. /* Delete a record                                                      */
  596. /************************************************************************/
  597. static int delete(dbfile, filter)
  598. D4DATA *dbfile;
  599. X4FILTER filter;
  600. {
  601.     D4DATA* db_chistory;
  602.     D4DATA* db_credit;
  603.     D4DATA* db_kwcasdoc;
  604.  
  605.     /* If that case is found in a chistory or credit DBF do not delete the record */
  606.     db_chistory = d4open(&set, files(27));
  607.     d4tag_select(db_chistory, d4tag(db_chistory, "CASE_T"));
  608.     if(d4seek(db_chistory, f4str(d4field(dbfile, "CODE"))) == 0) {
  609.         d4close(db_chistory);
  610.         w4display("", mes[ME+29], mes[ME+31], " ", mes[MH+16], (char*) 0);
  611.         return(0);
  612.     }
  613.     d4close(db_chistory);
  614.  
  615.     db_credit = d4open(&set, files(30));
  616.     d4tag_select(db_credit, d4tag(db_credit, "CASE_T"));
  617.     if(d4seek(db_credit, f4str(d4field(dbfile, "CODE"))) == 0) {
  618.         d4close(db_credit);
  619.         w4display("", mes[ME+29], mes[ME+31], " ", mes[MH+16], (char*) 0);
  620.         return(0);
  621.     }
  622.     d4close(db_credit);
  623.  
  624.     if (warning(mes[MH+5])) {
  625.         db_kwcasdoc = d4open(&set, files(25));
  626.         d4tag_select(db_kwcasdoc, d4tag(db_kwcasdoc, "CODE_T"));
  627.  
  628.         while (d4seek(db_kwcasdoc, f4str(d4field(dbfile, "CODE"))) == 0) {
  629.             d4delete(db_kwcasdoc);
  630.             d4flush_all(db_kwcasdoc);
  631.             d4unlock_all_data(db_kwcasdoc);
  632.             d4unlock_index(db_kwcasdoc);
  633.         }
  634.         d4close(db_kwcasdoc);
  635.  
  636.         d4delete(dbfile);
  637.         d4flush_all(dbfile);
  638.         d4unlock_all_data(dbfile);
  639.         d4unlock_index(dbfile);
  640.         x4top(&filter);
  641.         d4unlock_index(dbfile);
  642.     }
  643.  
  644.     return (1);
  645. }
  646.