home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a014 / 1.ddi / CDBINC.EXE / TJ_Q.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-11  |  11.6 KB  |  379 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. #define black  0x0
  7. #define blue   0x10
  8. #define green  0x20
  9. #define cyan   0x30
  10. #define red    0x40
  11. #define white  0x70
  12.  
  13. #define PgUp 18688
  14. #define PgDn 20736
  15. #define UP   18432
  16. #define DOWN 20480
  17. #define LEFT 19200
  18. #define RIGHT 19712
  19. #define Enter 13
  20. #define Home  18176
  21. #define End   20224
  22. #define ESC   27
  23. #define Del 21248
  24. #define Ins 20992
  25.  
  26. #define  F1    15104
  27. #define  F2    15360
  28. #define  F3    15616
  29. #define  F4    15872
  30. #define  F5    16128
  31. #define  F6    16384
  32. #define  F7    16640
  33. #define  F8    16896
  34. #define  F9    17152
  35. #define  F10   17408
  36.  
  37. typedef struct PPP {              /* this is a database's structure */
  38.     char field[11];
  39.     char type;
  40.     int  length;
  41.     int  dec;
  42.        struct PPP *last;          /* poniter of the last block   */
  43.        struct PPP *next;          /* pointer of the next block   */
  44.     char sele;
  45.     char obj;
  46.     int cla;
  47.      }FIELD;
  48. extern FIELD *p,*p5;
  49.  
  50. typedef struct MM {            /*store base name*/
  51.     char mean[30];
  52.     char dbname[11];     /* the name of the database */
  53.     char mainkey[4][11];      /* mainkey of the database  */
  54.     struct PPP  *sstr;   /* point to the database's structure */
  55.     struct PPP  *estr;/* pointer for end of block of base*/
  56.     char flag;           /*if finish base 0--not finish 1--finish*/
  57.     char serve;
  58.     char path[30];
  59.     char sele;
  60.     int sort;
  61.     char join;
  62.     struct MM *last;
  63.     struct MM *next;
  64.       }BASE ;
  65. extern  BASE  *root,*root3,*root5,*roothead;/* end*/
  66. extern int basecount,selecount,fselecount,linknum,link[5];
  67. extern char linkfield[5][4][11],workname[30],linktype,lan,insert;
  68. extern BASE *root2,*root1,*root4;
  69. extern FIELD *p1,*p2,*p4;
  70. extern int num[6],use;
  71. extern char file[13],*title3[],PATH[30];
  72. extern FIELD *NEXT(),*LAST();
  73. extern FIELD *disp_f(),*disp_ch();
  74. extern int ob,f;
  75. extern char condition[200],*con[6];
  76. extern char class[3][100],classbak[3][11];
  77.  
  78.  tj_q() {
  79.    FILE *fp,*fp1;
  80.    char tail[4], name[13],copyright[60],copyr[13];
  81.    int  i,j,k,key;
  82.    char gsxih[50];
  83. /*-------------------------------MAKE START--------------------------------*/
  84. if(num[4]==0)
  85.      make_file(4);
  86.     if((insert!='Y')&&(insert!='y'))
  87.       r_mean();
  88.    strcpy(file,"tj_q");
  89.    itoa(num[4],tail,10);
  90.    strcat(file,tail); strcpy(copyr,file);
  91.    if((insert=='N')||(insert=='n'))
  92.       w_menuq();
  93. /*-----------------------select object  fields-----------------------------*/
  94.        make_t();
  95.        print(4,30,6|1,"╤í═│╝╞╫╓╢╬");
  96.        root2=root;
  97.        while(root2!=NULL)
  98.       if(root2->sele=='Y') break;
  99.       else root2=root2->next;
  100.       if(root2->sele=='Y')
  101.          {  p=root2->sstr;
  102.         p4=p2=p;
  103.          }
  104.      /*0-all1--n*/
  105.       p1=disp_f(p2,1);
  106.       sele_f(p2,p1,p4,1,0,0);
  107. /*------------select statistics  condition--------------------------------*/
  108.      for(;;) {
  109.     make_t();
  110.     print(4,5,6|1,"╟δ╩Σ╚δ╠⌡╝■▒φ┤∩╩╜");
  111.     root2=root;
  112.     while(root2!=NULL)
  113.         if(root2->sele=='Y')
  114.           break;
  115.         else
  116.         root2=root2->next;
  117.     if(root2->sele=='Y') {
  118.         p=root2->sstr;
  119.         p4=p2=p;     }
  120.     clear_win(5,4,9,76,6,0,black);
  121.     p1=disp_f(p2,0);
  122.     if((sele_f(p2,p1,p4,2,0,0))==1)
  123.            break;
  124.        } /*2--condition*/
  125. /*---------------------------gene  txt base-------------------------------*/
  126.   if(selecount>1) {
  127.     strcpy(name,file);
  128.     strcat(name,".txt");
  129.     if((fp=fopen(name,"w"))==NULL) {
  130.        error("▓╗─▄┤≥┐¬╬─╝■!");
  131.        exit(0);   }
  132.     root2=root;
  133.      while(root2!=NULL)  {
  134.        if(root2->sele=='Y') {
  135.      p2=p=root2->sstr;
  136.      while(p2!=NULL){
  137.         if(p2->sele=='Y')
  138.            if (p2->obj=='Y')
  139.             fprintf(fp,"#%s#,#%c#,19,%d\n",p2->field,p2->type,(p2->dec==0? 0:6));
  140.            else
  141.            fprintf(fp,"#%s#,#%c#,%d,%d\n",p2->field,p2->type,p2->length,p2->dec);
  142.          p2=p2->next; }  }
  143.        root2=root2->next;  }
  144.        fclose(fp);
  145.     }
  146. /*-------------------------gene base--------------------------------------*/
  147.     strcpy(name,file);
  148.     strcat(name,".prg");
  149.     if((fp=fopen(name,"w"))==NULL) {
  150.        error("don't open file!");
  151.        exit(0); }
  152.     fprintf(fp,"set echo off\nset talk off\nset safe off\n");
  153.     if((lan=='Y')||(lan=='y'))
  154.     fprintf(fp,"set excl off\n");
  155.      else
  156.     fprintf(fp, "set excl on\n");
  157.     fprintf(fp,"close all\n");
  158.     if(selecount>1)
  159.      {  fprintf(fp,"sele 10\nuse dbstr excl\nif reccount()>1\n zap\n endif\n");
  160.         strcpy(name,file);
  161.         strcat(name,".txt");
  162.         fprintf(fp,"append from %s deli with #\nuse\n",name);
  163.         fprintf(fp,"creat dbf from dbstr\n");
  164.      }
  165. /*----------------------------selcetion & index-------------------------*/
  166.      root2=root;
  167.      for(j=0;j<selecount;j++) {
  168.         while(root2!=NULL)
  169.            if(root2->sele=='Y') break;
  170.            else root2=root2->next;
  171.         if(root2->join=='Y')
  172.            fprintf(fp,"if .not.file('%s\\%s.dbf')\nclear\n@12,10 say \"╬─╝■╗╣▓╗┤µ╘┌,─·╙ª╧╚╘╦╨╨▒≡╡─│╠╨≥,▓·╔·┤╦┐Γúí\" \nreturn\nendif\n",root2->path,root2->dbname);
  173.       fprintf(fp,"sele %c\nuse %s\\%s ",j+65,root2->path,root2->dbname);
  174.       if(root2->serve!='Y')
  175.         fprintf(fp," excl \n");
  176.       else
  177.            fprintf(fp," \n");
  178.  
  179.    if(j!=0)
  180.           {
  181. /*-----------------------------------lock---------------------------------*/
  182.          if(((lan=='y')||(lan=='Y'))&&(root2->serve=='Y'))
  183.             { fprintf(fp,"do while .T.\ntime=0\ndo while .not.flock().and.time<250\n");
  184.               fprintf(fp,"time=time+1\nenddo\nif time<250\n");
  185.             }
  186. /*-----------------------------endlock------------------------------------*/
  187.          fprintf(fp,"index on");
  188.          for(i=0;i<link[j-1];i++)
  189.              if(i==0)
  190.                fprintf(fp, " %s",linkfield[j-1][i]);
  191.              else
  192.                fprintf(fp,"+%s",linkfield[j-1][i]);
  193.         fprintf(fp," to ndx%-d\n",j-1);/*j-1*/
  194. /*-------------------------unlock----------------------------------------*/
  195.         if(((lan=='y')||(lan=='Y'))&&(root2->serve=='Y'))
  196.                { fprintf(fp,"unlock\nexit\nelse\nyes=' '\nclear\n@12,10 say \"╬─╝■╥╤▒╗╞Σ╦√╙├╗º,╝╠╨°╝╙╦°┬≡ú┐(Y/N)\" get  yes\n");
  197.              fprintf(fp,"read\nclear\nif yes='N'.or.yes='n'\n@15,10 say \"╟δ╣²╥╗╗ß╢∙╘┘╙├\" \nwait\n");
  198.              fprintf(fp,"return\nendif\nendif\nenddo\n");
  199.                }
  200. /*----------------------------end unlock cance---------------------------*/
  201.           }
  202.        root2=root2->next;
  203.        }
  204. /*-------------------------set realtion----------------------------*/
  205.      if((linktype=='C')||(linktype=='c')) {
  206.      for(j=0;j<selecount-1;j++)
  207.          { fprintf(fp,"sele %c\nset relation to ",j+65);
  208.         for(i=0;i<link[j];i++)
  209.              if(i==0)
  210.              fprintf(fp," %s",linkfield[j][i]);
  211.              else
  212.              fprintf(fp,"+%s",linkfield[j][i]);
  213.         fprintf(fp," into %c\n",j+66);
  214.            }
  215.        }
  216.      else
  217.        for(j=0;j<selecount-1;j++)
  218.         {  fprintf(fp,"sele A\nset relation to ");
  219.            for(i=0;i<link[j];i++)
  220.                if(i==0)
  221.                  fprintf(fp, "%s",linkfield[j][i]);
  222.                else
  223.                 fprintf(fp, "+%s",linkfield[j][i]);
  224.            fprintf(fp," into %c\n",j+66);
  225.          }
  226. /*----------------------------end relation-----------------------------*/
  227.     if(selecount>1)
  228.      {  fprintf(fp,"sele 10\nuse dbf excl\nnu=1\nsele a\n");
  229.         fprintf(fp,"do while .T.\n");
  230.         fprintf(fp,"go nu\nsele 10\nappen blank\nrepl ");
  231.         root2=root;
  232.         while(root2!=NULL)
  233.          { if(root2->dbname[0]=='\0')
  234.              root2->sele='N';
  235.            root2=root2->next;
  236.          }
  237.         root2=root;
  238.        j=k=0;
  239.         while(root2!=NULL)
  240.          { if(root2->sele=='Y')
  241.              { p2=p=root2->sstr;
  242.                while(p2!=NULL)
  243.                 { if(p2->sele=='Y')
  244.                        {  if(k<5)
  245.                           {  fprintf(fp," %s with %c->%s ",p2->field,j+65,p2->field);
  246.                          k++;
  247.                            }
  248.                       else
  249.                            { fprintf(fp,"\nrepl ");
  250.                          fprintf(fp," %s with %c->%s ",p2->field,j+65,p2->field);
  251.                          k=1;
  252.                         }
  253.                      }
  254.                      p2=p2->next;
  255.                  }
  256.                  j++;
  257.                }
  258.             root2=root2->next;
  259.          }
  260.          fprintf(fp,"\nnu=nu+1\nsele 1\nif nu>reccount()\nexit\nendif\nenddo\nsele 10\n");
  261.        }
  262.   else
  263.     fprintf(fp,"copy to dbf.dbf\n");
  264.  
  265. /*-------------------end of gene base ------------------------------------*/
  266. /*-----------------tatistics_class-field----------------------------------*/
  267.        make_t();
  268.        print(4,30,6|1,"╤í╖╓└α╫╓╢╬");
  269.        root2=root;
  270.       while(root2!=NULL)
  271.      if(root2->sele=='Y') break;
  272.      else root2=root2->next;
  273.      if(root2->sele=='Y') {
  274.        p=root2->sstr;
  275.        p4=p2=p;    }
  276.       p1=disp_ch(p2);
  277.       sele_ch(p2,p1,p4,1);
  278. /*-----------------------statistics_class--end-----------------------------*/
  279.    strcpy(name,file);
  280.     strcat(name,"j.txt");
  281.     if((fp1=fopen(name,"w"))==NULL) {
  282.       error("▓╗─▄┤≥┐¬╬─╝■%s",name);
  283.       exit(0);    }
  284.     else {
  285.       root2=root;
  286.      while(root2!=NULL)  {
  287.        if(root2->sele=='Y') {
  288.      p2=p=root2->sstr;
  289.      while(p2!=NULL){
  290.        if(p2->obj=='Y')
  291.            fprintf(fp1,"#%s#,#%c#,%d,%d\n",p2->field,p2->type,19,(p2->dec==0? 0:6));
  292.        if(p2->cla!=0)
  293.            fprintf(fp1,"#%s#,#%c#,%d,%d\n",p2->field,p2->type,p2->length,p2->dec);
  294.        p2=p2->next; }  }
  295.        root2=root2->next;  }
  296.        fclose(fp1);   }
  297. /*---------------------gene jg base ---------------------------------------*/
  298.      strcpy(name,file);
  299.      strcat(name,".dbf");
  300.      fprintf(fp,"\nclose all \nrun copy c:dbf.dbf c:base_jg.dbf >zl\n");
  301.      fprintf(fp,"sele 1\nuse base_jg excl\n");
  302.      fprintf(fp,"index on ");
  303.      fprintf(fp," %s ",class[0]);
  304.      fprintf(fp,"to qundx0\nset index to qundx0\n");
  305.      fprintf(fp,"\ngo top\ntotal on ");
  306.      fprintf(fp," %s ",class[0]);
  307.      fprintf(fp,"to %sj.dbf fields",file);
  308.      i=0;
  309.      root2=root;
  310.      while(root2!=NULL) {
  311.        if(root2->sele=='Y') {
  312.        p2=root2->sstr;
  313.        while(p2!=NULL) {
  314.            if(p2->obj=='Y') {
  315.            if(i==0)
  316.             fprintf(fp," %s",p2->field);
  317.            else
  318.             fprintf(fp," ,%s",p2->field);
  319.             i++;      }
  320.         p2=p2->next; }     }
  321.  
  322.          root2=root2->next;    }
  323.  
  324.        fprintf(fp," for %s \n",condition);
  325.        fprintf(fp,"!del c:qundx?.?dx >zl\n");
  326.        fprintf(fp,"!del c:base_jg.dbf >zl\n");
  327.        fprintf(fp,"! c:brow c:%sj.dbf\n",file);
  328. /*-----------gene----------------end--------------------------------------*/
  329.      clear_win(5,4,9,76,6,0,black);
  330.      print(7,10,6|1,"╥¬╢╘┤╦═│╝╞╜ß╣√┐Γ╜°╨╨═│╝╞┬≡ú┐(Y/N)");
  331.      key=getcc();
  332.      root5=NULL;
  333.      if((key=='Y')||(key=='y'))
  334.     { read_key();
  335.       strcpy(root3->path,PATH);
  336.       strcpy(copyright,"copy "); strcat(copyright,copyr);
  337.       strcat(copyright,"j.txt "); strcat(copyright,root3->path);
  338.       strcat(copyright,"\\");
  339.       strcat(copyright,root3->dbname); strcat(copyright,".txt");
  340.           system(copyright);
  341.       fprintf(fp,"!copy c:%sj.dbf %s\\%s.dbf >zl\n",file,root3->path,root3->dbname);
  342.       root3->serve='N';
  343.       root3->join='Y';
  344.       roothead->last=root3;
  345.           root3->next=roothead;
  346.       roothead=root3;
  347.       roothead->sstr=NULL; roothead->estr=NULL;
  348.       fprintf(fp,"! c:brow.exe c:%sj.dbf \n",file);
  349.      }
  350.     fprintf(fp,"clear\n");
  351.     fprintf(fp,"ser=' '\n@ 10,10 say \"┤╦═│╝╞╜ß╣√╥¬▒╕╖▌┬≡ú┐(Y/N)\"  get ser\nread\n");
  352.     fprintf(fp,"if ser='Y'.or.ser='y'\n ser=space(30)\n@12,10 say \"╟δ╩Σ╚δ─┐┬╝╝░╬─╝■├√│╞:\"  get ser\nread\n");
  353.     fprintf(fp,"!copy c:%s  &ser > zl\nendif\n",file);
  354.     fprintf(fp,"!del c:dbf.dbf >zl\n");
  355.     clear_win(13,4,20,75,6,0,black);
  356.     printf("\033[17;20H┤╦═│╝╞╜ß╣√╥¬╣▓╧φ┬≡ú┐(Y/N)");
  357.     k=getcc();
  358.     if((k=='Y')||(k=='y'))
  359.      { print(19,10,6|1,"╩Σ╚δ╣▓╧φ─┐┬╝╝░╬─╝■├√:  ");
  360.        scanf("%s",gsxih);
  361.        fprintf(fp,"!copy c:%sj.dbf %s >zl",file,gsxih);
  362.      }
  363.    fclose(fp);
  364.    num[4]++;
  365.    }/*end*/
  366.  
  367. /*--------------------------WRITE STATIS.TXT------------------------------------*/
  368.  
  369.   w_menuq() {
  370.   FILE *fp;
  371.      if((fp=fopen("statis4.txt","a"))==NULL) {
  372.      error("don't open file statis.txt");
  373.       exit(1); }
  374.    fprintf(fp,"#%s#,#%s#\n",workname,file);
  375.     fclose(fp); }
  376.  
  377. /*--------------------------------END ALL ----------------------------------------*/
  378.  
  379.