Changeset 73 for trunk/UCore.pas
- Timestamp:
- Dec 13, 2021, 11:33:11 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r72 r73 11 11 12 12 type 13 14 { TMergeResult }15 16 TMergeResult = record17 Loaded: Integer;18 New: Integer;19 Updated: Integer;20 procedure Clear;21 class operator Add(const A, B: TMergeResult): TMergeResult;22 end;23 13 24 14 { TCore } … … 30 20 AGenerate: TAction; 31 21 AFindDuplicate: TAction; 32 AFile Merge: TAction;22 AFileCombine: TAction; 33 23 ASettings: TAction; 34 24 AFileOpenRecent: TAction; … … 53 43 procedure AAboutExecute(Sender: TObject); 54 44 procedure AExitExecute(Sender: TObject); 55 procedure AFile MergeExecute(Sender: TObject);45 procedure AFileCombineExecute(Sender: TObject); 56 46 procedure AFileNewExecute(Sender: TObject); 57 47 procedure AFileOpenExecute(Sender: TObject); … … 95 85 procedure FileOpen(FileName: string); 96 86 procedure FileClose; 97 function FileMerge(FileName: string): TMergeResult;98 87 procedure Initialize; 99 88 procedure UpdateInterface; … … 118 107 SFileSplitFinishedOpenDirectory = 'Total %d contact files saved. Do you want to open the directory %s?'; 119 108 SFileNotFound = 'File ''%s'' not found.'; 120 S MergedContacts = 'Contacts merged. Loaded: %d, New: %d, Updated: %d';109 SCombinedContacts = 'Combined %d contact files.'; 121 110 SLine = 'Line %d: %s'; 122 111 123 { TMergeResult }124 125 procedure TMergeResult.Clear;126 begin127 Loaded := 0;128 New := 0;129 Updated := 0;130 end;131 132 class operator TMergeResult.Add(const A, B: TMergeResult): TMergeResult;133 begin134 Result.Loaded := A.Loaded + B.Loaded;135 Result.New := A.New + B.New;136 Result.Updated := A.Updated + B.Updated;137 end;138 139 112 { TCore } 140 113 … … 144 117 end; 145 118 146 procedure TCore.AFile MergeExecute(Sender: TObject);119 procedure TCore.AFileCombineExecute(Sender: TObject); 147 120 var 148 121 TempFile: TDataFile; 149 122 I: Integer; 150 MergeResult: TMergeResult; 151 TotalMergeResult: TMergeResult; 123 LoadedFiles: Integer; 152 124 begin 153 125 TempFile := DefaultDataFileClass.Create; … … 164 136 OpenDialog1.Options := OpenDialog1.Options + [ofAllowMultiSelect]; 165 137 if OpenDialog1.Execute then begin 166 TotalMergeResult.Clear;138 LoadedFiles := 0; 167 139 for I := 0 to OpenDialog1.Files.Count - 1 do begin 168 MergeResult := FileMerge(OpenDialog1.Files[I]); 169 TotalMergeResult := TotalMergeResult + MergeResult; 140 if FileExists(OpenDialog1.Files[I]) then begin 141 TempFile := TContactsFile.Create; 142 try 143 TempFile.LoadFromFile(OpenDialog1.Files[I]); 144 TContactsFile(DataFile).Contacts.AddContacts(TContactsFile(TempFile).Contacts); 145 Inc(LoadedFiles); 146 finally 147 TempFile.Free; 148 end; 149 end; 170 150 end; 171 ShowMessage(Format(SMergedContacts, [TotalMergeResult.Loaded,172 TotalMergeResult.New, TotalMergeResult.Updated]));151 if LoadedFiles > 0 then TContactsFile(DataFile).Modified := True; 152 ShowMessage(Format(SCombinedContacts, [LoadedFiles])); 173 153 UpdateFile; 174 154 end; … … 411 391 end; 412 392 413 function TCore.FileMerge(FileName: string): TMergeResult;414 var415 TempFile: TContactsFile;416 NewContact: TContact;417 I: Integer;418 begin419 Result.Clear;420 if FileExists(FileName) then begin421 TempFile := TContactsFile.Create;422 try423 TempFile.LoadFromFile(FileName);424 Result.Loaded := TempFile.Contacts.Count;425 for I := 0 to TempFile.Contacts.Count - 1 do begin426 NewContact := TContactsFile(DataFile).Contacts.Search(TempFile.Contacts[I].Fields[cfFullName]);427 if not Assigned(NewContact) then begin428 NewContact := TContact.Create;429 NewContact.Assign(TempFile.Contacts[I]);430 NewContact.Parent := TContactsFile(DataFile);431 TContactsFile(DataFile).Contacts.Add(NewContact);432 Inc(Result.New);433 end else begin434 if NewContact.UpdateFrom(TempFile.Contacts[I]) then435 Inc(Result.Updated);436 end;437 end;438 TContactsFile(DataFile).Modified := True;439 finally440 TempFile.Free;441 end;442 end else ShowMessage(Format(SFileNotFound, [FileName]));443 end;444 445 393 procedure TCore.FileNew; 446 394 begin … … 540 488 AFileClose.Enabled := Assigned(DataFile); 541 489 AFileSplit.Enabled := Assigned(DataFile); 542 AFile Merge.Enabled := Assigned(DataFile);490 AFileCombine.Enabled := Assigned(DataFile); 543 491 AFindDuplicate.Enabled := Assigned(DataFile); 544 492 AGenerate.Enabled := Assigned(DataFile);
Note:
See TracChangeset
for help on using the changeset viewer.