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

  1. // verze pro 32bitovou WinBase602 4.0  (jin² I_deklar)
  2.  
  3. // 1) oprava ve fci DoplnJmeno v p°φpad∞ jmen Üablon < 8 znak∙
  4. // 2) na zaΦßtku se zeptß na skupinu
  5. // 3) oprava v SELECTU p°i exportu v TDT
  6. // 4) volit. varianta pro OEM
  7.  
  8. {******************************************************************}
  9. {*****      aplikace Adresß° firem v. 3.32.05     15.5.1996   *****}
  10. {******************************************************************}
  11.  
  12. {$I I_deklar}  //32
  13. {$I I_sestavd}
  14. {$I I_expimp}
  15. {$I I_udrzba}
  16. {$I I_kontakty}
  17. {$I I_tisk}
  18. {$I I_mailmerg}
  19. {$I I_prava}
  20.  
  21. procedure Synchronizace(vzor,cil : window_id);
  22. {**************************************}
  23. var 
  24.   irec,erec,cilnum : integer;
  25.   curvzor,curcil : cursor;
  26.   fl : short;
  27.   s1,s2 : string[20];
  28. begin
  29.   if Get_view_pos(vzor, irec, erec) then
  30.     if Get_fcursor(vzor, curvzor, fl) then
  31.       if Get_fcursor(cil, curcil, fl) then  
  32.         if not Super_recnum(curvzor, curcil, erec, cilnum) then begin
  33.           Set_ext_pos(cil, cilnum, -1);
  34.           Pick_window(cil);
  35.         end;  
  36. end;
  37.  
  38. procedure Prepnuti;
  39. {**************************************}
  40. {synchronizace aktußlnφch zßznam∙ pohledu Pfirma a Pseznam, tlaΦφtko F6}
  41. begin
  42.   if (Active_view = id_sez) then begin                // v pohledu Pseznam  
  43.     if (id = 0) then begin
  44.       Open_view('*Pfirma',curmain,0,0,0,id);        
  45.       SetWindowText(id,s2);
  46.     end;
  47.     Synchronizace(id_sez,id)
  48.   end  else
  49.   if (Active_view = id) then begin                    // v pohledu Pfirma
  50.     if (id_sez = 0) then begin
  51.       Open_view('*Pseznam',curmain,0,0,0,id_sez);        
  52.       SetWindowText(id_sez,s4);
  53.     end;
  54.     Synchronizace(id,id_sez);
  55.   end  
  56. end;
  57.  
  58. procedure UplatnitDotaz;
  59. {**************************************}
  60. {definice dotazu v prom. dotaz se pou₧ije pro kurzor curmain}
  61. var
  62.   pocetx : integer;
  63.   pomshort : short;
  64. begin
  65.     if id > 0 then Send_message(id,1599,0,0);         // odstran∞nφ p°φpadnΘho QBE dotazu
  66.     if id_sez > 0 then Send_message(id_sez,1599,0,0);
  67.     if not Close_cursor(curmain) then             // zav°φt star² kurzor
  68.       if not Open_sql_cursor(curmain,dotaz) then  // otev°φt ho s novou definicφ  TADY
  69.       begin
  70.         if id>0 then begin
  71.           Set_fcursor(id,curmain,-1);              // je-li pohled otev°en, vnutit mu nov² kurzor
  72.         end; 
  73.         if id_sez>0 then begin
  74.           Set_fcursor(id_sez,curmain,-1);
  75.         end;  
  76.         Err_mask(true);                           // aby nßsledujφcφ mo₧nß chyba neskonΦila program..
  77.         pomshort := curmain[0].cislo;             // rychlΘ zjiÜt∞nφ, mß-li kurzor alespo≥ jeden zßznam
  78.         if Sz_error = 131 then Info_box("Nelze","Podmφnce nevyhovuje ₧ßdn² zßznam !");    // chyba Zßznam mimo tabulku
  79.         Err_mask(false);
  80.       end else Signalize;
  81. end;
  82.   
  83. procedure VyberSkupinu;
  84. {**************************************}
  85. var
  86.   id_vs : window_id;
  87. begin
  88.   zrusitAkci := true;
  89.   vybrat := true;
  90.   Open_view('*Vyberskup',no_redir,0,0,0,id_vs);
  91.   repeat Peek_message until id_vs=0;
  92.   
  93.   if not zrusitAkci then begin
  94.     if vsechnysk then begin
  95.       s2 := 'VÜechny skupiny';
  96.       s4 := 'P°ehled firem vÜech skupin';
  97.       dotaz := 'SELECT * FROM Tfirma';
  98.     end 
  99.     else begin
  100.       nazskup := Skupiny[skup].nazev;
  101.       s2 := 'Skupina: '+nazskup;
  102.       s4 := 'P°ehled firem skupiny: '+nazskup;
  103.       dotaz := 'SELECT * FROM Tfirma WHERE skupina='+Int2str(skup);
  104.     end;
  105.     UplatnitDotaz;
  106.     DoplnitTexty;
  107.     if id > 0 then begin
  108.       SetWindowText(id,s2);
  109.       Reset_view(id,-1,reset_controls);
  110.     end;  
  111.     if id_sez > 0 then begin
  112.       SetWindowText(id_sez,s4);
  113.       Reset_view(id,-1,reset_controls);
  114.     end;
  115.   end;
  116. end;
  117.  
  118. procedure Kopie;
  119. {**************************************}
  120. {Vytvo°enφ kopie aktußlnφho zßznamu, p°enßÜejφ se ·daje o firm∞, nikoliv 
  121. personßlnφ ·daje}
  122. type
  123.   mult = array[1..10] of string[20];
  124. var
  125.   i : short;
  126.   rr,reci,rece : integer;
  127.   sk : short;
  128.   fir,fir2,ulic,mest : string[50];
  129.   ps : string[6]; st : string[30];
  130.   dc : string[13]; ic : string[8];
  131.   p1,p2,p3,p4,p5,p6,p7,p8 : boolean;
  132.   tel,faxx : mult;
  133.   maill : array[1..5] of string[30];
  134.   bank : array[1..5] of string[50];
  135.   cf : cursor;
  136.   pom,cisloZaznamu : integer;
  137.   cislox,pomcislok : integer;
  138.   idkop : window_id;
  139. begin
  140.   Send_message(id_sez,1599,0,0);          
  141.   Send_message(id,1599,0,0);              // odznaΦenφ p°φp. QBE dotazu 
  142.   if Active_view = id_sez then Prepnuti;  // p°epnutφ do pohledu Pfirma
  143.   
  144.   if Get_view_pos(id,reci,rece) then begin  // zjiÜt∞nφ Φφsla kopφrovanΘho zßznamu
  145.     Get_fcursor(id,cf,nil);
  146.     pomcislok := cf;
  147.     Translate(cf,rece,0,cisloZaznamu);      // p°epoΦet na Φφslo zßznamu v tabulce, abych se nemusel starat o beztypovy kurzor cf
  148.     Set_cursor(1);
  149.     with Tfirma[cisloZaznamu] do begin      // naΦtenφ ·daj∙ do prom∞nn²ch
  150.       sk := skupina;
  151.       fir := firma;
  152.       fir2 := firma2;
  153.       ulic := ulice;
  154.       mest := mesto; 
  155.       ps := psc;
  156.       st := stat;
  157.       ic := ico;
  158.       dc := dic;
  159.       p1 := prep1; p2 := prep2; p3 := prep3;  
  160.       p4 := prep4; p5 := prep5; p6 := prep6;
  161.       p7 := prep7; p8 := prep8;
  162.       for i := 1 to 10 do
  163.         tel[i] := telefon[i-1];
  164.       for i := 1 to 10 do
  165.         faxx[i] := fax[i-1];
  166.       for i := 1 to 10 do
  167.         maill[i] := mail[i-1];
  168.       for i := 1 to 10 do
  169.         bank[i] := banka[i-1];
  170.     end; 
  171.     rr := Insert(cf);                   // vlo₧enφ novΘho zßznamu do kurzoru
  172.     if rr <> -1 then begin
  173.         cf[rr].skupina := sk;           // zapsßnφ ·daj∙ z prom∞nn²ch - beztypovΘ p°i°azenφ
  174.         cf[rr].muz := true;  
  175.         cf[rr].firma := fir;
  176.         cf[rr].firma2 := fir2;
  177.         cf[rr].ulice := ulic;
  178.         cf[rr].mesto := mest; 
  179.         cf[rr].psc := ps;
  180.         cf[rr].stat := st;
  181.         cf[rr].ico := ic;
  182.         cf[rr].dic := dc;
  183.         cf[rr].prep1 := p1;  
  184.         cf[rr].prep2 := p2; 
  185.         cf[rr].prep3 := p3;  
  186.         cf[rr].prep4 := p4;  
  187.         cf[rr].prep5 := p5; 
  188.         cf[rr].prep6 := p6;
  189.         cf[rr].prep7 := p7;  
  190.         cf[rr].prep8 := p8;
  191.         for i := 1 to 10 do
  192.           if tel[i] <> "" then cf[rr].telefon[i-1] := tel[i];
  193.         for i := 1 to 10 do
  194.           if faxx[i] <> "" then cf[rr].fax[i-1] := faxx[i];
  195.         for i := 1 to 10 do
  196.           if maill[i] <> "" then cf[rr].mail[i-1] := maill[i];
  197.         for i := 1 to 10 do
  198.           if bank[i] <> "" then cf[rr].banka[i-1] := bank[i];
  199.  
  200.         Reset_view(id,-1,reset_cache+reset_controls);
  201.         Set_ext_pos(id,rr,-1)  ;  // nastavenφ pohledu na nov² zßznam
  202.         PosledniCislo;
  203.     end else Info_box("Nelze","Nelze vlo₧it nov² zßznam");
  204.   end;  
  205.   Set_cursor(0);
  206. end;
  207.  
  208. procedure Vlozeni;
  209. {**************************************}
  210. {vlo₧enφ novΘho zßznamu klßvesou Ins}
  211. var
  212.   cx : cursor;
  213.   rer : integer;
  214. begin
  215.   if vsechnysk then Info_box('Nelze','Pro vlo₧enφ musφte mφt vybrßnu jednu konkrΘtnφ skupinu!')
  216.   else begin
  217.     Set_cursor(1);
  218.     if id_sez>0 then Close_view(id_sez);          
  219.     if id = 0 then begin
  220.       Open_view('*Pfirma',curmain,0,0,0,id);
  221.       SetWindowText(id,s2);
  222.     end else begin
  223.       Pick_window(id);
  224.       Send_message(id,1599,0,0);              // odznaΦenφ p°φp. QBE dotazu 
  225.     end;  
  226.     Get_fcursor(id,cx,nil);
  227.     rer := Insert(cx);                        // vlo₧it zßznam
  228.     if rer <> -1 then begin                   
  229.       cx[rer].skupina := skup;                // zapsat skupinu
  230.       Set_ext_pos(id,rer,-1);                 // pozice novΘho zßznamu
  231.       PosledniCislo;                          // zapsat Φφslo zßznamu
  232.     end;
  233.     if id_sez>0 then 
  234. //       Reset_view(id_sez,-1,RESET_CACHE+RESET_CONTROLS);
  235.     Set_cursor(0);
  236.   end;
  237. end;
  238.  
  239. procedure Smazani;
  240. {**************************************}
  241. {smazßnφ zßznamu klßvesou Ctrl+Del}
  242. var
  243.   ic,ec : integer;
  244.   ct,cx : cursor;
  245.   sqldel : string[40]; 
  246.   cis : short;
  247.   pocett : integer;
  248.   spom : string[60];
  249. begin
  250.   if Active_view = id_sez then Prepnuti;      // otev°enφ Pfirma na stejnΘm zßznamu
  251.   if Get_fcursor(id,cx,nil) then
  252.     if Get_view_pos(id,ic,ec) then begin
  253.       cis := cx[ec].cislo;
  254.       if cis = noneshort then Send_message(id,1603,0,0)
  255.       else begin
  256.         spom := 'SELECT * FROM Tschuzky WHERE cislo='+Int2str(cis);
  257.         if not Open_sql_cursor(ct,spom) then begin
  258.           if not Rec_cnt(ct,pocett) then begin 
  259.             if pocett = 0 then begin                     // nejsou kontakty
  260.               Send_message(id,1603,0,0);                 // smazat
  261.             end
  262.             else begin
  263.               if YesNo_box('Varovßnφ','Adresu nelze smazat, proto₧e v tabulce kontakt∙ existujφ odpovφdajφcφ zßpisy.'#10'Majφ se smazat zßpisy v tabulce kontakt∙ souΦasn∞?') then
  264.               begin
  265.                 if not Delete_all_records(ct) then begin
  266.                   Send_message(id,1603,0,0); 
  267.                 end else Info_box('Cbyba','Nezda°ilo se');
  268.               end;
  269.             end;
  270.           end else Signalize;
  271.           Close_cursor(ct);
  272.         end else Signalize;
  273.       end;
  274.     end;  
  275. end;  
  276.  
  277. function VymazatZKontaktu(cis : integer) : boolean;
  278. {**************************************}
  279. var
  280.   spom : string[60];
  281.   ct : cursor;
  282.  
  283. begin
  284.   VymazatZKontaktu := false;
  285.   spom := 'SELECT * FROM Tschuzky WHERE cislo='+Int2str(cis);
  286.   if not Open_sql_cursor(ct,spom) then begin
  287.     if Delete_all_records(ct) then Signalize else VymazatZKontaktu := true;
  288.     Close_cursor(ct);
  289.   end else Signalize;
  290. end;
  291.  
  292. procedure SmazatVsechnyZaznamy;
  293. {**************************************}
  294. var
  295.   zam : boolean;
  296.   sp : string[200];
  297.   cpom : cursor;
  298.   spom : string[100];
  299.   i,pocetpom : integer;
  300.   
  301. begin
  302.   zam := false;
  303. //  if myName <> 'DB_ADMIN' then Info_box('Nelze','  Smazat vÜechna data m∙₧e provΘst pouze sprßvce databßze!')
  304. //  else begin
  305.     if vsechnysk then sp := 'Opravdu chcete vymazat z Adresß°e vÜechny firmy'#10'vÜech skupin a zßznamy o kontaktech s nimi?'
  306.     else sp := 'Opravdu chcete vymazat z Adresß°e vÜechny firmy'#10'skupiny > '+nazskup+' < a zßznamy o kontaktech s nimi?';
  307.     if YesNo_box('Varovßnφ',sp) then begin
  308.       if id > 0 then Close_view(id);
  309.       if id_sez > 0 then Close_view(id_sez);
  310.       if Close_cursor(curmain) then Signalize;
  311.  
  312.       if not (Write_lock_table(Tfirma) or Write_lock_table(Tschuzky)) then begin
  313.         if vsechnysk then spom := 'SELECT * FROM Tfirma'
  314.         else spom := 'SELECT * FROM Tfirma WHERE skupina='+Int2str(skup);
  315.         if not Open_sql_cursor(cpom, spom) then begin
  316.           Rec_cnt(cpom, pocetpom);
  317.           if pocetpom > 0 then
  318.             for i := 0 to pocetpom-1 do begin
  319.               Set_status_nums(i,pocetpom-1);
  320.               if VymazatZKontaktu(cpom[i].cislo) then
  321.                 if Delete(cpom,i) then Signalize;
  322.             end;
  323.           Close_cursor(cpom);
  324.         end else Signalize;
  325.         Free_deleted(Tfirma); Free_deleted(Tschuzky);
  326.         Write_unlock_table(Tfirma); Write_unlock_table(Tschuzky);
  327.         VyberSkupinu;
  328.         if Open_sql_cursor(curmain,dotaz) then Signalize     // v glob. prom. dotaz je ulo₧ena definice dotazu z proc VyberSkupinu
  329.         else begin
  330.           Open_view('*Pfirma',curmain,0,0,0,id);
  331.           SetWindowText(id,s2);
  332.         end;  
  333.       end else begin
  334.         Info_box('Nelze zamknout','S tabulkami n∞kdo pracuje.');
  335.         zam := true;
  336.       end;  
  337.     end;
  338. //  end;
  339. end;
  340.  
  341. procedure ZmenitSkupinuZaznamu;
  342. {**************************************}
  343. var
  344.   id_zs : window_id;
  345.   cx,cy : cursor;
  346.   ic,ec : integer;
  347.   res : integer;
  348.   pocetzaz,i : integer;
  349.   cis : short;
  350.   u : untyped;
  351.  
  352. begin
  353.   if vsechnysk then Info_box('Nelze','Pro tuto operaci musφte mφt vybrßnu jednu konkrΘtnφ skupinu!')
  354.   else begin
  355.     zrusitAkci := true;
  356.     jeden := 1;
  357.     Open_view('*UrciSkup',no_redir,modal_view,0,0,id_zs);
  358.     repeat Peek_message until id_zs = 0;
  359.     SmazatFrontu;
  360.     if not zrusitAkci then begin
  361.       vsechnysk := false;
  362.       nazskup := Skupiny[skup].nazev;
  363.       s2 := 'Skupina: '+nazskup;
  364.       s4 := 'P°ehled firem skupiny: '+nazskup;
  365.   
  366.       if Get_fcursor(Active_view,cx,nil) then begin
  367.  
  368.         if jeden = 1 then begin               // zm∞na u jednoho zßznamu
  369.           if Active_view = id_sez then Prepnuti;
  370.           if (Get_view_item(id,54) = '') then PosledniCislo;
  371.  
  372.           Get_view_pos(id,ic,ec);
  373.           cis := cx[ec].cislo;
  374.           Start_transaction;
  375.           cx[ec].skupina := skup;
  376.           cx[ec].prep1 := false;
  377.           cx[ec].prep2 := false;
  378.           cx[ec].prep3 := false;
  379.           cx[ec].prep4 := false;
  380.           cx[ec].prep5 := false;
  381.           cx[ec].prep6 := false;
  382.           cx[ec].prep7 := false;
  383.           cx[ec].prep8 := false;
  384.           Commit;
  385.           dotaz := 'SELECT * FROM Tfirma where skupina='+Int2str(skup);
  386.           UplatnitDotaz;
  387.           DoplnitTexty;
  388.           u := cis;
  389.           res := Look_up(curmain,'cislo',u);              // zjiÜt∞nφ zßznamu s Φφslem cis
  390.           if res <> -1 then Set_ext_pos(id,res,-1);
  391.           SetWindowText(id,s2);
  392.           Reset_view(id,-1,reset_cache+reset_controls);
  393.           if id_sez>0 then SetWindowText(id_sez,s4);
  394.         end else begin                    // zm∞na u vÜech sejmut²ch zßznam∙
  395.           Rec_cnt(cx,pocetzaz);
  396.           if pocetzaz <> -1 then begin
  397.             for i := 0 to pocetzaz-1 do begin
  398.               Set_status_nums(i+1,pocetzaz);
  399.               Start_transaction;
  400.               cx[i].skupina := skup;
  401.               cx[i].prep1 := false;
  402.               cx[i].prep2 := false;
  403.               cx[i].prep3 := false;
  404.               cx[i].prep4 := false;
  405.               cx[i].prep5 := false;
  406.               cx[i].prep6 := false;
  407.               cx[i].prep7 := false;
  408.               cx[i].prep8 := false;
  409.               Commit;
  410.             end;
  411.             dotaz := 'SELECT * FROM Tfirma where skupina='+Int2str(skup);
  412.             UplatnitDotaz;
  413.             DoplnitTexty;
  414.             SetWindowText(id,s2);
  415.             Reset_view(id,-1,reset_cache+reset_controls);
  416.             if id_sez>0 then SetWindowText(id_sez,s4);
  417.             
  418.           end;
  419.         end;
  420.       end else Info_box('Chyba','Get_fcursor');
  421.     end;
  422.   end;
  423. end;
  424.  
  425. procedure Najit;
  426. {**************************************}
  427. {vyhledß zßznamy, kterΘ v sob∞ obsahujφ zadan² °et∞zec}
  428. var  
  429.   id_f,id_zal,id_vyb : window_id;
  430.   wherestr : string[200];
  431.   costr : string[30];
  432.   sel : string[300];
  433.   pstr : string[30];
  434. begin
  435.   column := 1;
  436.   zrusitAkci := true;
  437.   Open_view('*Pfind',no_redir,modal_view,0,0,id_f);  
  438.   repeat Peek_message until id_f=0;
  439.   SmazatFrontu;
  440.  
  441.   if not zrusitAkci then begin
  442.     pstr := " .=."""+search+"""";
  443.     case column of
  444.       1 : begin
  445.         wherestr := 'firma'+pstr+' OR firma2'+pstr+' OR prijmeni'+pstr+' OR ulice'+pstr+' OR mesto'+pstr+' OR pozn'+pstr ;
  446.         costr := '';
  447.         end;
  448.       3 : begin
  449.         wherestr := 'firma'+pstr+' OR firma2'+pstr;
  450.         costr := 'v nßzvu firmy ';
  451.         end;
  452.       2 : begin
  453.         wherestr := 'prijmeni'+pstr;
  454.         costr := 've jmΘnu odp. pracovnφka ';
  455.         end;
  456.       4 : begin
  457.         wherestr := 'ulice'+pstr+' OR mesto'+pstr;
  458.         costr := 'v adrese firmy ';
  459.         end;
  460.       5 : begin
  461.         wherestr := 'pozn'+pstr;
  462.         costr := 'v poznßmce ';
  463.         end;
  464.     end; 
  465.  
  466.     sel :='SELECT * FROM Tfirma WHERE '+wherestr;
  467.     if Open_sql_cursor(cfind,sel) then Signalize;
  468.     if Rec_cnt(cfind,pocetNalez) then Signalize;    // pro podmφnku aktivity v pohledu Pvybrsuper
  469.  
  470.     s := 'V tabulce firem byly nalezeny tyto zßznamy obsahujφcφ '+costr+'°et∞zec '''+search+'''. TlaΦφtkem Firma si zobrazφte podrobn² popis vybranΘ firmy.';
  471.     Open_view('*pvybrsuper',no_redir,0,0,0,id_vyb);
  472.     id_subvyb := GetDlgItem(id_vyb,3);
  473.     if not Set_fcursor(id_subvyb,cfind,0) then Info_box('Chyba','Set_fcursor');
  474. //    vsechnysk := true;
  475.   end;
  476. end;
  477.  
  478. procedure ZavritKurzor;
  479. {**************************************}
  480. //akce po zav°enφ pohledu Pvybrsuper
  481. begin
  482.   Close_cursor(cfind);
  483. end;
  484.  
  485. procedure Prepni;
  486. {**************************************}
  487. {tlaΦφtko v pohledu Pvybrsuper s vybran²mi zßznamy - p°epne do formulß°e na stejn² zßznam}
  488. begin
  489.   dotaz := 'SELECT * FROM Tfirma';
  490.   vsechnysk := true;
  491.   s2 := 'VÜechny skupiny';
  492.   s4 := 'P°ehled firem vÜech skupin';
  493.   UplatnitDotaz;
  494.   DoplnitTexty;
  495.   if id=0 then begin 
  496.     Open_view('*pfirma',curmain,0,0,0,id);
  497.     SetWindowText(id,s2);
  498.   end;  
  499.   Synchronizace(id_subvyb,id);
  500.   if id_sez > 0 then SetWindowText(id_sez,s4);
  501. end;
  502.  
  503.  
  504. function TestDotazu(odkud : short; dot : string[255]) : boolean;
  505. {************************************************}
  506. //odkud = 1 : nezobrazovat info o spravne syntaxi
  507. //odkud = 0 : zobrazovat
  508. var
  509.   c_test : cursor;
  510. begin
  511.   if Open_sql_cursor(c_test,dot) then begin
  512.     Info_box('Test dotazu','Chyba v syntaxi');
  513.     TestDotazu := false
  514.   end
  515.   else begin
  516.     if odkud=0 then Info_box('Test dotazu','Syntaxe v po°ßdku'); // tlacitko Test syntaxe
  517.     Close_cursor(c_test);
  518.     TestDotazu := true;
  519.   end;  
  520. end;
  521.  
  522. procedure UlozitDotaz;
  523. {************************************************}
  524. var
  525.   drec : trecnum;
  526.   pop : string[20];
  527.   a : boolean;
  528. begin
  529.   pop := '';
  530.   a := Input_Box('popis dotazu',pop,20);
  531.   if a then begin
  532.     drec := Insert(Tdotazy);
  533.     Tdotazy[drec].cislo := drec;
  534.     Tdotazy[drec].popis := pop;
  535.     Tdotazy[drec].dotaz := dotaz;
  536.     Tdotazy[drec].autord := Who_am_I;
  537.     Info_box('Provedeno','OK');
  538.   end;
  539. end;
  540.  
  541. procedure Ulozit(pom : short);
  542. {************************************************}
  543. begin
  544.   SestavitDotaz;
  545.   if TestDotazu(1,dotaz) then begin
  546.     UlozitDotaz;
  547.     ptatse := false;
  548.     if pom = 1 then
  549.        Close_view(id_tool);
  550.   end;
  551. end;
  552.  
  553. procedure ZavritTool;
  554. {************************************************}
  555. begin
  556.   SestavitDotaz;
  557.   if TestDotazu(1,dotaz) then begin
  558.     if ptatse then if YesNo_box('Otßzka','Ulo₧it dotaz pro dalÜφ pou₧itφ?') then Ulozit(2);
  559.     Close_view(id_tool);
  560.     if id>0 then Send_message(id,1599,0,0);              // odznaΦenφ p°φp. QBE dotazu 
  561.     if id_sez>0 then Send_message(id_sez,1599,0,0);          
  562.     UplatnitDotaz;
  563.   end;  
  564.   
  565. end;
  566.  
  567. procedure TestTlac;
  568. {************************************************}
  569. begin
  570.   SestavitDotaz;
  571.   TestDotazu(0,dotaz);
  572. end;
  573.  
  574. procedure Vsechny;
  575. {**************************************}
  576. {vybrat vÜechny zßznamy}
  577. begin
  578.   if id>0 then Send_message(id,1599,0,0);              // odznaΦenφ p°φp. QBE dotazu 
  579.   if id_sez>0 then Send_message(id_sez,1599,0,0);          
  580.   if vsechnysk then dotaz := 'SELECT * FROM Tfirma'
  581.   else              dotaz := 'SELECT * FROM Tfirma WHERE skupina='+Int2str(skup);
  582.   UplatnitDotaz;
  583. end;  
  584.   
  585. procedure VybratDotaz;
  586. {**************************************}
  587. {vybrat p°ipraven² dotaz a uplatnit ho}
  588. var
  589.   id_dot : window_id;
  590. begin
  591.   zrusitAkci := true;
  592.   Open_view("*VyberDotaz",no_redir,modal_view,0,0,id_dot);
  593.   repeat Peek_message until id_dot=0;
  594.   SmazatFrontu;
  595.  
  596.   if not zrusitAkci then begin
  597.     if id>0 then Send_message(id,1599,0,0);              // odznaΦenφ p°φp. QBE dotazu 
  598.     if id_sez>0 then Send_message(id_sez,1599,0,0);          
  599.     dotaz := Tdotazy[dotazpom].dotaz;
  600.     UplatnitDotaz;
  601.   end;
  602. end;
  603.  
  604. procedure EditDotaz;
  605. {**************************************}
  606. {opravit nebo smazat p°ipraven² dotaz}
  607. var
  608.   id_edit : window_id;
  609. begin
  610.   Open_view("*PDotazy",no_redir,0,0,0,id_edit);
  611.   repeat Peek_message until id_edit=0;
  612. end;
  613.  
  614. procedure ResetTool(ind : short) ;
  615. {************************************************}
  616. {vyΦistφ dotazov² tool a₧ k danΘmu °ßdku}
  617. var
  618.   i : short;
  619. begin
  620.   for i := 7 downto ind do begin
  621.     atr[i] := 0;
  622.     oper[i] := 0;
  623.     hodn[i] := '';
  624.     spoj [i] := 0;
  625.   end;
  626.   if ind > 1 then spoj[ind-1] := 0;
  627.   if id_tool > 0 then Reset_view(id_tool,-1,1); //p°ekreslenφ funguje pouze za b∞hu programu!
  628. end;
  629.  
  630. procedure SmazatDotaz(idd : window_id; cis : integer);
  631. {************************************************}
  632. //tlaΦφtko Smazat u zßznamu v pohledu Pdotazy
  633. var
  634.   cd : cursor;
  635.   rescislo : integer;
  636. begin
  637.   if YesNo_box('Otßzka','Opravdu chcete vymazat tento dotaz?') then begin
  638.     if Get_fcursor(idd,cd,nil) then ;
  639.       if Delete(cd,cis) then Signalize
  640.       else Reset_view(idd,-1,RESET_DELETIONS+RESET_CURSOR);
  641.   end;    
  642. end;
  643.  
  644. procedure NovyDotaz;  
  645. {************************************************}
  646. begin
  647.   Set_cursor(1);
  648.   Set_status_text('Otevφrßm pohled pro sestrojenφ dotazu...');
  649.   ResetTool(1);
  650.   ptatse := true;
  651.   Open_view("*tool",no_redir,modal_view,0,0,id_tool);
  652.   repeat Peek_message until id_tool=0;
  653.   SmazatFrontu;
  654. end;  
  655.  
  656. procedure ToolProNovy;  
  657. {************************************************}
  658. begin
  659.   Set_cursor(1);
  660.   Set_status_text('Otevφrßm pohled pro sestrojenφ dotazu...');
  661.   ResetTool(1);
  662.   Open_view("*tool_n",no_redir,modal_view,0,0,id_tool);
  663.   repeat Peek_message until id_tool=0;
  664.   SmazatFrontu;
  665. end;  
  666.  
  667. procedure DveKat(idd : window_id);
  668. {**************************************}
  669. var
  670.   i,s : short;
  671.    
  672. begin
  673.   for i := 1 to 8 do
  674.     if p[i] then s := s+1;
  675.   if s >= 2 then dvekateg := true 
  676.   else dvekateg := false;
  677.   Reset_view(id,-1,1);
  678. end;
  679.  
  680. procedure PodleKategorii;
  681. {**************************************}
  682. var
  683.   id_pk : window_id;
  684. begin
  685.   if vsechnysk then Info_box('Nelze','Pro v²b∞r podle kategoriφ musφte mφt vybrßnu jednu konkrΘtnφ skupinu!')
  686.   else begin
  687.     sp := 1;
  688.     Open_view('*Podlekateg',-1,0,0,0,id_pk);
  689.     repeat Peek_message until id_pk=0;
  690.   
  691.     if not zrusitAkci then begin
  692.       SestavitDotazKateg;
  693.       UplatnitDotaz;
  694.     end;
  695.   end;
  696. end;
  697.  
  698. procedure Zobraz(tab : string[10]);
  699. {**************************************}
  700. var
  701.   idx : window_id;
  702.   sx : string[40];
  703.   
  704. begin  
  705.   sx := 'DEFAULT '+tab+' TABLEVIEW';
  706.   Open_view(sx,no_redir,0,0,0,idx);
  707. //  repeat Peek_message until idx=0;
  708. end;
  709.  
  710. function WTCesta(var cesta : string[100]) : boolean;
  711. {**************************************}
  712. {zjiÜt∞nφ cesty k programu WinText602 z registraΦnφ databßze Windows}
  713. var
  714.   key : string[100];
  715.   s : string[100];
  716.   buf : integer;
  717.   err : short;
  718. begin
  719.   WTCesta := false;
  720.   err := -1;
  721.   buf := 100;
  722.   key := 'WinText602\CurVer';
  723.   s := '';
  724.   RegQueryValue(1,key,s,buf);                  // zjiÜt∞nφ aktußlnφ verze WinTextu
  725.  
  726.   buf := 100;
  727.   key := s+'\protocol\StdFileEditing\server';
  728.   s := '';
  729.   err := RegQueryValue(1,key,s,buf);           // zjiÜt∞nφ cesty k Wintext602.exe
  730.   cesta := s;                                  // odkazem vrßcenß hodnota
  731.   if err <> 0 then WTCesta := true;
  732. end;
  733.  
  734. function WMCesta(var cesta : string[100]) : boolean;
  735. {**************************************}
  736. {zjiÜt∞nφ cesty k programu WinMana₧er602 z registraΦnφ databßze Windows}
  737. var
  738.   key : string[100];
  739.   s : string[100];
  740.   buf : integer;
  741.   err : short;
  742. begin
  743.   WMCesta := false;
  744.   err := -1;
  745.   buf := 100;
  746.   key := 'WinM602\Shell\Open\Command';
  747.   s := '';
  748.   err := RegQueryValue(1,key,s,buf);                
  749.   StrDelete(s,StrLength(s)-2,3);
  750.   cesta := s;
  751.   if err <> 0 then WMCesta := true;
  752. end;
  753.  
  754. function WFCesta(var cesta : string[100]) : boolean;
  755. {**************************************}
  756. {zjiÜt∞nφ cesty k programu WinFax602 z registraΦnφ databßze Windows}
  757. var
  758.   key : string[100];
  759.   s : string[100];
  760.   buf : integer;
  761.   err : short;
  762. begin
  763.   WFCesta := false;
  764.   err := -1;
  765.   buf := 100;
  766.   key := 'WinFM602\Shell\Open\Command';
  767.   s := '';
  768.   err := RegQueryValue(1,key,s,buf);                
  769.   StrDelete(s,StrLength(s)-2,3);
  770.   cesta := s;
  771.   if err <> 0 then WFCesta := true;
  772. end;
  773.  
  774. procedure LokalSablony;
  775. {**************************************}
  776. // pro OEM instalaci (lokßlnφ) je nutnΘ nastavit cestu k Üablonßm automaticky
  777. var
  778.   spom : CSIstring[255];
  779. begin
  780.   spom := pathwt;
  781.   UpCase(spom);
  782.   StrDelete(spom,StrPos('\EXEC',spom),StrLength('\exec\wintext.exe'));
  783.   spom := spom+'\SABLONY';
  784.   Parametry[0].sablonywt := spom;
  785. end;
  786.  
  787. procedure LokalSablonyOEM;
  788. {**************************************}
  789. // 19.4. verze spec., LOF p°enese do C:\ADRESAR
  790. var
  791.   spom : CSIstring[255];
  792. begin
  793.   spom := pathwb;
  794.   Parametry[0].sablonywt := spom;
  795. end;
  796.  
  797. function TestPrav : Boolean;
  798. {**************************************}
  799. {ov∞°enφ, mß-li p°ihlßÜen² u₧ivatel dostatek prßv pro prßci}
  800. var
  801.  a,b,c,d,e,f,g,h,i,j : short;
  802. begin
  803.   TestPrav := true;
  804.  
  805.   myname := Who_am_I;
  806.  
  807.   Get_data_rights(Tfirma, myName,a,b,c); 
  808.   Get_data_rights(MailMerge, myName,b,c,d); 
  809.   Get_data_rights(Tdotazy, myName,c,d,e);
  810.   Get_data_rights(Tschuzky, myName,d,e,f);     
  811.   Get_data_rights(Parametry, myName,e,f,g);
  812.   Get_data_rights(Tool_res, myName,f,g,h);
  813.   Get_data_rights(TsablonyWT, myName,g,h,i);
  814.  
  815.  
  816.   if (a and Right_read = 0) or (a and Right_write = 0) or (a and Right_insert = 0) or (a and Right_del = 0) or
  817.      (b and Right_read = 0) or (b and Right_write = 0) or (b and Right_insert = 0) or (b and Right_del = 0) or
  818.      (c and Right_read = 0) or (c and Right_write = 0) or (c and Right_insert = 0) or (c and Right_del = 0) or
  819.      (d and Right_read = 0) or (d and Right_write = 0) or (d and Right_insert = 0) or (d and Right_del = 0) or
  820.      (e and Right_read = 0) or (e and Right_write = 0) or (e and Right_insert = 0) or (e and Right_del = 0) or
  821.      (f and Right_read = 0) or (f and Right_write = 0) or (f and Right_insert = 0) or (f and Right_del = 0) or
  822.      (g and Right_read = 0) or (g and Right_write = 0) or (g and Right_insert = 0) or (g and Right_del = 0) 
  823.   then
  824.     if YesNo_box("Upozorn∞nφ","Nemßte vÜechna pot°ebnß prßva,"#10"budou Vßm odep°eny n∞kterΘ akce."#10#10"PokraΦovat?")
  825.       then begin
  826.         if (e and Right_read = 0) or (e and Right_write = 0) or (e and Right_insert = 0) or (e and Right_del = 0) 
  827.         then begin
  828.           Info_box('Nelze','Mßte tak mßlo prßv, ₧e nenφ mo₧no pokraΦovat.');
  829.           TestPrav := false;
  830.         end;  
  831.       end else TestPrav := false;
  832. end;
  833.  
  834. procedure Inicializace;
  835. {**************************************}
  836. var
  837.   pocet : integer;
  838. begin
  839.   konec := false;
  840.   s2 := 'VÜechny Skupiny';
  841.   s4 := 'P°ehled firem vÜech skupin'; 
  842.   vsechnysk := true;
  843.   vybrat := true;
  844.   dvekateg := false;
  845.   kolikrat := 1;
  846.   kolikpred := 0; 
  847.   preview := 0;
  848.   str_od := 1; str_do := 999;
  849.   repsort := 1;
  850.   nall := false;
  851.   expkod := 3;
  852.   exptype := 4;
  853.   editTisk := false;
  854.   kon := true;
  855.   
  856.   if Rec_cnt(Parametry,pocet) then      {kdyby n∞kdo omylem smazal tabulku Parametry... }
  857.   begin
  858.     Signalize;
  859.     Halt;
  860.   end;
  861.   if pocet = 0 then begin               {kdyby n∞kdo omylem smazal zßznam v tab Parametry... }
  862.     Insert(Parametry);
  863.   end 
  864.   else begin                            {naΦtenφ velikosti naposled pou₧itΘho Ütφtku}
  865.     labeltype := Parametry[0].typst;
  866.     labelsize := Parametry[0].velik;
  867.     template := Parametry[0].template;         
  868.   end;
  869.  
  870.   if Server_access(pathwb) then Info_box('Chyba','Chyba p°i zjiÜ¥ovßnφ cesty k databßzi WinBase.'#10'MailMerge nebude fungovat.');
  871.   if WTcesta(pathwt) then Info_box('Chyba','ZjiÜt∞nφ cesty k programu WinText602.'#10'MailMerge nebude fungovat.') ;
  872.   if WMcesta(pathwm) then Info_box('Chyba','ZjiÜt∞nφ cesty k programu WinMana₧er602.'#10'VytßΦenφ Φφsel nebude fungovat.') ;
  873.   if WFcesta(pathwf) then Info_box('Chyba','ZjiÜt∞nφ cesty k programu WinFM602.'#10'RychlΘ faxovßnφ nebude fungovat.'); 
  874. //  LokalSablony;             // pro OEM verzi se Üablonami ve WT
  875. //  LokalSablonyOEM;          // pro OEM verzi bez nov²ch Üablon na matricφch WT
  876.  
  877.   Help_file("adresar3.hlp");
  878.   DoplnitTexty;                         
  879.  
  880.   if Open_sql_cursor(curmain,'SELECT * FROM Tfirma') then begin
  881.     Signalize;
  882.     Halt;
  883.   end;  
  884.  
  885.   Register_key(117,false,false,false,3000);   {klßvesa F6 pro p°echod ze seznamu do formulß°e}
  886.   Register_key(115,false,false,false,2222);   {F4 Φφslo zßznamu}
  887.   Register_key(114,false,false,false,2001);   {klßvesa F3 pro otev°enφ formulß°e}
  888.   Register_key(114,false,true,false,2002);    {klßvesa Ctrl+F3 pro otev°enφ seznamu}
  889.   Register_key(123,false,false,false,2050);   {klßvesa F12 pro v²b∞r vÜech zßznam∙}
  890.   Register_key(46,false,true,false,2083);     {klßvesy Ctrl+Del pro smazßnφ zßznamu}
  891.   Register_key(45,false,false,false,2080);    {klßvesa Ins pro vlo₧enφ zßznamu}
  892.   Register_key(45,false,true,false,2081);     {klßvesy Ctrl+Ins pro vlo₧enφ kopie zßznamu}
  893.   Register_key(119,true,false,false,9999);    {zablokovßnφ klßvesy Shift+F8 (zruÜenφ zßznamu)}
  894.   Register_key(118,true,false,false,9999);    {zablokovßnφ klßvesy Shift+F7 (zruÜenφ vÜech zßznam∙)}
  895.  
  896. end;
  897.  
  898.  
  899. {************************************************************}
  900. {******************     hlavnφ program     ******************}
  901. {************************************************************}
  902. begin
  903.  
  904.   if 1 = 2 then begin
  905.   if not TestPrav then halt;
  906.   Inicializace;
  907.   
  908.   if not Main_menu ("*MHlavni") then halt;
  909.  
  910.   Open_view("*Pseznam",curmain,0,0,0,id_sez);    
  911.   SetWindowText(id_sez,s4);
  912.   VyberSKupinu;
  913.  
  914.   while not konec and Get_ext_message (Msg, handle, NIL) do
  915.   begin
  916.     if msg = -1 then konec := true;                 {Konec}
  917.     if msg = 2000 then VyberSkupinu;                {Vybrat skupinu...}
  918.     if msg = 2001 then                              {Adresß°}
  919.       if id = 0 then begin
  920.          Open_view("*Pfirma",curmain,0,0,0,id);
  921.          SetWindowText(id,s2);
  922.          Reset_view(id,-1,5);
  923.       end   
  924.       else Close_view(id);       
  925.     if msg = 2002 then                              {P°ehled firem}
  926.       if id_sez = 0 then begin
  927.         Open_view("*Pseznam",curmain,0,0,0,id_sez);
  928.         SetWindowText(id,s4);
  929.         id_s := GetDlgItem(id_sez,3);
  930.         Reset_view(id_sez,-1,5);
  931.       end  
  932.       else Close_view(id_sez);       
  933.     if msg = 2003 then PrehledKontaktu;             {P°ehled kontakt∙} 
  934.     if msg = 2004 then Export;
  935.     if msg = 2005 then ImportDBF;
  936.     if msg = 2006 then ImportTDT;
  937.     if msg = 2100 then DefSkupin;                   {Nßzvy skupin}
  938.     if msg = 2010 then Kategorie;                   {Text kategoriφ}
  939.     if msg = 2011 then WT;                          {WinText}
  940.     if msg = 2012 then Sablony;                     {èablony}
  941.     if msg = 2013 then SdilenyAdresar;              {Sdφlenφ Üablon}
  942.     if msg = 2020 then TiskStitku(-1);              {Tisk Ütφtk∙}
  943.     if msg = 2021 then TiskSeznamu;                 {Tisk seznamu firem}
  944.     if msg = 2025 then TiskMailMerge;               {Mail Merge}
  945.     if msg = 2032 then VyberStitku;                 {V²b∞r Ütφtku}
  946.     if msg = 2033 then NastaveniTiskarny;           {Nastavenφ tiskßrny}
  947.     if msg = 2040 then Kontrola;                    {Kontrola databßze}
  948.     if msg = 2041 then Zaloha;                      {Zßloha}
  949.     if msg = 2042 then Obnoveni;                    {Obnovenφ}
  950.     if msg = 2043 then Uvolneni;                    {Uvoln∞nφ}
  951.     if msg = 2044 then OpravitIndexy;               {Opravit indexy}
  952.     if msg = 2045 then ResetCursor;                 {NaΦφst obsah}
  953.     if msg = 2046 then NastavitZalohu;              {Parametry zßlohy}
  954.     if msg = 2047 then Prenosz2x;                   {P°enos dat z verze 2.x}
  955.     if msg = 2049 then OdemknoutMM;                 {Odemknout}
  956.     if msg = 2050 then Vsechny;                     {VÜechny zßznamy}
  957.     if msg = 2051 then NovyDotaz;                   {Polo₧it dotaz}
  958.     if msg = 2052 then VybratDotaz;                 {Vybrat dotaz}
  959.     if msg = 2053 then ToolProNovy;                 {Definovat dotaz}
  960.     if msg = 2054 then EditDotaz;                   {Opravit dotaz}
  961.     if msg = 2055 then Najit;                       {Najit zßznam}
  962.     if msg = 2061 then PodleKategorii;              {Podle kategoriφ}
  963.     if msg = 2080 then Vlozeni;                     {Nov² zßznam}
  964.     if msg = 2081 then Kopie;                       {Kopie zaznamu}
  965.     if msg = 2083 then Smazani;                     {ZruÜenφ zßznamu}
  966.     if msg = 2084 then SmazatVsechnyZaznamy;        {ZruÜit vÜe}
  967.     if msg = 2105 then ZmenitSkupinuZaznamu;        {}
  968.     if msg = 2222 then PosledniCislo;               {}
  969.     if msg = 2301 then Zobraz('Tfirma');
  970.     if msg = 2302 then Zobraz('Tschuzky');
  971.     if msg = 2303 then Zobraz('Skupiny');
  972.     if msg = 2304 then Zobraz('Parametry');
  973.     if msg = 2305 then Zobraz('Tdotazy');
  974.     if msg = 2306 then Zobraz('Tinserty');
  975.     if msg = 3000 then Prepnuti;                    {p°epnutφ z p°ehledu firem do adresß°e (tlaΦφtko na liÜt∞)}
  976.     if msg = 3001 then View_open("*Pinfo");         {Informace}
  977.     if msg = 3002 then Show_help(20000);            {Nßpov∞da k aplikaci}
  978.     Set_status_text("");
  979.   end;
  980.   Main_menu (nil);
  981.   if Close_cursor(curmain) then Signalize;
  982.   end;
  983. end.
  984.  
  985.