tvplanit: Fix deleting of records from ini datastore.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4849 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-06-28 09:36:30 +00:00
parent dac023e5ee
commit 9f385a2fb1
2 changed files with 50 additions and 16 deletions

View File

@ -93,9 +93,9 @@ end;
function TVpIniDatastore.ContactToStr(AContact: TVpContact): String; function TVpIniDatastore.ContactToStr(AContact: TVpContact): String;
begin begin
Result := '{' + // RecordID is stored in ini value name. Result := '{' + // RecordID is stored in ini value name.
AContact.FirstName + '{|}' + AContact.FirstName + '}|{' +
AContact.LastName + '{|}' + AContact.LastName + '}|{' +
FormatDateTime('ddddd', AContact.BirthDate, FFormatSettings) + '{|}' + // Short date format FormatDateTime('ddddd', AContact.BirthDate, FFormatSettings) + '}|{' + // Short date format
FormatDateTime('ddddd', AContact.Anniversary, FFormatSettings) + '}|{' + FormatDateTime('ddddd', AContact.Anniversary, FFormatSettings) + '}|{' +
AContact.Title + '}|{' + AContact.Title + '}|{' +
AContact.Company + '}|{' + AContact.Company + '}|{' +
@ -337,13 +337,33 @@ begin
end; end;
procedure TVpIniDatastore.PostContacts; procedure TVpIniDatastore.PostContacts;
var
i: Integer;
contact: TVpContact;
begin begin
// Nothing to do... if Resource = nil then
exit;
for i := Resource.Contacts.Count-1 downto 0 do begin
contact := Resource.Contacts.GetContact(i);
if contact.Deleted then
contact.Free;
end;
RefreshContacts;
end; end;
procedure TVpIniDatastore.PostEvents; procedure TVpIniDatastore.PostEvents;
var
i: Integer;
event: TVpEvent;
begin begin
// Nothing to do ... if Resource = nil then
exit;
for i := Resource.Schedule.EventCount-1 downto 0 do begin
event := Resource.Schedule.GetEvent(i);
if event.Deleted then
event.Free;
end;
RefreshEvents;
end; end;
procedure TVpIniDatastore.PostResources; procedure TVpIniDatastore.PostResources;
@ -352,8 +372,18 @@ begin
end; end;
procedure TVpIniDatastore.PostTasks; procedure TVpIniDatastore.PostTasks;
var
i: Integer;
task: TVpTask;
begin begin
// Nothing to do... if Resource = nil then
exit;
for i := Resource.Tasks.Count-1 downto 0 do begin
task := Resource.Tasks.GetTask(i);
if task.Deleted then
task.Free;
end;
RefreshTasks;
end; end;
procedure TVpIniDatastore.StrToContact(AString: String; AContact: TVpContact); procedure TVpIniDatastore.StrToContact(AString: String; AContact: TVpContact);
@ -534,7 +564,7 @@ begin
s := ini.ReadString('Resources', ResList[i], ''); s := ini.ReadString('Resources', ResList[i], '');
if s = '' then if s = '' then
IniError(RSIniFileStructure); IniError(RSIniFileStructure);
resID := StrToInt(ResList[i]); resID := StrToInt64(ResList[i]);
res := Resources.AddResource(resID); res := Resources.AddResource(resID);
StrToResource(s, res); StrToResource(s, res);
@ -542,7 +572,7 @@ begin
L.Clear; L.Clear;
ini.ReadSection(key, L); ini.ReadSection(key, L);
for j:=0 to L.Count-1 do begin for j:=0 to L.Count-1 do begin
id := StrToInt(L[j]); id := StrToInt64(L[j]);
contact := res.Contacts.AddContact(id); contact := res.Contacts.AddContact(id);
s := ini.ReadString(key, L[j], ''); s := ini.ReadString(key, L[j], '');
StrToContact(s, contact); StrToContact(s, contact);
@ -553,7 +583,7 @@ begin
L.Clear; L.Clear;
ini.ReadSection(key, L); ini.ReadSection(key, L);
for j:=0 to L.Count-1 do begin for j:=0 to L.Count-1 do begin
id := StrToInt(L[j]); id := StrToInt64(L[j]);
event := res.Schedule.AddEvent(id, 0, 1); event := res.Schedule.AddEvent(id, 0, 1);
s := ini.ReadString(key, L[j], ''); s := ini.ReadString(key, L[j], '');
StrToEvent(s, event); StrToEvent(s, event);
@ -563,7 +593,7 @@ begin
L.Clear; L.Clear;
ini.ReadSection(key, L); ini.ReadSection(key, L);
for j:=0 to L.Count-1 do begin for j:=0 to L.Count-1 do begin
id := StrToInt(L[j]); id := StrToInt64(L[j]);
task := res.Tasks.AddTask(id); task := res.Tasks.AddTask(id);
s := ini.ReadString(key, L[j], ''); s := ini.ReadString(key, L[j], '');
StrToTask(s, task); StrToTask(s, task);
@ -595,7 +625,8 @@ begin
for i:=0 to Resources.Count-1 do begin for i:=0 to Resources.Count-1 do begin
res := Resources.Items[i]; res := Resources.Items[i];
ini.WriteString('Resources', IntToStr(res.ResourceID), ResourceToStr(res)); if not res.Deleted then
ini.WriteString('Resources', IntToStr(res.ResourceID), ResourceToStr(res));
end; end;
for i:=0 to Resources.Count-1 do begin for i:=0 to Resources.Count-1 do begin
@ -603,7 +634,8 @@ begin
key := Format('ContactsOfResource%d', [res.ResourceID]); key := Format('ContactsOfResource%d', [res.ResourceID]);
for j:=0 to res.Contacts.Count-1 do begin for j:=0 to res.Contacts.Count-1 do begin
contact := res.Contacts.GetContact(i); contact := res.Contacts.GetContact(i);
ini.WriteString(key, IntToStr(contact.RecordID), ContactToStr(contact)); if not contact.Deleted then
ini.WriteString(key, IntToStr(contact.RecordID), ContactToStr(contact));
end; end;
end; end;
@ -612,7 +644,8 @@ begin
key := Format('TasksOfResource%d', [res.ResourceID]); key := Format('TasksOfResource%d', [res.ResourceID]);
for j:=0 to res.Tasks.Count-1 do begin for j:=0 to res.Tasks.Count-1 do begin
task := res.Tasks.GetTask(i); task := res.Tasks.GetTask(i);
ini.WriteString(key, IntToStr(task.RecordID), TaskToStr(task)); if not task.Deleted then
ini.WriteString(key, IntToStr(task.RecordID), TaskToStr(task));
end; end;
end; end;
@ -621,7 +654,8 @@ begin
key := Format('EventsOfResource%d', [res.ResourceID]); key := Format('EventsOfResource%d', [res.ResourceID]);
for j:=0 to res.Schedule.EventCount-1 do begin for j:=0 to res.Schedule.EventCount-1 do begin
event := res.Schedule.GetEvent(j); event := res.Schedule.GetEvent(j);
ini.WriteString(key, IntToStr(event.RecordID), EventToStr(event)); if not event.Deleted then
ini.WriteString(key, IntToStr(event.RecordID), EventToStr(event));
end; end;
end; end;

View File

@ -75,8 +75,8 @@ type
TVpResourceEditDialog = class(TVpBaseDialog) TVpResourceEditDialog = class(TVpBaseDialog)
protected {private} protected {private}
reEditDlg : TResEditForm; reEditDlg: TResEditForm;
reResource : TVpResource; reResource: TVpResource;
function Show: Boolean; function Show: Boolean;
public public
function Execute: Boolean; reintroduce; function Execute: Boolean; reintroduce;