2021-12-04 12:06:23 +00:00
|
|
|
{ Basic Visual PlanIt datastore using an flat files, such as ini, xml or json }
|
|
|
|
|
|
|
|
{$IF FPC_FullVersion >= 30200}
|
|
|
|
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined}
|
|
|
|
{$IFEND}
|
|
|
|
|
2022-06-07 16:29:20 +00:00
|
|
|
{$I vp.inc}
|
2021-12-04 12:06:23 +00:00
|
|
|
|
|
|
|
unit VpFileDS;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2021-12-06 22:34:33 +00:00
|
|
|
VpData, VpBaseDS;
|
2021-12-04 12:06:23 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
TVpCustomFileDataStore = class(TVpCustomDataStore)
|
|
|
|
private
|
|
|
|
protected
|
|
|
|
public
|
2021-12-06 22:34:33 +00:00
|
|
|
procedure RefreshEvents; override;
|
|
|
|
procedure UngroupEvents; virtual;
|
|
|
|
procedure UpdateGroupEvents; override;
|
2021-12-04 12:06:23 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2021-12-06 22:34:33 +00:00
|
|
|
procedure TVpCustomFileDataStore.RefreshEvents;
|
|
|
|
begin
|
|
|
|
UpdateGroupEvents;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpCustomFileDataStore.UngroupEvents;
|
|
|
|
var
|
|
|
|
i, j: Integer;
|
|
|
|
res: TVpResource;
|
|
|
|
event, newEvent: TVpEvent;
|
|
|
|
eventRes: TVpResource;
|
|
|
|
begin
|
|
|
|
for i := 0 to Resources.Count-1 do
|
|
|
|
begin
|
|
|
|
res := Resources.Items[i];
|
|
|
|
for j := res.Schedule.EventCount-1 downto 0 do
|
|
|
|
begin
|
|
|
|
event := res.Schedule.GetEvent(j);
|
|
|
|
if event.IsOverlayed then
|
|
|
|
begin
|
|
|
|
eventRes := Resources.GetResource(event.ResourceID);
|
|
|
|
newEvent := event.CopyToSchedule(eventres.Schedule);
|
|
|
|
newEvent.ResourceID := eventRes.ResourceID;
|
|
|
|
event.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Iterates through all events and moves them to the resource as specified by the
|
|
|
|
resource groups. }
|
|
|
|
procedure TVpCustomFileDataStore.UpdateGroupEvents;
|
|
|
|
var
|
|
|
|
i, j, k: Integer;
|
|
|
|
res, gres: TVpResource;
|
|
|
|
event, newevent: TVpEvent;
|
|
|
|
begin
|
|
|
|
UngroupEvents;
|
|
|
|
|
|
|
|
for i := 0 to Resources.Count-1 do
|
|
|
|
begin
|
|
|
|
res := Resources.Items[i];
|
|
|
|
if res.Group <> nil then begin
|
|
|
|
for j := 0 to res.Group.Count-1 do
|
|
|
|
begin
|
|
|
|
gres := res.Group.Items[j];
|
|
|
|
for k := gres.Schedule.EventCount-1 downto 0 do
|
|
|
|
begin
|
|
|
|
event := gres.Schedule.GetEvent(k);
|
|
|
|
if event.ResourceID = gres.ResourceID then
|
|
|
|
begin
|
|
|
|
newEvent := event.CopyToSchedule(res.Schedule);
|
|
|
|
newEvent.ResourceID := event.ResourceID;
|
|
|
|
event.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2021-12-04 12:06:23 +00:00
|
|
|
end.
|