TvPlanIt: Fix leaving orphan events, tasks and contacts in an ini datastore when a resource is deleted.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8952 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-12 14:22:23 +00:00
parent ad75d24647
commit 6852677f7c

View File

@ -33,6 +33,10 @@ type
procedure StrToResource(AString: String; AResource: TVpResource);
procedure StrToTask(AString: String; ATask: TVpTask);
procedure InternalPurgeContacts(Res: TVpResource); override;
procedure InternalPurgeEvents(Res: TVpResource); override;
procedure InternalPurgeTasks(Res: TVpResource); override;
procedure SetConnected(const AValue: Boolean); override;
function UniqueID(AValue: Integer): Boolean;
@ -52,6 +56,7 @@ type
procedure PostEvents; override;
procedure PostResources; override;
procedure PostTasks; override;
procedure PurgeResource(Res: TVpResource); override;
procedure SetResourceByName(Value: String); override;
published
@ -362,6 +367,21 @@ begin
until UniqueID(Result) and (Result <> -1);
end;
procedure TVpIniDataStore.InternalPurgeContacts(Res: TVpResource);
begin
Res.Contacts.ClearContacts;
end;
procedure TVpIniDataStore.InternalPurgeEvents(Res: TVpResource);
begin
Res.Schedule.ClearEvents;
end;
procedure TVpIniDataStore.InternalPurgeTasks(Res: TVpResource);
begin
Res.Tasks.ClearTasks;
end;
function TVpIniDatastore.UniqueID(AValue: Integer): Boolean;
var
i, j: Integer;
@ -568,6 +588,15 @@ begin
RefreshTasks;
end;
procedure TVpIniDataStore.PurgeResource(Res: TVpResource);
begin
PurgeEvents(Res);
PurgeContacts(Res);
PurgeTasks(Res);
Res.Deleted := true;
inherited PurgeResource(Res);
end;
procedure TVpIniDatastore.StrToContact(AString: String; AContact: TVpContact);
var
L: TVpIniStrings;
@ -1262,31 +1291,40 @@ begin
for i:=0 to Resources.Count-1 do begin
res := Resources.Items[i];
key := Format('Contacts of resource %d', [res.ResourceID]);
for j:=0 to res.Contacts.Count-1 do begin
contact := res.Contacts.GetContact(j);
if not contact.Deleted then
ini.WriteString(key, IntToStr(contact.RecordID), ContactToStr(contact));
if not res.Deleted then
begin
key := Format('Contacts of resource %d', [res.ResourceID]);
for j:=0 to res.Contacts.Count-1 do begin
contact := res.Contacts.GetContact(j);
if not contact.Deleted then
ini.WriteString(key, IntToStr(contact.RecordID), ContactToStr(contact));
end;
end;
end;
for i:=0 to Resources.Count-1 do begin
res := Resources.Items[i];
key := Format('Tasks of resource %d', [res.ResourceID]);
for j:=0 to res.Tasks.Count-1 do begin
task := res.Tasks.GetTask(j);
if not task.Deleted then
ini.WriteString(key, IntToStr(task.RecordID), TaskToStr(task));
if not res.Deleted then
begin
key := Format('Tasks of resource %d', [res.ResourceID]);
for j:=0 to res.Tasks.Count-1 do begin
task := res.Tasks.GetTask(j);
if not task.Deleted then
ini.WriteString(key, IntToStr(task.RecordID), TaskToStr(task));
end;
end;
end;
for i:=0 to Resources.Count-1 do begin
res := Resources.Items[i];
key := Format('Events of resource %d', [res.ResourceID]);
for j:=0 to res.Schedule.EventCount-1 do begin
event := res.Schedule.GetEvent(j);
if not event.Deleted then
ini.WriteString(key, IntToStr(event.RecordID), EventToStr(event));
if not res.Deleted then
begin
key := Format('Events of resource %d', [res.ResourceID]);
for j:=0 to res.Schedule.EventCount-1 do begin
event := res.Schedule.GetEvent(j);
if not event.Deleted then
ini.WriteString(key, IntToStr(event.RecordID), EventToStr(event));
end;
end;
end;