// Registar 1.25
// bsnseabra@hotmail.com
// bsntuga www.portugal-a-programar.org
// Projecto 1

unit Unit1;

interface

// Usa
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Mask, StdCtrls, DB, ExtCtrls, Buttons, XPMan, jpeg;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit1: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit2: TMaskEdit;
    Label7: TLabel;
    Edit7: TEdit;
    EditCod: TEdit;
    Label8: TLabel;
    Bevel1: TBevel;
    BitBtn1: TBitBtn;
    OpenDialog1: TOpenDialog;
    XPManifest1: TXPManifest;
    GroupBox2: TGroupBox;
    BitBtn3: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    Bevel2: TBevel;
    BitBtn2: TBitBtn;
    BitBtn4: TBitBtn;
    Image1: TImage;
    Label10: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
  private
    ArqNovo,ArqAtual: string;
    Novo,ArquivoAberto: boolean;
  public
  end;

// Records
Type
   tBase=record
   QtReg:integer;
   PsReg:integer;
   end;
   tAgenda=record // vars
   Cod :string;
   Nome :String;
   Telefone :String;
   Bairro :String;
   Numero_Res :String;
   Numero_Ap :String;
   Rua :String;
   Referencia :String;
end;

var
  Form1: TForm1;
  Base:tBase;
  vAgenda:array[1..100] of tAgenda; 

implementation

Uses
 Unit3,
 Unit4;

{$R *.dfm}

procedure TForm1.FormActivate(Sender: TObject);
begin
 Base.QtReg:=1;
 Base.PsReg:=1;
 EditCod.ReadOnly:=True;
 EditCod.text:=InttoStr(Base.PsReg);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
 Base.QtReg:=Base.QtReg+1;
 Base.PsReg:=Base.QtReg;
 EditCod.text:=InttoStr(Base.QtReg);
 Edit1.text:='';
 Edit2.text:='';
 Edit3.text:='';
 Edit4.text:='';
 Edit5.text:='';
 Edit6.text:='';
 Edit7.text:='';
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
 EditCod.text:=InttoStr(Base.QtReg);
 Edit1.text:='';
 Edit2.text:='';
 Edit3.text:='';
 Edit4.text:='';
 Edit5.text:='';
 Edit6.text:='';
 Edit7.text:='';
 if OpenDialog1.Execute then
 begin
 ArqAtual:=OpenDialog1.Filename;
 Unit4.AbrirArq (PesArq, ArqAtual, Novo);
 Novo:=False;
 end
 else
 Exit;
 ArquivoAberto:=True;
end;

procedure TForm1.BitBtn6Click(Sender: TObject);
begin
 if ArquivoAberto=false then
begin
 ShowMessage ('Abrir Primeiro o ficheiro da Base de dados');
 exit;
end;
 Form3.ShowModal;
end;

procedure TForm1.BitBtn7Click(Sender: TObject);
var
 Reg: Unit4.TPessoasReg;
 RegN: integer;
begin
 edit1.SetFocus;
 if ArquivoAberto=false then
begin
 ShowMessage ('Abrir Primeiro o ficheiro da Base de dados');
 exit;
end;
begin
 with Reg do
begin
 Cod:=EditCod.Text;
 Nome:=Edit1.Text;
 Telefone:=Edit2.Text;
 Bairro:=Edit3.Text;
 Numero_Res:=Edit4.Text;
 Numero_Ap:=Edit5.Text;
 Rua:=Edit6.Text;
 Referencia:=Edit7.Text;
end;
 Form3.ComboBox1.Items.Add (edit1.Text);
 RegN:= FileSize(PesArq);
 Unit4.GravarArq (PesArq, RegN, Reg);
end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
 Base.QtReg:=Base.QtReg+1;
 Base.PsReg:=Base.QtReg;
 EditCod.text:=InttoStr(Base.QtReg);
 Edit1.text:='';
 Edit2.text:='';
 Edit3.text:='';
 Edit4.text:='';
 Edit5.text:='';
 Edit6.text:='';
 Edit7.text:='';
end;

procedure TForm1.BitBtn4Click(Sender: TObject);
begin
Form1.Close;
end;

end.
