home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / tema / 602propc / disk5 / data.5 / WINTIME / APPS / I_SESTAV.PGM < prev    next >
Text File  |  1996-12-03  |  4KB  |  136 lines

  1. Include
  2.  
  3. function Num2atrib(num : short) : string[10];
  4. {************************************************}
  5. begin
  6.   case num of
  7.      1 : Num2atrib := 'cislo ';
  8.      2 : Num2atrib := 'firma ';
  9.      3 : Num2atrib := 'firma2 ';
  10.      4 : Num2atrib := 'jmeno ';
  11.      5 : Num2atrib := 'prijmeni ';
  12.      6 : Num2atrib := 'titul ';
  13.      7 : Num2atrib := 'funkce ';
  14.      8 : Num2atrib := 'muz ';
  15.      9 : Num2atrib := 'mesto ';
  16.     10 : Num2atrib := 'ulice ';
  17.     11 : Num2atrib := 'psc ';
  18.     12 : Num2atrib := 'stat ';
  19.     13 : Num2atrib := 'ico ';
  20.     14 : Num2atrib := 'dic ';
  21.     15 : Num2atrib := 'pozn ';
  22.     16 : Num2atrib := 'prep1 ';
  23.     17 : Num2atrib := 'prep2 ';
  24.     18 : Num2atrib := 'prep3 ';
  25.     19 : Num2atrib := 'prep4 ';
  26.     20 : Num2atrib := 'prep5 ';
  27.     21 : Num2atrib := 'prep6 ';
  28.     22 : Num2atrib := 'prep7 ';
  29.     23 : Num2atrib := 'prep8 ';
  30.   end;
  31. end;
  32.  
  33. function Num2oper(num : short) : string[4];
  34. {************************************************}
  35. begin
  36.   case num of
  37.     1 : Num2oper := '= ';
  38.     2 : Num2oper := '< ';
  39.     3 : Num2oper := '<= ';
  40.     4 : Num2oper := '> ';
  41.     5 : Num2oper := '>= ';
  42.     6 : Num2oper := '<> ';
  43.     7 : Num2oper := '.= ';
  44.     8 : Num2oper := '.=. ';
  45.     9 : Num2oper := '~ ';
  46.   end;
  47. end;
  48.  
  49. function Num2spoj(num : short) : string[5];
  50. {************************************************}
  51. begin
  52.   case num of
  53.     1 : Num2spoj := 'and ';
  54.     2 : Num2spoj := 'or ';
  55.   end;
  56. end;
  57.  
  58. function KolikPodminek : short;
  59. {************************************************}
  60. var
  61.   i : short;
  62.   stop : boolean;
  63. begin
  64.   i := 7;
  65.   stop := false;
  66.   while not stop do begin
  67.     if atr[i] > 0 then stop := true;
  68.     i := i-1;
  69.   end;
  70.   KolikPodminek := i+1;
  71. end;
  72.  
  73. procedure SestavitDotaz;
  74. {************************************************}
  75. var
  76.   pomstr : string[40];
  77.   i,mez : short;
  78. begin
  79.   if (atr[1]=0) and (oper[1]=0) and (hodn[1]='') and (spoj[1]=0) then begin
  80.     if vsechnysk then dotaz := 'SELECT * FROM Tfirma'
  81.     else              dotaz := 'SELECT * FROM Tfirma WHERE skup='+Int2str(skup)
  82.   end
  83.   else begin
  84.     if vsechnysk then  dotaz := ''
  85.       else             dotaz := '(skupina='+Int2str(skup)+') AND ';
  86.     mez := KolikPodminek;
  87.     for i := 1 to mez do begin
  88.       if i = 1 then 
  89.         pomstr := '('+Num2atrib(atr[i])+Num2oper(oper[i])+hodn[i]+') '
  90.       else
  91.         pomstr := Num2spoj(spoj[i-1])+'('+Num2atrib(atr[i])+Num2oper(oper[i])+hodn[i]+') ';
  92.       StrInsert(pomstr, dotaz, StrLength(dotaz)+1);
  93.     end;  
  94.     StrTrim(dotaz);
  95.     if mez>1 then begin
  96.       if vsechnysk then  StrInsert("(", dotaz, 1)
  97.         else             StrInsert("(", dotaz, 17);
  98.       StrInsert(")", dotaz, StrLength(dotaz));
  99.     end;  
  100.     StrInsert('SELECT * FROM Tfirma WHERE ',dotaz,1);
  101.   end;  
  102. end;
  103.  
  104. procedure SestavitDotazKateg;
  105. {************************************************}
  106. var
  107.   spojka : string[4]; 
  108.   len : short;
  109. begin
  110.   if sp = 2 then spojka := " or" else spojka := " and";
  111.  
  112.   if vsechnysk then dotaz := ''
  113.   else              dotaz := '(skupina='+Int2str(skup)+') AND';
  114.   len := StrLength(dotaz);
  115.  
  116.   if p[1] then dotaz := dotaz+spojka+" prep1=true";
  117.   if p[2] then dotaz := dotaz+spojka+" prep2=true";
  118.   if p[3] then dotaz := dotaz+spojka+" prep3=true";
  119.   if p[4] then dotaz := dotaz+spojka+" prep4=true";
  120.   if p[5] then dotaz := dotaz+spojka+" prep5=true";
  121.   if p[6] then dotaz := dotaz+spojka+" prep6=true";
  122.   if p[7] then dotaz := dotaz+spojka+" prep7=true";
  123.   if p[8] then dotaz := dotaz+spojka+" prep8=true";
  124.   
  125.   if len < StrLength(dotaz) then begin
  126.     if Strcopy(dotaz,17,3)="and" then Strdelete(dotaz,17,4);
  127.     if Strcopy(dotaz,17,2)="or" then Strdelete(dotaz,17,3);
  128.     StrInsert("(", dotaz, 17);    
  129.     StrInsert(")", dotaz, StrLength(dotaz)+1); 
  130.     dotaz :='SELECT * FROM Tfirma WHERE"+dotaz;
  131.   end else
  132.     dotaz := 'SELECT * FROM Tfirma WHERE skupina='+Int2str(skup);
  133.   
  134. end;
  135.  
  136.