tvplanit: Fix VpFlexDatastore mapping issues and extend GetFieldName so that field mappings are needed only for differing field names. Both changes proposed by DonAlfredo (http://forum.lazarus.freepascal.org/index.php/topic,32918.msg212813.html#msg212813).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4735 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-06-13 09:28:07 +00:00
parent e76bce0df3
commit 9a1cfcd5f8

View File

@ -1110,11 +1110,11 @@ begin
begin begin
FResourceDataSrc.DataSet.Open; FResourceDataSrc.DataSet.Open;
FN := GetFieldName(FEventMappings, 'ResourceID'); // FN := GetFieldName(FEventMappings, 'ResourceID');
FN := GetFieldName(FResourceMappings, 'ResourceID');
if (FN <> '') and FResourceDataSrc.DataSet.Locate(FN, Resource.ResourceID, []) if (FN <> '') and FResourceDataSrc.DataSet.Locate(FN, Resource.ResourceID, [])
then begin then begin
SetFilterCriteria(FEventsDataSrc.DataSet, False, Resource.ResourceID, SetFilterCriteria(FEventsDataSrc.DataSet, False, Resource.ResourceID, 0, 0);
0, 0);
for J := pred(Resource.Schedule.EventCount) downto 0 do begin for J := pred(Resource.Schedule.EventCount) downto 0 do begin
Event := Resource.Schedule.GetEvent(J); Event := Resource.Schedule.GetEvent(J);
@ -1536,7 +1536,8 @@ begin
begin begin
FResourceDataSrc.DataSet.Open; FResourceDataSrc.DataSet.Open;
if FResourceDataSrc.DataSet.Active then begin if FResourceDataSrc.DataSet.Active then begin
FN := GetFieldName(FTaskMappings, 'ResourceID'); // FN := GetFieldName(FTaskMappings, 'ResourceID');
FN := GetFieldName(FResourceMappings, 'ResourceID');
{ Dump this resource's dirty contacts to the DB } { Dump this resource's dirty contacts to the DB }
if not FResourceDataSrc.DataSet.Locate(FN, Resource.ResourceID, []) then if not FResourceDataSrc.DataSet.Locate(FN, Resource.ResourceID, []) then
Exit; Exit;
@ -2069,8 +2070,7 @@ var
begin begin
I := 0; I := 0;
result := ''; result := '';
while (I < Mappings.Count) while (I < Mappings.Count) and (result = '') do begin
and (result = '') do begin
FM := TVpFieldMapping(Mappings.Items[I]); FM := TVpFieldMapping(Mappings.Items[I]);
if Uppercase(FM.VPField) = Uppercase(VPField) then begin if Uppercase(FM.VPField) = Uppercase(VPField) then begin
result := FM.DBField; result := FM.DBField;
@ -2079,32 +2079,45 @@ begin
Inc(I); Inc(I);
end; end;
end; end;
*) *)
{ returns the name of the dataset field currently mapped to the } { returns the name of the dataset field currently mapped to the }
{ specified internal Visual PlanIt field. If not field is mapped, } { specified internal Visual PlanIt field. If not field is mapped, }
{ then it returns the Visual PlanIt field name } { then it returns the Visual PlanIt field name, but if the field }
function TVpFlexDataStore.GetFieldName(Mappings: TCollection; { is not available in the database it returns an empty string. }
VPField: string): string; function TVpFlexDataStore.GetFieldName(Mappings: TCollection;
var VPField: string): string;
I: integer;
FM: TVpFieldMapping; function FieldAvail(AFieldName: String; ADataset: TDataset): Boolean;
begin begin
I := 0; Result := ADataset.FieldDefs.IndexOf(AFieldName) > -1;
result := ''; end;
if Mappings.Count = 0 then
Result := VpField var
else I: integer;
while (I < Mappings.Count) and (result = '') do begin FM: TVpFieldMapping;
FM := TVpFieldMapping(Mappings.Items[I]); begin
if Uppercase(FM.VPField) = Uppercase(VPField) then begin // Use PlanIt field name as default, i.e. mappings only required for fields
result := FM.DBField; // with different names.
break; result := VpField;
end; I := 0;
Inc(I); while (I < Mappings.Count) do begin
FM := TVpFieldMapping(Mappings.Items[I]);
if Uppercase(FM.VPField) = Uppercase(VPField) then begin
Result := FM.DBField;
break;
end; end;
end; Inc(I);
{=====} end;
// Make sure that non-existing fields are identified by an empty return string
if ((Mappings = FResourceMappings) and not FieldAvail(Result, ResourceTable)) or
((Mappings = FContactMappings) and not FieldAvail(Result, ContactsTable)) or
((Mappings = FEventMappings) and not FieldAvail(Result, EventsTable)) or
((Mappings = FTaskMappings) and not FieldAvail(Result, TasksTable))
then
Result := '';
end;
{=====}
procedure TVpFlexDataStore.SetFilterCriteria(aTable: TDataset; procedure TVpFlexDataStore.SetFilterCriteria(aTable: TDataset;
aUseDateTime: Boolean; aResourceID: Integer; aStartDateTime, aUseDateTime: Boolean; aResourceID: Integer; aStartDateTime,