unit FormGenerate;

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Spin, VCard, FormEx;

type

  { TFormGenerate }

  TFormGenerate = class(TFormEx)
    ButtonGenerate: TButton;
    Label1: TLabel;
    SpinEditCount: TSpinEdit;
    procedure ButtonGenerateClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormShow(Sender: TObject);
  public
    Contacts: TContacts;
    procedure UpdateInterface;
  end;


implementation

{$R *.lfm}

uses
  Core;

const
  Names: array[0..100] of string = ('Peter', 'Susan', 'Luis', 'Jane', 'Bill', 'Jeniffer',
    'Leo', 'Veronica', 'Stephan', 'Adele', 'Elvis', 'Caroline', 'John', 'Elisabeth',
    'Joseph', 'Michaele', 'Bruce', 'Eva', 'Samuel', 'Olivie', 'Fred', 'Maria',
    'Jose', 'David', 'Michael', 'Anna', 'Mary', 'Juan', 'Robert', 'Daniel', 'James',
    'Richard', 'Paul', 'Olga', 'William', 'Sergey', 'Anita', 'Victor', 'Sarah',
    'Mark', 'Rita', 'Martin', 'Patrick', 'Andrea', 'Vladimir', 'Barbara', 'Angela',
    'Ivan', 'Jesus', 'Marian', 'Eric', 'Diana', 'Claudia', 'Gloria', 'Teresa',
    'Francis', 'Andrew', 'Eduardo', 'Steven', 'Karen', 'Brian', 'Monica', 'Sonia',
    'Alberto', 'Alex', 'Julio', 'Juana', 'Adam', 'Kevin', 'Edward', 'Roland',
    'Cheng', 'Roman', 'Silvia', 'Marta', 'Lisa', 'Alice', 'Felix', 'Jan', 'Lucia',
    'Janet', 'Sharon', 'Paula', 'Helen', 'Anton', 'Henry', 'Antonia', 'Adriana',
    'Brenda', 'Nicole', 'Tatina', 'Gary', 'Dennis', 'Isaac', 'Luiz', 'Erika',
    'Amanda', 'Donald', 'Edgar', 'Ruben', 'Jason');

  LastNames: array[0..80] of string = ('Gates', 'Simmons', 'Eliott', 'Onion',
    'Presleys', 'Clinton', 'Dell', 'Ford', 'Miles', 'Young', 'Newton', 'Smith',
    'Williams', 'Johnson', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis',
    'Lopez', 'Wilson', 'Taylor', 'Moore', 'Jackson', 'Lee', 'White', 'Lewis',
    'Robinson', 'Walker', 'King', 'Wright', 'Scott', 'Torres', 'Green',
    'Adams', 'Nelson', 'Baker', 'Hall', 'Rivera', 'Carter', 'Evans', 'Diaz',
    'Collins', 'Edwards', 'Stewart', 'Murphy', 'Cook', 'Ortiz', 'Morgan', 'Cooper',
    'Peterson', 'Reed', 'Kim', 'Watson', 'Brooks', 'Wood', 'James', 'Gray',
    'Hughes', 'Long', 'Powell', 'Jenkins', 'Perry', 'Bell', 'Butler', 'Romero',
    'Jordan', 'Hamilton', 'Moreno', 'West', 'Cole', 'Hayes', 'Gibson', 'Medina',
    'Owens', 'Harrison', 'Woods', 'Wells', 'Chen', 'Webb', 'Tucker');

{ TFormGenerate }

procedure TFormGenerate.ButtonGenerateClick(Sender: TObject);
var
  I: Integer;
  Contact: TContact;
begin
  for I := 1 to SpinEditCount.Value do begin
    Contact := Contacts.AddNew;
    with Contact do begin
      Fields[cfVersion] := Core.Core.DefaultVcardVersion;
      Fields[cfFirstName] := Names[Random(Length(Names))];
      Fields[cfLastName] := LastNames[Random(Length(LastNames))];
      Fields[cfFullName] := Fields[cfFirstName] + ' ' +Fields[cfLastName];
      Fields[cfTelCell] := IntToStr(Random(1000000000));
      Fields[cfTelHome] := IntToStr(Random(1000000000));
      Fields[cfTelWork] := IntToStr(Random(1000000000));
      Fields[cfNote] := 'Some contact notes';
      Fields[cfEmail] := LowerCase(Fields[cfFirstName] + '.' + Fields[cfLastName]) + '@email.com';
      Fields[cfEmailHome] := Fields[cfEmail];
      Fields[cfEmailWork] := Fields[cfEmail];
      Fields[cfUrl] := 'https://url.com';
      Fields[cfUrlWork] := 'https://work.com';
      Fields[cfUrlHome] := 'https://home.com';
    end;
  end;
  Close;
  ModalResult := mrOk;
end;

procedure TFormGenerate.FormClose(Sender: TObject; var CloseAction: TCloseAction
  );
begin
  Core.Core.GenerateCount := SpinEditCount.Value;
end;

procedure TFormGenerate.FormShow(Sender: TObject);
begin
  SpinEditCount.Value := Core.Core.GenerateCount;
  UpdateInterface;
end;

procedure TFormGenerate.UpdateInterface;
begin
  ButtonGenerate.Enabled := Assigned(Contacts);
end;

end.

