| 1 | unit UFormFind;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
|---|
| 7 | ExtCtrls, StdCtrls, ActnList, Menus, UVCard, UFormContacts;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 |
|
|---|
| 11 | { TFormFind }
|
|---|
| 12 |
|
|---|
| 13 | TFormFind = class(TForm)
|
|---|
| 14 | ButtonFind: TButton;
|
|---|
| 15 | ComboBoxField: TComboBox;
|
|---|
| 16 | EditValue: TEdit;
|
|---|
| 17 | Label1: TLabel;
|
|---|
| 18 | Panel1: TPanel;
|
|---|
| 19 | procedure ButtonFindClick(Sender: TObject);
|
|---|
| 20 | procedure ComboBoxFieldChange(Sender: TObject);
|
|---|
| 21 | procedure EditValueKeyPress(Sender: TObject; var Key: char);
|
|---|
| 22 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 23 | procedure FormCreate(Sender: TObject);
|
|---|
| 24 | procedure FormDestroy(Sender: TObject);
|
|---|
| 25 | procedure FormShow(Sender: TObject);
|
|---|
| 26 | private
|
|---|
| 27 | FContacts: TContacts;
|
|---|
| 28 | FormContacts: TFormContacts;
|
|---|
| 29 | procedure SetContacts(AValue: TContacts);
|
|---|
| 30 | public
|
|---|
| 31 | ContactFieldIndex: TContactFieldIndex;
|
|---|
| 32 | procedure Find;
|
|---|
| 33 | property Contacts: TContacts read FContacts write SetContacts;
|
|---|
| 34 | end;
|
|---|
| 35 |
|
|---|
| 36 | var
|
|---|
| 37 | FormFind: TFormFind;
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | implementation
|
|---|
| 41 |
|
|---|
| 42 | {$R *.lfm}
|
|---|
| 43 |
|
|---|
| 44 | uses
|
|---|
| 45 | UCore;
|
|---|
| 46 |
|
|---|
| 47 | resourcestring
|
|---|
| 48 | SAny = 'Any';
|
|---|
| 49 |
|
|---|
| 50 | { TFormFind }
|
|---|
| 51 |
|
|---|
| 52 | procedure TFormFind.SetContacts(AValue: TContacts);
|
|---|
| 53 | var
|
|---|
| 54 | ContactField: TContactField;
|
|---|
| 55 | Items: TStringList;
|
|---|
| 56 | I: Integer;
|
|---|
| 57 | begin
|
|---|
| 58 | if FContacts = AValue then Exit;
|
|---|
| 59 | FContacts := AValue;
|
|---|
| 60 | if Assigned(FContacts) then begin
|
|---|
| 61 | Items := TStringList.Create;
|
|---|
| 62 | try
|
|---|
| 63 | TContact.GetFields.LoadToStrings(Items);
|
|---|
| 64 |
|
|---|
| 65 | // Remove fields which are not used in contacts
|
|---|
| 66 | for I := Items.Count - 1 downto 0 do
|
|---|
| 67 | if Contacts.CountByField(TContactField(Items.Objects[I]).Index) = 0 then
|
|---|
| 68 | Items.Delete(I);
|
|---|
| 69 |
|
|---|
| 70 | Items.InsertObject(0, SAny, nil);
|
|---|
| 71 | ComboBoxField.Items.Assign(Items);
|
|---|
| 72 | finally
|
|---|
| 73 | Items.Free;
|
|---|
| 74 | end;
|
|---|
| 75 | ContactField := TContact.GetFields.GetByIndex(ContactFieldIndex);
|
|---|
| 76 | ComboBoxField.ItemIndex := ComboBoxField.Items.IndexOfObject(ContactField);
|
|---|
| 77 | if (ComboBoxField.Items.Count > 0) and (ComboBoxField.ItemIndex = -1) then
|
|---|
| 78 | ComboBoxField.ItemIndex := 0;
|
|---|
| 79 | end else begin
|
|---|
| 80 | ComboBoxField.Clear;
|
|---|
| 81 | end;
|
|---|
| 82 | FormContacts.Contacts := Contacts;
|
|---|
| 83 | end;
|
|---|
| 84 |
|
|---|
| 85 | procedure TFormFind.Find;
|
|---|
| 86 | begin
|
|---|
| 87 | with FormContacts.FilterItems do begin
|
|---|
| 88 | Clear;
|
|---|
| 89 | if EditValue.Text <> '' then
|
|---|
| 90 | AddNew(ContactFieldIndex, EditValue.Text);
|
|---|
| 91 | end;
|
|---|
| 92 | FormContacts.ReloadList;
|
|---|
| 93 | FormContacts.UpdateInterface;
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | procedure TFormFind.FormCreate(Sender: TObject);
|
|---|
| 97 | begin
|
|---|
| 98 | Core.Translator.TranslateComponentRecursive(Self);
|
|---|
| 99 | Core.ThemeManager1.UseTheme(Self);
|
|---|
| 100 |
|
|---|
| 101 | ContactFieldIndex := cfNone;
|
|---|
| 102 |
|
|---|
| 103 | FormContacts := TFormContacts.Create(nil);
|
|---|
| 104 | FormContacts.ListViewFilter1.Visible := False;
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | procedure TFormFind.ComboBoxFieldChange(Sender: TObject);
|
|---|
| 108 | var
|
|---|
| 109 | ContactField: TContactField;
|
|---|
| 110 | begin
|
|---|
| 111 | if ComboBoxField.ItemIndex <> -1 then begin
|
|---|
| 112 | ContactField := TContactField(ComboBoxField.Items.Objects[ComboBoxField.ItemIndex]);
|
|---|
| 113 | if Assigned(ContactField) then
|
|---|
| 114 | ContactFieldIndex := ContactField.Index
|
|---|
| 115 | else ContactFieldIndex := cfNone;
|
|---|
| 116 | end else ContactFieldIndex := cfNone;
|
|---|
| 117 | Find;
|
|---|
| 118 | end;
|
|---|
| 119 |
|
|---|
| 120 | procedure TFormFind.EditValueKeyPress(Sender: TObject; var Key: char);
|
|---|
| 121 | begin
|
|---|
| 122 | if Key = #13 then Find;
|
|---|
| 123 | end;
|
|---|
| 124 |
|
|---|
| 125 | procedure TFormFind.ButtonFindClick(Sender: TObject);
|
|---|
| 126 | begin
|
|---|
| 127 | Find;
|
|---|
| 128 | end;
|
|---|
| 129 |
|
|---|
| 130 | procedure TFormFind.FormClose(Sender: TObject;
|
|---|
| 131 | var CloseAction: TCloseAction);
|
|---|
| 132 | begin
|
|---|
| 133 | Core.PersistentForm1.Save(Self);
|
|---|
| 134 | end;
|
|---|
| 135 |
|
|---|
| 136 | procedure TFormFind.FormDestroy(Sender: TObject);
|
|---|
| 137 | begin
|
|---|
| 138 | FreeAndNil(FormContacts);
|
|---|
| 139 | end;
|
|---|
| 140 |
|
|---|
| 141 | procedure TFormFind.FormShow(Sender: TObject);
|
|---|
| 142 | begin
|
|---|
| 143 | Core.PersistentForm1.Load(Self);
|
|---|
| 144 |
|
|---|
| 145 | FormContacts.ManualDock(Self, nil, alClient);
|
|---|
| 146 | FormContacts.Align := alClient;
|
|---|
| 147 | FormContacts.Show;
|
|---|
| 148 |
|
|---|
| 149 | Find;
|
|---|
| 150 | end;
|
|---|
| 151 |
|
|---|
| 152 | end.
|
|---|
| 153 |
|
|---|