Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Indirizzi - GestoreForm.pas

GestoreForm.pas

Caricato da: Poggi Marco
Scarica il programma completo

  1. unit GestoreForm;
  2.  
  3. {Sorgente per Lazarus}
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  9.   Dialogs, StdCtrls, ExtCtrls, CheckLst,
  10.   Nominativo,IoFile;
  11.  
  12. type
  13.   TForm1 = class(TForm)
  14.     CheckListBoxSiti: TCheckListBox;
  15.     LabelEtichettaSiti: TLabel;
  16.     LabeledEditNome: TLabeledEdit;
  17.     LabeledEditURL: TLabeledEdit;
  18.     LabeledEditUtente: TLabeledEdit;
  19.     LabeledEditPass: TLabeledEdit;
  20.     MemoNote: TMemo;
  21.     LabelNoteEventuali: TLabel;
  22.     ButtonCarica: TButton;
  23.     ButtonCancellaSelezionati: TButton;
  24.     LabelCaratteriDigitati: TLabel;
  25.     ButtonLibera: TButton;
  26.     ButtonModifica: TButton;
  27.     procedure FormCreate(Sender: TObject);
  28.     procedure ButtonCaricaClick(Sender: TObject);
  29.     procedure LabeledEditNomeChange(Sender: TObject);
  30.     procedure LabeledEditURLChange(Sender: TObject);
  31.     procedure MemoNoteChange(Sender: TObject);
  32.     procedure ButtonCancellaSelezionatiClick(Sender: TObject);
  33.     procedure CheckListBoxSitiClick(Sender: TObject);
  34.     procedure ButtonLiberaClick(Sender: TObject);
  35.     procedure LabeledEditPassChange(Sender: TObject);
  36.     procedure LabeledEditUtenteChange(Sender: TObject);
  37.     procedure ButtonModificaClick(Sender: TObject);
  38.     procedure LabeledEditNomeDblClick(Sender: TObject);
  39.     procedure LabeledEditURLDblClick(Sender: TObject);
  40.     procedure LabeledEditUtenteDblClick(Sender: TObject);
  41.     procedure LabeledEditPassDblClick(Sender: TObject);
  42.   private
  43.     { Déclarations privées }
  44.     procedure cancella;
  45.     procedure edita_Indirizzi;
  46.     function giaEsistente(esaminato:indirizzo):Boolean;
  47.     procedure aggiungiRecord(nuovo:indirizzo; posizione:Longint);
  48.   public
  49.     { Déclarations publiques }
  50.     registro:string;
  51.     fileLogico:fiolima;
  52.   end;
  53.  
  54. var
  55.   Form1: TForm1;
  56.  
  57. implementation
  58.  
  59. {$R *.dfm}
  60.  
  61. procedure TForm1.FormCreate(Sender: TObject);
  62. begin
  63.   registro:=GetCartella+'\dati.dat';
  64.   edita_Indirizzi;
  65.   form1.Caption:='Indirizzi';
  66. end;
  67.  
  68. procedure TForm1.cancella;
  69. begin
  70.   LabeledEditNome.Text:='';
  71.   LabeledEditURL.Text:='';
  72.   LabeledEditUtente.Text:='';
  73.   LabeledEditPass.Text:='';
  74.   MemoNote.Lines.Clear;
  75.   CheckListBoxSiti.Items.Clear;
  76.   LabelCaratteriDigitati.Caption:='';
  77. end;
  78.  
  79. procedure TForm1.ButtonCaricaClick(Sender: TObject);
  80. var nuovo:indirizzo;
  81.     i:integer;
  82. begin
  83.   nuovo:=indirizzoNullo;
  84.   nuovo.nome:=LabeledEditNome.Text;
  85.   nuovo.indirizzo:=LabeledEditURL.Text;
  86.   nuovo.utente:=LabeledEditUtente.Text;
  87.   nuovo.pas:=LabeledEditPass.Text;
  88.   i:=0;
  89.   while i<MemoNote.Lines.Count do
  90.   begin
  91.     nuovo.note:=nuovo.note + MemoNote.Lines[i];
  92.     i:=i+1;
  93.     if i<MemoNote.Lines.Count then nuovo.note:=nuovo.note+#13+#10;
  94.   end;
  95.   if (not giaEsistente(nuovo)) and (not ugualeANullo(nuovo)) then
  96.   begin
  97.     aggiungiRecord(nuovo, -5);
  98.   end;
  99. end;
  100.  
  101. procedure TForm1.LabeledEditNomeChange(Sender: TObject);
  102. begin
  103.  LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(length(LabeledEditNome.Text));
  104. end;
  105.  
  106. procedure TForm1.LabeledEditURLChange(Sender: TObject);
  107. begin
  108.   LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(length(LabeledEditURL.Text));
  109. end;
  110.  
  111. procedure TForm1.MemoNoteChange(Sender: TObject);
  112. var somma,linee:integer;
  113. begin
  114.   somma:=0;
  115.   linee:=0;
  116.   while linee<MemoNote.Lines.Count do
  117.   begin
  118.      somma:=somma+length(MemoNote.Lines[linee]);
  119.      linee:=linee+1;
  120.   end;
  121.   LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(somma)+' su '+IntToStr(linee)+' linee';
  122. end;
  123.  
  124. procedure TForm1.ButtonCancellaSelezionatiClick(Sender: TObject);
  125. var i,j,fine,selezione:longint;
  126.     copia:fiolima;
  127.     elemento:indirizzo;
  128.     percorsoCopia,breveTesto:string;
  129. begin
  130.   percorsoCopia:=getCartella+'\copia.cop';
  131.   selezione:=-500;
  132.   if (filelogico.ApriFile(registro, 'a')) and (copia.ApriFile(percorsoCopia, 'w')) then
  133.   begin
  134.     fine:=CheckListBoxSiti.Items.Count;
  135.     i:=0;
  136.     j:=0;
  137.     while i<fine do
  138.     begin
  139.       elemento:=filelogico.leggi(i);
  140.       if not CheckListBoxSiti.Checked[i] then
  141.       begin
  142.          copia.scrivi(elemento, j);
  143.          j:=j+1;
  144.       end
  145.       else
  146.       begin
  147.         breveTesto:='Cancello'+#13+#10+elemento.nome+char(13)+char(10)+elemento.indirizzo;
  148.         // if selezione <>mrYesToAll then selezione:=MessageDlg(breveTesto, mtConfirmation, mbYesAllNoAllCancel, 0);  Istruzione per Delphi
  149.         if selezione <>mrYesToAll then selezione:=MessageDlg('Cosa fare ?', breveTesto,  mtConfirmation, [mbYes, mbNo, mbIgnore],0 ); // Nuova istruzione riscritta per Lazarus
  150.         if not((selezione=mrYesToAll) or (selezione=mrYes)) then
  151.         begin
  152.           copia.scrivi(elemento, j);
  153.           j:=j+1;
  154.         end;
  155.       end;
  156.       i:=i+1;
  157.     end;
  158.     filelogico.ChiudiFile;
  159.     copia.ChiudiFile;
  160.     DeleteFile(registro);
  161.     RenameFile(percorsoCopia, registro);
  162.     edita_Indirizzi;
  163.     LabeledEditNome.SetFocus;
  164.   end
  165.   else
  166.     ShowMessage('Fine '+fileLogico.GetNome+' non trovato!');
  167. end;
  168.  
  169. procedure TForm1.edita_Indirizzi;
  170. var elemento:indirizzo;
  171. begin
  172.   cancella;
  173.   if fileLogico.ApriFile(registro, 'r') then
  174.   begin
  175.     while not fileLogico.FineFile  do
  176.     begin
  177.       elemento:=fileLogico.leggi;
  178.       CheckListBoxSiti.Items.Add(elemento.nome);
  179.     end;
  180.     LabelEtichettaSiti.Caption:='Siti presenti: '+IntToStr(fileLogico.NumeroDiCampi);
  181.     fileLogico.ChiudiFile;
  182.   end
  183.   else
  184.     ShowMessage('Il file '+fileLogico.GetNome+char(13)+char(10)+'non è presente !');
  185. end;
  186.  
  187. procedure TForm1.CheckListBoxSitiClick(Sender: TObject);
  188. var elemento:indirizzo;
  189.     selezione:longint;
  190. begin
  191.   selezione:=CheckListBoxSiti.ItemIndex;
  192.   if selezione>=0 then
  193.    if fileLogico.ApriFile(registro, 'r') then
  194.    begin
  195.      elemento:=fileLogico.leggi(selezione);
  196.      LabeledEditNome.Text:=elemento.nome;
  197.      LabeledEditURL.Text:=elemento.indirizzo;
  198.      LabeledEditUtente.Text:=elemento.utente;
  199.      LabeledEditPass.Text:=elemento.pas;
  200.      MemoNote.Lines.Clear;
  201.      MemoNote.Lines.Add(elemento.note);
  202.      fileLogico.ChiudiFile;
  203.    end;
  204. end;
  205.  
  206. procedure TForm1.ButtonLiberaClick(Sender: TObject);
  207. begin
  208.   edita_Indirizzi;
  209.   LabeledEditNome.SetFocus;
  210. end;
  211.  
  212. procedure TForm1.LabeledEditPassChange(Sender: TObject);
  213. begin
  214.   LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(length(LabeledEditPass.Text));
  215. end;
  216.  
  217. procedure TForm1.LabeledEditUtenteChange(Sender: TObject);
  218. begin
  219.   LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(length(LabeledEditUtente.Text));
  220. end;
  221.  
  222. function TForm1.giaEsistente(esaminato:indirizzo):Boolean;
  223. var risultato:Boolean;
  224.     letto:indirizzo;
  225. begin
  226.   risultato:=False;
  227.   if fileLogico.ApriFile(registro, 'r') then
  228.   begin
  229.     while (not risultato) and (not fileLogico.FineFile) do
  230.     begin
  231.        letto:=fileLogico.leggi();
  232.        risultato:=recordUguali(letto, esaminato);
  233.     end;
  234.     fileLogico.ChiudiFile;
  235.   end;
  236.   giaEsistente:=risultato;
  237. end;
  238.  
  239. procedure TForm1.aggiungiRecord(nuovo:indirizzo; posizione:Longint);
  240. begin
  241.   if fileLogico.ApriFile(registro, 'a') then
  242.   begin
  243.     if posizione>=0 then
  244.     begin
  245.       fileLogico.scrivi(nuovo, posizione);
  246.     end
  247.     else
  248.     begin
  249.       fileLogico.scrivi(nuovo);
  250.     end;
  251.     fileLogico.ChiudiFile;
  252.   end
  253.   else
  254.   begin
  255.       MessageDlg('Ipoossibile aprire il file '+fileLogico.GetNome, mtError, mbOKCancel, 0);
  256.       Application.Terminate;
  257.   end;
  258.   edita_Indirizzi;
  259.   LabeledEditNome.SetFocus;
  260. end;
  261.  
  262. procedure TForm1.ButtonModificaClick(Sender: TObject);
  263. var daModificare:indirizzo;
  264.     linee,selezione:integer;
  265. begin
  266.   daModificare:=indirizzoNullo;
  267.   if CheckListBoxSiti.ItemIndex>=0 then
  268.   begin
  269.     daModificare.nome:=LabeledEditNome.Text;
  270.     daModificare.indirizzo:=LabeledEditURL.Text;
  271.     daModificare.utente:=LabeledEditUtente.Text;
  272.     daModificare.pas:=LabeledEditPass.Text;
  273.     linee:=0;
  274.     while linee<MemoNote.Lines.Count do
  275.     begin
  276.       daModificare.note:=daModificare.note+MemoNote.Lines[linee];
  277.       linee:=linee+1;
  278.       if linee<MemoNote.Lines.Count then daModificare.note:=daModificare.note+#13+#10;
  279.     end;
  280.     selezione:=MessageDlg('Modifica in'+#13+#10+daModificare.nome+#13+#10+daModificare.indirizzo , mtConfirmation, mbYesNoCancel, 0);
  281.     if (not ugualeANullo(daModificare)) and (selezione=mrYes) then
  282.       aggiungiRecord(daModificare, CheckListBoxSiti.ItemIndex);
  283.   end;
  284.   edita_Indirizzi;
  285.   LabeledEditNome.SetFocus;
  286. end;
  287.  
  288. procedure TForm1.LabeledEditNomeDblClick(Sender: TObject);
  289. begin
  290.   LabeledEditNome.SelStart:=0;
  291.   LabeledEditNome.SelLength:=length(LabeledEditNome.Text);
  292. end;
  293.  
  294. procedure TForm1.LabeledEditURLDblClick(Sender: TObject);
  295. begin
  296.   LabeledEditURL.SelStart:=0;
  297.   LabeledEditURL.SelLength:=length(LabeledEditURL.Text);
  298. end;
  299.  
  300. procedure TForm1.LabeledEditUtenteDblClick(Sender: TObject);
  301. begin
  302.   LabeledEditUtente.SelStart:=0;
  303.   LabeledEditUtente.SelLength:=length(LabeledEditUtente.Text);
  304. end;
  305.  
  306. procedure TForm1.LabeledEditPassDblClick(Sender: TObject);
  307. begin
  308.   LabeledEditPass.SelStart:=0;
  309.   LabeledEditPass.SelLength:=length(LabeledEditPass.Text);
  310. end;
  311.  
  312. end.