Extraer seleccionados: Mejorado el sistema de localización de las filas seleccionadas. Se usa la columna internar 'RecID' para identificar de manera única una tupla en vez de usar el campo 'ID', que no siempre existe en una tabla.

git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@493 0c75b7a4-871f-7646-8a2f-f78d34cc349f
This commit is contained in:
David Arranz 2008-07-31 18:11:26 +00:00
parent e9a6941c8b
commit e40cf73e67
2 changed files with 17 additions and 10 deletions

View File

@ -106,7 +106,7 @@ function TSelectedRecords.CurrentRow: integer;
begin begin
if not FDataTable.Active then if not FDataTable.Active then
raise EDatabaseError.Create(sDataSetClosed); raise EDatabaseError.Create(sDataSetClosed);
Result := FDataTable.FieldByName('ID').AsInteger; Result := FDataTable.GetRowRecIDValue;
end; end;
function TSelectedRecords.GetCurrentRowSelected: Boolean; function TSelectedRecords.GetCurrentRowSelected: Boolean;
@ -158,7 +158,8 @@ function TSelectedRecords.LocateItem(const Index: Integer) : Boolean;
begin begin
if not FDataTable.Active then if not FDataTable.Active then
raise EDatabaseError.Create(sDataSetClosed); raise EDatabaseError.Create(sDataSetClosed);
Result := FDataTable.Locate('ID', Items[Index], []); Result := FDataTable.Locate(FDataTable.RecIDField.FieldName, Items[Index], []);
end; end;

View File

@ -60,8 +60,8 @@ procedure CopyDataTableDA5(ASource : TDADataTable; ATarget: TDADataTable;
var var
DABin: Binary; DABin: Binary;
DADataStreamer : TDABin2DataStreamer; DADataStreamer : TDABin2DataStreamer;
AFilter : String;
AFiltered : Boolean; AFiltered : Boolean;
AFilter : String;
AObj : ISeleccionable; AObj : ISeleccionable;
i : Integer; i : Integer;
begin begin
@ -73,6 +73,12 @@ begin
if not Supports(ASource, ISeleccionable, aObj) then if not Supports(ASource, ISeleccionable, aObj) then
raise Exception.Create('El origen de datos no soporta la interfaz ISeleccionable (CopyDataTable)'); raise Exception.Create('El origen de datos no soporta la interfaz ISeleccionable (CopyDataTable)');
{ Si la tabla está abierta, la cerramos antes de aplicar los filtros
porque por cada cambio en el filtro se hacen llamadas internas de TDADataTable. }
if ASource.Active then
ASource.Close;
// Si la tabla origen viene con un filtro, lo guardamos para luego restablecerlo.
if ASource.Filtered then if ASource.Filtered then
begin begin
AFiltered := True; AFiltered := True;
@ -81,19 +87,18 @@ begin
end; end;
ASource.Filter := ''; ASource.Filter := '';
// if ASource.Active then
// ASource.Close;
//Si no hay elemento seleccionados filtramos para que ATarget se quede vacia //Si no hay elemento seleccionados filtramos para que ATarget se quede vacia
if (AObj.SelectedRecords.Count = 0) then if (AObj.SelectedRecords.Count = 0) then
ASource.Filter := ASource.Filter + '(ID = ' + IntToStr(ID_NULO) + ')' ASource.Filter := ASource.Filter + '(' + ASource.RecIDField.FieldName + ' = ' + IntToStr(ID_NULO) + ')'
//En caso contrario filtramos por los elementos seleccionados //En caso contrario filtramos por los elementos seleccionados
else else
for i := 0 to AObj.SelectedRecords.Count - 1 do for i := 0 to AObj.SelectedRecords.Count - 1 do
begin begin
if (i > 0) then if (i > 0) then
ASource.Filter := ASource.Filter + ' or '; ASource.Filter := ASource.Filter + ' or ';
ASource.Filter := ASource.Filter + '(ID = ' + IntToStr(AObj.SelectedRecords.Items[i]) + ')'; ASource.Filter := ASource.Filter + '(' + ASource.RecIDField.FieldName + ' = ' + IntToStr(AObj.SelectedRecords.Items[i]) + ')';
end; end;
ASource.Filtered := True; ASource.Filtered := True;
end; end;
@ -108,8 +113,9 @@ begin
ATarget.LogicalName := ASource.LogicalName; // We need to specify new dataset LogicalName ATarget.LogicalName := ASource.LogicalName; // We need to specify new dataset LogicalName
ATarget.RemoteFetchEnabled := False; // "Desconectamos" la tabla destino del servidor ATarget.RemoteFetchEnabled := False; // "Desconectamos" la tabla destino del servidor
// if not ASource.Active then if not ASource.Active then
// ASource.Open; ASource.Open;
ASource.First; ASource.First;
DADataStreamer.WriteDataset(DABin, ASource, [woRows, woSchema], -1); DADataStreamer.WriteDataset(DABin, ASource, [woRows, woSchema], -1);
@ -459,7 +465,7 @@ begin
else else
begin begin
ATarget.First; ATarget.First;
if not ATarget.Locate('ID', ASource.FieldByName('ID').AsVariant, []) then if not ATarget.Locate(ATarget.RecIDField.FieldName, ASource.GetRowRecIDValue, []) then
DuplicarRegistro(ASource, ATarget, WithPKKey, WithFKKey); DuplicarRegistro(ASource, ATarget, WithPKKey, WithFKKey);
end; end;