2008-02-03 12:05:55 +00:00
|
|
|
{*********************************************************}
|
|
|
|
{* VPCONTACTEDITDLG.PAS 1.03 *}
|
|
|
|
{*********************************************************}
|
|
|
|
|
|
|
|
{* ***** BEGIN LICENSE BLOCK ***** *}
|
|
|
|
{* Version: MPL 1.1 *}
|
|
|
|
{* *}
|
|
|
|
{* The contents of this file are subject to the Mozilla Public License *}
|
|
|
|
{* Version 1.1 (the "License"); you may not use this file except in *}
|
|
|
|
{* compliance with the License. You may obtain a copy of the License at *}
|
|
|
|
{* http://www.mozilla.org/MPL/ *}
|
|
|
|
{* *}
|
|
|
|
{* Software distributed under the License is distributed on an "AS IS" basis, *}
|
|
|
|
{* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License *}
|
|
|
|
{* for the specific language governing rights and limitations under the *}
|
|
|
|
{* License. *}
|
|
|
|
{* *}
|
|
|
|
{* The Original Code is TurboPower Visual PlanIt *}
|
|
|
|
{* *}
|
|
|
|
{* The Initial Developer of the Original Code is TurboPower Software *}
|
|
|
|
{* *}
|
|
|
|
{* Portions created by TurboPower Software Inc. are Copyright (C) 2002 *}
|
|
|
|
{* TurboPower Software Inc. All Rights Reserved. *}
|
|
|
|
{* *}
|
|
|
|
{* Contributor(s): *}
|
|
|
|
{* *}
|
|
|
|
{* ***** END LICENSE BLOCK ***** *}
|
|
|
|
|
|
|
|
{$I Vp.INC}
|
|
|
|
|
|
|
|
unit VpContactEditDlg;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF LCL}
|
2016-06-22 07:59:17 +00:00
|
|
|
LCLProc, LCLType, LCLIntf, LResources,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ELSE}
|
2016-06-22 07:59:17 +00:00
|
|
|
Windows, Messages,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
2016-06-22 07:59:17 +00:00
|
|
|
SysUtils,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$IFDEF VERSION6} Variants, {$ENDIF}
|
|
|
|
Classes, Graphics, Controls, Forms, Dialogs, VpData, ExtCtrls, StdCtrls,
|
2016-07-12 18:00:32 +00:00
|
|
|
VpException, VpMisc, VpBase, VpSR, VpDlg, VpBaseDS, ComCtrls, EditBtn;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
{ forward declarations }
|
|
|
|
TVpContactEditDialog = class;
|
|
|
|
|
2016-06-28 19:50:19 +00:00
|
|
|
{ TContactEditForm }
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
TContactEditForm = class(TForm)
|
2016-06-29 11:02:25 +00:00
|
|
|
BirthdateEdit: TDateEdit;
|
|
|
|
BirthdateLbl: TLabel;
|
2016-06-28 19:50:19 +00:00
|
|
|
FirstNameEdit: TEdit;
|
|
|
|
FirstNameLbl: TLabel;
|
2008-02-03 12:05:55 +00:00
|
|
|
tsContacts: TPageControl;
|
|
|
|
tabMain: TTabSheet;
|
2016-06-28 19:50:19 +00:00
|
|
|
LastNameLbl: TLabel;
|
2008-02-03 12:05:55 +00:00
|
|
|
AddrLbl: TLabel;
|
|
|
|
CityLbl: TLabel;
|
|
|
|
StateLbl: TLabel;
|
|
|
|
ZipLbl: TLabel;
|
|
|
|
CountryLbl: TLabel;
|
|
|
|
PositionLbl: TLabel;
|
|
|
|
TitleLbl: TLabel;
|
|
|
|
CompanyLbl: TLabel;
|
2016-06-28 19:50:19 +00:00
|
|
|
LastNameEdit: TEdit;
|
2008-02-03 12:05:55 +00:00
|
|
|
AddressEdit: TEdit;
|
|
|
|
CityEdit: TEdit;
|
|
|
|
StateEdit: TEdit;
|
|
|
|
ZipCodeEdit: TEdit;
|
|
|
|
PositionEdit: TEdit;
|
|
|
|
TitleEdit: TEdit;
|
|
|
|
CompanyEdit: TEdit;
|
|
|
|
cboxCategory: TComboBox;
|
|
|
|
cboxCountry: TComboBox;
|
|
|
|
cboxState: TComboBox;
|
|
|
|
edtCountry: TEdit;
|
|
|
|
tabContact: TTabSheet;
|
|
|
|
tabCustom: TTabSheet;
|
|
|
|
pnlBottom: TPanel;
|
|
|
|
OKBtn: TButton;
|
|
|
|
CancelBtn: TButton;
|
|
|
|
tabNotes: TTabSheet;
|
|
|
|
NoteEdit: TMemo;
|
|
|
|
CustomLbl1: TLabel;
|
|
|
|
CustomLbl2: TLabel;
|
|
|
|
CustomLbl3: TLabel;
|
|
|
|
CustomLbl4: TLabel;
|
|
|
|
Custom1Edit: TEdit;
|
|
|
|
Custom2Edit: TEdit;
|
|
|
|
Custom3Edit: TEdit;
|
|
|
|
Custom4Edit: TEdit;
|
|
|
|
cboxPhoneLbl1: TComboBox;
|
|
|
|
cboxPhoneLbl2: TComboBox;
|
|
|
|
cboxPhoneLbl3: TComboBox;
|
|
|
|
cboxPhoneLbl4: TComboBox;
|
|
|
|
Phone4Edit: TEdit;
|
|
|
|
Phone3Edit: TEdit;
|
|
|
|
Phone2Edit: TEdit;
|
|
|
|
Phone1Edit: TEdit;
|
|
|
|
cboxPhoneLbl5: TComboBox;
|
|
|
|
Phone5Edit: TEdit;
|
|
|
|
EMailLbl: TLabel;
|
|
|
|
EMailEdit: TEdit;
|
|
|
|
CategoryLbl: TLabel;
|
2016-07-14 12:20:59 +00:00
|
|
|
procedure cboxCountryChange(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure CancelBtnClick(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
2016-06-28 22:49:33 +00:00
|
|
|
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure FormShow(Sender: TObject);
|
2016-07-14 12:20:59 +00:00
|
|
|
procedure OKBtnClick(Sender: TObject);
|
|
|
|
procedure ItemChanged(Sender: TObject);
|
|
|
|
procedure tsContactsChange(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
private
|
|
|
|
procedure SetCaptions;
|
|
|
|
procedure DisplayCurrentCountry;
|
|
|
|
procedure ResizeControls;
|
|
|
|
public
|
2016-06-18 21:03:53 +00:00
|
|
|
Resource: TVpResource;
|
|
|
|
Contact: TVpContact;
|
|
|
|
ReturnCode: TVpEditorReturnCode;
|
|
|
|
ControlLink: TVpControlLink;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure PopulateSelf;
|
|
|
|
procedure DePopulateSelf;
|
|
|
|
procedure ArrangeControls;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TVpContactEditDialog = class(TVpBaseDialog)
|
|
|
|
protected {private}
|
2016-06-18 21:03:53 +00:00
|
|
|
ceEditDlg: TContactEditForm;
|
|
|
|
ceContact: TVpContact;
|
|
|
|
ceResource: TVpResource;
|
2008-02-03 12:05:55 +00:00
|
|
|
public
|
|
|
|
function Execute(Contact: TVpContact): Boolean; reintroduce;
|
|
|
|
function AddNewContact: Boolean;
|
|
|
|
published
|
|
|
|
{properties}
|
|
|
|
property ControlLink;
|
|
|
|
property DataStore;
|
|
|
|
property Placement;
|
|
|
|
end;
|
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
implementation
|
|
|
|
|
2016-06-07 16:34:18 +00:00
|
|
|
{$IFDEF LCL}
|
|
|
|
{$R *.lfm}
|
|
|
|
{$ELSE}
|
|
|
|
{$R *.dfm}
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
uses
|
|
|
|
VpConst;
|
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
{ Utility functions }
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
function Max(const a, b: Integer): Integer;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if a >= b then
|
|
|
|
Result := a
|
|
|
|
else
|
|
|
|
Result := b;
|
|
|
|
end;
|
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
|
|
|
|
{ TContactEditForm }
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
procedure TContactEditForm.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ReturnCode := rtAbandon;
|
|
|
|
SetCaptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.SetCaptions;
|
|
|
|
begin
|
2016-06-10 14:45:43 +00:00
|
|
|
tabMain.Caption := RSMasterData;
|
|
|
|
tabContact.Caption := RSDlgContactEdit;
|
|
|
|
tabCustom.Caption := RSCustom;
|
|
|
|
tabNotes.Caption := RSNotes;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
OkBtn.Caption := RSOKBtn;
|
|
|
|
CancelBtn.Caption := RSCancelBtn;
|
2016-06-28 19:50:19 +00:00
|
|
|
LastNameLbl.Caption := RSLastNameLbl;
|
|
|
|
FirstNameLbl.Caption := RSFirstNameLbl;
|
2008-02-03 12:05:55 +00:00
|
|
|
TitleLbl.Caption := RSTitleLbl;
|
|
|
|
AddrLbl.Caption := RSAddressLbl;
|
|
|
|
CityLbl.Caption := RSCityLbl;
|
|
|
|
StateLbl.Caption := RSStateLbl;
|
|
|
|
ZipLbl.Caption := RSZipCodeLbl;
|
|
|
|
CountryLbl.Caption := RSCountryLbl;
|
|
|
|
CompanyLbl.Caption := RSCompanyLbl;
|
|
|
|
PositionLbl.Caption := RSPositionLbl;
|
|
|
|
CategoryLbl.Caption := RSCategoryLbl;
|
2016-06-29 11:02:25 +00:00
|
|
|
BirthdateLbl.Caption := RSBirthDateLbl;
|
2008-02-03 12:05:55 +00:00
|
|
|
EmailLbl.Caption := RSEmail;
|
|
|
|
CustomLbl1.Caption := RSCustom1;
|
|
|
|
CustomLbl2.Caption := RSCustom2;
|
|
|
|
CustomLbl3.Caption := RSCustom3;
|
|
|
|
CustomLbl4.Caption := RSCustom4;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.OKBtnClick(Sender: TObject);
|
|
|
|
begin
|
2016-06-28 19:50:19 +00:00
|
|
|
if LastNameEdit.Text = '' then begin
|
2008-02-03 12:05:55 +00:00
|
|
|
raise EVpContactEditError.Create(RSNameIsRequired);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
ReturnCode := rtCommit;
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.CancelBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ReturnCode := rtAbandon;
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.DePopulateSelf;
|
|
|
|
begin
|
2016-06-28 19:50:19 +00:00
|
|
|
// ParseName(Contact, LastNameEdit.Text);
|
|
|
|
Contact.LastName := LastNameEdit.Text;
|
|
|
|
Contact.FirstName := FirstNameEdit.Text;
|
2008-02-03 12:05:55 +00:00
|
|
|
Contact.Address := AddressEdit.Text;
|
|
|
|
Contact.City := CityEdit.Text;
|
|
|
|
if cboxState.Visible then
|
|
|
|
Contact.State := cboxState.Text
|
|
|
|
else
|
|
|
|
Contact.State := StateEdit.Text;
|
|
|
|
Contact.Zip := ZipCodeEdit.Text;
|
2016-06-12 12:53:26 +00:00
|
|
|
Contact.Job_Position := PositionEdit.Text;
|
2008-02-03 12:05:55 +00:00
|
|
|
Contact.Title := TitleEdit.Text;
|
|
|
|
Contact.EMail := EMailEdit.Text;
|
|
|
|
Contact.Company := CompanyEdit.Text;
|
2016-06-29 11:02:25 +00:00
|
|
|
Contact.Birthdate := BirthdateEdit.Date;
|
2008-02-03 12:05:55 +00:00
|
|
|
Contact.Phone1 := Phone1Edit.Text;
|
|
|
|
Contact.Phone2 := Phone2Edit.Text;
|
|
|
|
Contact.Phone3 := Phone3Edit.Text;
|
|
|
|
Contact.Phone4 := Phone4Edit.Text;
|
|
|
|
Contact.Phone5 := Phone5Edit.Text;
|
|
|
|
if cboxCountry.Visible then
|
|
|
|
Contact.Country := cboxCountry.Text
|
|
|
|
else
|
|
|
|
Contact.Country := edtCountry.Text;
|
2016-06-12 12:53:26 +00:00
|
|
|
Contact.Notes := NoteEdit.Text;
|
2008-02-03 12:05:55 +00:00
|
|
|
Contact.Category := cboxCategory.ItemIndex;
|
|
|
|
Contact.Custom1 := Custom1Edit.Text;
|
|
|
|
Contact.Custom2 := Custom2Edit.Text;
|
|
|
|
Contact.Custom3 := Custom3Edit.Text;
|
|
|
|
Contact.Custom4 := Custom4Edit.Text;
|
|
|
|
|
|
|
|
Contact.PhoneType1 := cboxPhoneLbl1.ItemIndex;
|
|
|
|
Contact.PhoneType2 := cboxPhoneLbl2.ItemIndex;
|
|
|
|
Contact.PhoneType3 := cboxPhoneLbl3.ItemIndex;
|
|
|
|
Contact.PhoneType4 := cboxPhoneLbl4.ItemIndex;
|
|
|
|
Contact.PhoneType5 := cboxPhoneLbl5.ItemIndex;
|
|
|
|
|
|
|
|
Contact.Category := cboxCategory.ItemIndex;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.PopulateSelf;
|
|
|
|
var
|
2016-06-18 21:03:53 +00:00
|
|
|
CurCountry: Integer;
|
|
|
|
pt: TVpPhoneType;
|
|
|
|
ct: TVpCategoryType;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
begin
|
2016-06-28 19:50:19 +00:00
|
|
|
LastNameEdit.Text := Contact.LastName;
|
|
|
|
FirstNameEdit.Text := Contact.FirstName; //AssembleName(Contact);
|
2008-02-03 12:05:55 +00:00
|
|
|
AddressEdit.Text := Contact.Address;
|
|
|
|
CityEdit.Text := Contact.City;
|
|
|
|
ZipCodeEdit.Text := Contact.Zip;
|
2016-06-12 12:53:26 +00:00
|
|
|
PositionEdit.Text := Contact.Job_Position;
|
2008-02-03 12:05:55 +00:00
|
|
|
TitleEdit.Text := Contact.Title;
|
|
|
|
EMailEdit.Text := Contact.EMail;
|
|
|
|
CompanyEdit.Text := Contact.Company;
|
|
|
|
Phone1Edit.Text := Contact.Phone1;
|
|
|
|
Phone2Edit.Text := Contact.Phone2;
|
|
|
|
Phone3Edit.Text := Contact.Phone3;
|
|
|
|
Phone4Edit.Text := Contact.Phone4;
|
|
|
|
Phone5Edit.Text := Contact.Phone5;
|
2016-06-12 12:53:26 +00:00
|
|
|
NoteEdit.Text := Contact.Notes;
|
2008-02-03 12:05:55 +00:00
|
|
|
cboxCategory.ItemIndex := Contact.Category;
|
|
|
|
Custom1Edit.Text := Contact.Custom1;
|
|
|
|
Custom2Edit.Text := Contact.Custom2;
|
|
|
|
Custom3Edit.Text := Contact.Custom3;
|
|
|
|
Custom4Edit.Text := Contact.Custom4;
|
|
|
|
cboxCountry.Text := Contact.Country;
|
|
|
|
edtCountry.Text := Contact.Country;
|
|
|
|
if (Contact.Country = '') and (Assigned (ControlLink)) then begin
|
|
|
|
if ControlLink.DefaultCountry <> '' then begin
|
|
|
|
cboxCountry.Text := ControlLink.DefaultCountry;
|
|
|
|
edtCountry.Text := ControlLink.DefaultCountry;
|
|
|
|
end else begin
|
|
|
|
CurCountry := ControlLink.Localization.GetCurrentCountry;
|
|
|
|
if CurCountry >= 0 then begin
|
|
|
|
cboxCountry.Text := ControlLink.Localization.Countries.Items[CurCountry].Name;
|
|
|
|
edtCountry.Text := ControlLink.Localization.Countries.Items[CurCountry].Name;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
StateEdit.Text := Contact.State;
|
|
|
|
cboxState.Text := Contact.State;
|
2016-06-29 11:02:25 +00:00
|
|
|
if Contact.Birthdate = 0.0 then
|
|
|
|
BirthdateEdit.Clear else
|
|
|
|
BirthdateEdit.Date := Contact.Birthdate;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
for pt := Low (TVpPhoneType) to High (TVpPhoneType) do begin
|
|
|
|
cboxPhoneLbl1.Items.Add(PhoneLabel(pt));
|
|
|
|
cboxPhoneLbl2.Items.Add(PhoneLabel(pt));
|
|
|
|
cboxPhoneLbl3.Items.Add(PhoneLabel(pt));
|
|
|
|
cboxPhoneLbl4.Items.Add(PhoneLabel(pt));
|
|
|
|
cboxPhoneLbl5.Items.Add(PhoneLabel(pt));
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
cboxPhoneLbl1.ItemIndex := Contact.PhoneType1;
|
|
|
|
cboxPhoneLbl2.ItemIndex := Contact.PhoneType2;
|
|
|
|
cboxPhoneLbl3.ItemIndex := Contact.PhoneType3;
|
|
|
|
cboxPhoneLbl4.ItemIndex := Contact.PhoneType4;
|
|
|
|
cboxPhoneLbl5.ItemIndex := Contact.PhoneType5;
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
for ct := Low (TVpCategoryType) to High (TVpCategoryType) do
|
|
|
|
cboxCategory.Items.Add(CategoryLabel(ct));
|
2008-02-03 12:05:55 +00:00
|
|
|
cboxCategory.ItemIndex := Contact.Category;
|
|
|
|
|
|
|
|
DisplayCurrentCountry;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.ItemChanged(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Contact.Changed := true;
|
|
|
|
|
2016-06-28 19:50:19 +00:00
|
|
|
{ if there is a comma in the LastNameEdit, then it is assumed that the name is }
|
2008-02-03 12:05:55 +00:00
|
|
|
{ formatted as last, first. Since the comma & space aren't actually part of }
|
|
|
|
{ the name, we need to allow two extra characters in the namefield's width. }
|
2016-06-28 19:50:19 +00:00
|
|
|
if Pos(',', LastNameEdit.Text) > 0 then
|
|
|
|
LastNameEdit.MaxLength := 102
|
2008-02-03 12:05:55 +00:00
|
|
|
else
|
2016-06-28 19:50:19 +00:00
|
|
|
LastNameEdit.MaxLength := 100;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.ArrangeControls;
|
|
|
|
begin
|
|
|
|
edtCountry.Left := cboxCountry.Left;
|
|
|
|
StateEdit.Left := cboxState.Left;
|
|
|
|
|
|
|
|
if (not Assigned (ControlLink)) or
|
|
|
|
(ControlLink.Localization.Countries.Count = 0) then begin
|
|
|
|
edtCountry.Visible := True;
|
|
|
|
CountryLbl.FocusControl := edtCountry;
|
|
|
|
cboxCountry.Visible := False;
|
|
|
|
StateEdit.Visible := True;
|
|
|
|
StateLbl.FocusControl := StateEdit;
|
|
|
|
cboxState.Visible := False;
|
|
|
|
end
|
|
|
|
else begin
|
2016-06-18 21:03:53 +00:00
|
|
|
ControlLink.Localization.CountriesToTStrings(cboxCountry.Items);
|
2008-02-03 12:05:55 +00:00
|
|
|
CountryLbl.FocusControl := cboxCountry;
|
|
|
|
cboxCountry.Visible := True;
|
|
|
|
edtCountry.Visible := False;
|
|
|
|
StateLbl.FocusControl := cboxState;
|
|
|
|
cboxState.Visible := True;
|
|
|
|
StateEdit.Visible := False;
|
|
|
|
end;
|
|
|
|
tsContacts.ActivePage := tabMain;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.ResizeControls;
|
|
|
|
const
|
|
|
|
ComboArrowWidth = 32;
|
2016-07-13 23:23:40 +00:00
|
|
|
// FieldVertSep = 25;
|
2016-06-28 22:49:33 +00:00
|
|
|
// FormRightBorder = 20;
|
|
|
|
// MinFormWidth = 265;
|
|
|
|
// FormHeightOffset = 103;
|
|
|
|
// MinFormHeight = 250;
|
2016-06-08 13:54:27 +00:00
|
|
|
TopField = 8;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
type
|
2016-06-28 22:49:33 +00:00
|
|
|
TLabelArray = array of TLabel;
|
|
|
|
TComboboxArray = array of TCombobox;
|
|
|
|
TEditArray = array of TEdit;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
var
|
2016-06-18 21:03:53 +00:00
|
|
|
Labels: TLabelArray;
|
2016-06-28 22:49:33 +00:00
|
|
|
Comboboxes: TComboboxArray;
|
|
|
|
Edits: TEditArray;
|
2016-07-13 23:23:40 +00:00
|
|
|
LargestLabelWidth: Integer;
|
2016-06-18 21:03:53 +00:00
|
|
|
WidestField: Integer;
|
|
|
|
i, j: Integer;
|
|
|
|
OldFont: TFont;
|
|
|
|
FieldTop: Integer;
|
|
|
|
delta: Integer;
|
2016-06-28 22:49:33 +00:00
|
|
|
corr: Integer; // difference between form's client width and tabsheet width
|
2016-07-13 23:23:40 +00:00
|
|
|
editHeight: Integer; // Height of an edit control
|
2016-07-14 09:40:54 +00:00
|
|
|
vDist: Integer; // Vertical distance between edits
|
|
|
|
hBorder: Integer; // Distance between container border and label
|
|
|
|
dist: Integer; // distance between label and edit/combo
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
begin
|
2016-07-14 09:40:54 +00:00
|
|
|
dist := round(4 * Screen.PixelsPerInch / DesignTimeDPI);
|
|
|
|
vdist := round(2 * Screen.PixelsPerInch / DesignTimeDPI);
|
|
|
|
hBorder := round(8 * Screen.PixelsPerInch / DesignTimeDPI);
|
|
|
|
editHeight := LastNameEdit.Height * Screen.PixelsPerInch div DesignTimeDPI;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
{ Note: The resizing algorithm is dependent upon the labels having their
|
|
|
|
FocusControl property set to the corresponding edit field or combobox. }
|
|
|
|
|
2016-06-29 11:02:25 +00:00
|
|
|
SetLength(Labels, 12);
|
2016-06-28 19:50:19 +00:00
|
|
|
Labels[0] := LastNameLbl;
|
|
|
|
Labels[1] := FirstNameLbl;
|
|
|
|
Labels[2] := TitleLbl;
|
|
|
|
Labels[3] := AddrLbl;
|
|
|
|
Labels[4] := CityLbl;
|
|
|
|
Labels[5] := StateLbl;
|
|
|
|
Labels[6] := ZipLbl;
|
|
|
|
Labels[7] := CountryLbl;
|
|
|
|
Labels[8] := CompanyLbl;
|
|
|
|
Labels[9] := PositionLbl;
|
|
|
|
Labels[10] := CategoryLbl;
|
2016-06-29 11:02:25 +00:00
|
|
|
Labels[11] := BirthdateLbl;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-07-13 23:23:40 +00:00
|
|
|
LargestLabelWidth := 0;
|
2008-02-03 12:05:55 +00:00
|
|
|
for i := Low(Labels) to High(Labels) do
|
2016-07-13 23:23:40 +00:00
|
|
|
LargestLabelWidth := Max(LargestLabelWidth, GetLabelWidth(Labels[i]));
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
{ Determine width of label based upon whether large or small fonts are
|
2008-02-03 12:05:55 +00:00
|
|
|
in effect. }
|
|
|
|
for i := Low(Labels) to High(Labels) do begin
|
2016-07-14 12:20:59 +00:00
|
|
|
Labels[i].FocusControl.Left := HBorder + LargestLabelWidth + Dist;
|
2016-07-13 23:23:40 +00:00
|
|
|
Labels[i].Left := Labels[i].FocusControl.Left - DIST - GetLabelWidth(Labels[i]);
|
|
|
|
Labels[i].Top := Labels[i].FocusControl.Top + (Labels[i].FocusControl.Height - Labels[i].Height) div 2;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
widestField := 250;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
{ If localization file is loaded determine the width of the country and state
|
|
|
|
comboboxes }
|
|
|
|
if cboxCountry.Visible or cboxState.Visible then begin
|
2008-02-03 12:05:55 +00:00
|
|
|
OldFont := TFont.Create;
|
|
|
|
try
|
2016-06-08 13:54:27 +00:00
|
|
|
OldFont.Assign(Canvas.Font);
|
2016-06-28 22:49:33 +00:00
|
|
|
|
|
|
|
if cboxCountry.Visible then begin
|
|
|
|
Canvas.Font.Assign(cboxCountry.Font);
|
|
|
|
for j := 0 to cboxCountry.Items.Count - 1 do
|
|
|
|
widestField := Max(widestField, Canvas.TextWidth(cboxCountry.Items[j]) + ComboArrowWidth);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if cboxState.Visible then begin
|
|
|
|
Canvas.Font.Assign(cboxCountry.Font);
|
|
|
|
for j := 0 to cboxState.Items.Count - 1 do
|
|
|
|
widestField := Max(widestfield, Canvas.TextWidth(cboxState.Items[j]) + ComboArrowWidth);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
finally
|
2016-06-28 22:49:33 +00:00
|
|
|
Canvas.Font.Assign(OldFont);
|
2008-02-03 12:05:55 +00:00
|
|
|
OldFont.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
{ Set form width according to widest field }
|
|
|
|
corr := ClientWidth - tabMain.ClientWidth;
|
2016-07-14 12:20:59 +00:00
|
|
|
ClientWidth := LastNameEdit.Left + widestfield + HBorder + corr;
|
2016-06-28 22:49:33 +00:00
|
|
|
|
|
|
|
{ Set edit and combo widths }
|
|
|
|
for i:= Low(Labels) to High(Labels) do
|
2016-06-29 11:02:25 +00:00
|
|
|
if (Labels[i].FocusControl <> ZipCodeEdit) and
|
|
|
|
(Labels[i].FocusControl <> BirthdateEdit)
|
|
|
|
then
|
2016-06-28 22:49:33 +00:00
|
|
|
Labels[i].FocusControl.Width := widestfield;
|
|
|
|
cboxCountry.Width := widestField;
|
|
|
|
cboxState.Width := widestField;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
{ Vertically arrange the fields. }
|
2016-06-08 13:54:27 +00:00
|
|
|
delta := (Labels[0].FocusControl.Height - labels[0].Height) div 2;
|
2008-02-03 12:05:55 +00:00
|
|
|
FieldTop := TopField;
|
|
|
|
for i := Low(Labels) to High(Labels) do
|
|
|
|
if Labels[i].Visible then begin
|
|
|
|
Labels[i].FocusControl.Top := FieldTop;
|
2016-06-08 13:54:27 +00:00
|
|
|
Labels[i].Top := FieldTop + delta;
|
2016-07-14 12:20:59 +00:00
|
|
|
inc(FieldTop, editHeight + VDist);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
{ Set form height such that first tab is filled completely by controls }
|
2016-06-29 11:02:25 +00:00
|
|
|
ClientHeight := BirthdateEdit.Top + BirthdateEdit.Height + TopField +
|
2016-06-28 20:08:51 +00:00
|
|
|
pnlBottom.Height + tsContacts.Height - tabMain.Height;
|
2016-06-10 14:45:43 +00:00
|
|
|
|
2016-06-28 22:49:33 +00:00
|
|
|
{ Page "Contact" }
|
|
|
|
SetLength(Comboboxes, 5);
|
|
|
|
Comboboxes[0] := cboxPhoneLbl1;
|
|
|
|
Comboboxes[1] := cboxPhoneLbl2;
|
|
|
|
Comboboxes[2] := cboxPhoneLbl3;
|
|
|
|
Comboboxes[3] := cboxPhoneLbl4;
|
|
|
|
Comboboxes[4] := cboxPhoneLbl5;
|
|
|
|
|
|
|
|
SetLength(Edits, 5);
|
|
|
|
Edits[0] := Phone1Edit;
|
|
|
|
Edits[1] := Phone2Edit;
|
|
|
|
Edits[2] := Phone3Edit;
|
|
|
|
Edits[3] := Phone4Edit;
|
|
|
|
Edits[4] := Phone5Edit;
|
|
|
|
|
2016-07-13 23:23:40 +00:00
|
|
|
largestLabelWidth := GetLabelWidth(EMailLbl);
|
2016-06-28 22:49:33 +00:00
|
|
|
OldFont := TFont.Create;
|
|
|
|
try
|
|
|
|
OldFont.Assign(Canvas.Font);
|
|
|
|
Canvas.Font.Assign(cboxPhoneLbl1.Font);
|
|
|
|
for i:=0 to cboxPhoneLbl1.Items.Count-1 do
|
2016-07-13 23:23:40 +00:00
|
|
|
largestLabelWidth := Max(cboxPhoneLbl1.Canvas.TextWidth(cboxPhoneLbl1.Items[i]) + ComboArrowWidth, largestlabelWidth);
|
2016-06-28 22:49:33 +00:00
|
|
|
finally
|
|
|
|
Canvas.Font.Assign(OldFont);
|
|
|
|
OldFont.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
FieldTop := TopField;
|
|
|
|
for i:=Low(Comboboxes) to High(Comboboxes) do begin
|
2016-07-14 12:20:59 +00:00
|
|
|
Comboboxes[i].Left := HBorder;
|
2016-07-13 23:23:40 +00:00
|
|
|
Comboboxes[i].Width := largestLabelWidth;
|
2016-06-28 22:49:33 +00:00
|
|
|
Comboboxes[i].Top := FieldTop;
|
2016-07-14 12:20:59 +00:00
|
|
|
inc(FieldTop, editHeight + VDist);
|
2016-06-28 22:49:33 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
for i:= Low(Edits) to High(Edits) do begin
|
|
|
|
Edits[i].Left := cboxPhoneLbl1.Left + cboxPhoneLbl1.Width + DIST;
|
2016-07-14 12:20:59 +00:00
|
|
|
Edits[i].Width := ClientWidth - Edits[i].Left - HBorder - corr;
|
2016-06-28 22:49:33 +00:00
|
|
|
Edits[i].Top := Comboboxes[i].Top;
|
|
|
|
end;
|
|
|
|
|
|
|
|
EMailEdit.Left := Phone1Edit.Left;
|
|
|
|
EMailEdit.Width := Phone1Edit.Width;
|
2016-07-14 12:20:59 +00:00
|
|
|
EMailEdit.Top := Phone5Edit.Top + editHeight + VDist;
|
|
|
|
EMailLbl.Left := EMailEdit.Left - GetLabelWidth(EMailLbl) - Dist;
|
2016-06-28 22:49:33 +00:00
|
|
|
EMailLbl.Top := EMailEdit.Top + delta;
|
|
|
|
|
|
|
|
{ Page "User-defined" }
|
|
|
|
SetLength(Labels, 4);
|
|
|
|
Labels[0] := CustomLbl1;
|
|
|
|
Labels[1] := CustomLbl2;
|
|
|
|
Labels[2] := CustomLbl3;
|
|
|
|
Labels[3] := CustomLbl4;
|
|
|
|
|
2016-07-13 23:23:40 +00:00
|
|
|
largestLabelWidth := 0;
|
2016-06-28 22:49:33 +00:00
|
|
|
for i := Low(Labels) to High(Labels) do
|
2016-07-13 23:23:40 +00:00
|
|
|
largestLabelWidth := Max(largestLabelWidth, GetLabelWidth(Labels[i]));
|
2016-06-28 22:49:33 +00:00
|
|
|
|
|
|
|
FieldTop := TopField;
|
|
|
|
for i := Low(Labels) to High(Labels) do begin
|
2016-07-14 12:20:59 +00:00
|
|
|
Labels[i].FocusControl.Left := HBorder + LargestLabelWidth + Dist;
|
2016-06-28 22:49:33 +00:00
|
|
|
Labels[i].FocusControl.Top := FieldTop;
|
2016-07-14 12:20:59 +00:00
|
|
|
Labels[i].FocusControl.Width := ClientWidth - Labels[i].FocusControl.Left - HBorder - corr;
|
2016-07-13 23:23:40 +00:00
|
|
|
Labels[i].Width := LargestLabelWidth;
|
2016-07-14 12:20:59 +00:00
|
|
|
Labels[i].Left := Labels[i].FocusControl.Left - GetLabelWidth(Labels[i]) - Dist;
|
2016-06-28 22:49:33 +00:00
|
|
|
Labels[i].Top := FieldTop + delta;
|
2016-07-14 12:20:59 +00:00
|
|
|
inc(FieldTop, editHeight + VDist);
|
2016-06-28 22:49:33 +00:00
|
|
|
end;
|
2016-07-14 12:20:59 +00:00
|
|
|
|
|
|
|
OKBtn.Width := Max(GetButtonWidth(OKBtn), GetButtonWidth(CancelBtn));
|
|
|
|
CancelBtn.Width := OKBtn.Width;
|
|
|
|
CancelBtn.Left := pnlBottom.ClientWidth - HBorder - CancelBtn.Width;
|
|
|
|
OKBtn.Left := CancelBtn.Left - Dist - OKBtn.Width;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.DisplayCurrentCountry;
|
|
|
|
var
|
|
|
|
Idx : Integer;
|
|
|
|
begin
|
2016-06-18 21:03:53 +00:00
|
|
|
if not Assigned(ControlLink) then
|
2008-02-03 12:05:55 +00:00
|
|
|
Exit;
|
|
|
|
|
2016-06-18 21:03:53 +00:00
|
|
|
Idx := ControlLink.Localization.CountryNameToIndex(cboxCountry.Text);
|
2008-02-03 12:05:55 +00:00
|
|
|
if Idx > -1 then begin
|
2016-06-18 21:03:53 +00:00
|
|
|
ControlLink.Localization.StatesToTStrings(Idx, cboxState.Items);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].Address1Visible then begin
|
|
|
|
AddrLbl.Visible := True;
|
|
|
|
AddressEdit.Visible := True;
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].Address1Caption <> '' then
|
|
|
|
AddrLbl.Caption := ControlLink.Localization.Countries.Items[Idx].Address1Caption
|
|
|
|
else
|
2016-06-28 22:49:33 +00:00
|
|
|
AddrLbl.Caption := RSAddressLbl;
|
2008-02-03 12:05:55 +00:00
|
|
|
end else begin
|
|
|
|
AddrLbl.Visible := False;
|
|
|
|
AddressEdit.Visible := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].CityVisible then begin
|
|
|
|
CityLbl.Visible := True;
|
|
|
|
CityEdit.Visible := True;
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].CityCaption <> '' then
|
|
|
|
CityLbl.Caption := ControlLink.Localization.Countries.Items[Idx].CityCaption
|
|
|
|
else
|
2016-06-28 22:49:33 +00:00
|
|
|
CityLbl.Caption := RSCityLbl;
|
2008-02-03 12:05:55 +00:00
|
|
|
end else begin
|
|
|
|
CityLbl.Visible := False;
|
|
|
|
CityEdit.Visible := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].StatesVisible then begin
|
|
|
|
StateLbl.Visible := True;
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].States.Count > 0 then begin
|
|
|
|
StateLbl.FocusControl := cboxState;
|
|
|
|
cboxState.Visible := True;
|
|
|
|
StateEdit.Visible := False;
|
|
|
|
end else begin
|
|
|
|
StateLbl.FocusControl := StateEdit;
|
|
|
|
StateEdit.Visible := True;
|
|
|
|
cboxState.Visible := False;
|
|
|
|
StateEdit.Left := cboxState.Left;
|
|
|
|
end;
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].StateCaption <> '' then
|
|
|
|
StateLbl.Caption := ControlLink.Localization.Countries.Items[Idx].StateCaption
|
|
|
|
else
|
2016-06-28 22:49:33 +00:00
|
|
|
StateLbl.Caption := RSStateLbl;
|
2008-02-03 12:05:55 +00:00
|
|
|
end else begin
|
|
|
|
StateLbl.Visible := False;
|
|
|
|
StateEdit.Visible := False;
|
|
|
|
cboxState.Visible := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].ZipVisible then begin
|
|
|
|
ZipLbl.Visible := True;
|
|
|
|
ZipCodeEdit.Visible := True;
|
|
|
|
if ControlLink.Localization.Countries.Items[Idx].ZipCaption <> '' then
|
|
|
|
ZipLbl.Caption := ControlLink.Localization.Countries.Items[Idx].ZipCaption
|
|
|
|
else
|
2016-06-28 22:49:33 +00:00
|
|
|
ZipLbl.Caption := RSZipCodeLbl;
|
2008-02-03 12:05:55 +00:00
|
|
|
end else begin
|
|
|
|
ZipLbl.Visible := False;
|
|
|
|
ZipCodeEdit.Visible := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end else begin
|
|
|
|
cboxState.Items.Clear;
|
|
|
|
|
|
|
|
end;
|
|
|
|
ResizeControls;
|
|
|
|
end;
|
2016-06-28 19:50:19 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure TContactEditForm.cboxCountryChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
StateEdit.Text := '';
|
|
|
|
cboxState.Text := '';
|
|
|
|
DisplayCurrentCountry;
|
|
|
|
end;
|
2016-06-28 22:49:33 +00:00
|
|
|
|
|
|
|
procedure TContactEditForm.FormKeyDown(Sender: TObject; var Key: Word;
|
|
|
|
Shift: TShiftState);
|
|
|
|
begin
|
2016-07-12 18:00:32 +00:00
|
|
|
Unused(Shift);
|
2016-06-28 22:49:33 +00:00
|
|
|
if Key = VK_ESCAPE then begin
|
|
|
|
ReturnCode := rtAbandon;
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.tsContactsChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if Visible then
|
|
|
|
if tsContacts.ActivePage = tabMain then
|
|
|
|
LastNameEdit.SetFocus
|
|
|
|
else if tsContacts.ActivePage = tabContact then
|
|
|
|
Phone1Edit.SetFocus
|
|
|
|
else if tsContacts.ActivePage = tabCustom then
|
|
|
|
Custom1Edit.SetFocus
|
|
|
|
else if tsContacts.ActivePage = tabNotes then
|
|
|
|
NoteEdit.SetFocus;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TContactEditForm.FormShow(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if tsContacts.ActivePage = tabMain then
|
|
|
|
LastNameEdit.SetFocus;
|
2016-07-14 09:40:54 +00:00
|
|
|
(*
|
|
|
|
{$IFDEF LCL}
|
|
|
|
ScaleDPI(Self, DesigntimeDPI);
|
|
|
|
{$ENDIF}
|
|
|
|
*)
|
2016-06-28 22:49:33 +00:00
|
|
|
end;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
{ TVpContactEditDialog }
|
|
|
|
|
|
|
|
function TVpContactEditDialog.Execute(Contact: TVpContact): Boolean;
|
|
|
|
var
|
|
|
|
EditForm: TContactEditForm;
|
|
|
|
begin
|
|
|
|
ceContact := Contact;
|
|
|
|
Result := false;
|
|
|
|
Application.CreateForm(TContactEditForm, EditForm);
|
|
|
|
try
|
|
|
|
DoFormPlacement(EditForm);
|
|
|
|
SetFormCaption(EditForm, Contact.FullName, RSDlgContactEdit);
|
|
|
|
EditForm.Contact := ceContact;
|
|
|
|
EditForm.Resource := DataStore.Resource;
|
|
|
|
EditForm.ControlLink := ControlLink;
|
|
|
|
EditForm.ArrangeControls;
|
|
|
|
EditForm.PopulateSelf;
|
|
|
|
EditForm.ShowModal;
|
|
|
|
if EditForm.ReturnCode = rtCommit then begin
|
|
|
|
EditForm.DePopulateSelf;
|
|
|
|
Result := true;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
EditForm.Release;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Result then begin
|
|
|
|
ceContact.Changed := true;
|
|
|
|
DataStore.PostContacts;
|
|
|
|
DataStore.NotifyDependents;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TVpContactEditDialog.AddNewContact: Boolean;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
if DataStore <> nil then begin
|
|
|
|
if DataStore.Resource = nil then
|
|
|
|
Exit;
|
|
|
|
ceContact := DataStore.Resource.Contacts.AddContact(
|
|
|
|
DataStore.GetNextID(ContactsTableName));
|
|
|
|
if ceContact <> nil then begin
|
|
|
|
Result := Execute(ceContact);
|
|
|
|
if Result then
|
|
|
|
DataStore.PostContacts
|
|
|
|
else
|
|
|
|
ceContact.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2008-02-08 15:07:26 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
end.
|
|
|
|
|
|
|
|
|