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

View File

@ -60,8 +60,8 @@ procedure CopyDataTableDA5(ASource : TDADataTable; ATarget: TDADataTable;
var
DABin: Binary;
DADataStreamer : TDABin2DataStreamer;
AFilter : String;
AFiltered : Boolean;
AFilter : String;
AObj : ISeleccionable;
i : Integer;
begin
@ -73,6 +73,12 @@ begin
if not Supports(ASource, ISeleccionable, aObj) then
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
begin
AFiltered := True;
@ -81,19 +87,18 @@ begin
end;
ASource.Filter := '';
// if ASource.Active then
// ASource.Close;
//Si no hay elemento seleccionados filtramos para que ATarget se quede vacia
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
else
for i := 0 to AObj.SelectedRecords.Count - 1 do
begin
if (i > 0) then
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;
ASource.Filtered := True;
end;
@ -108,8 +113,9 @@ begin
ATarget.LogicalName := ASource.LogicalName; // We need to specify new dataset LogicalName
ATarget.RemoteFetchEnabled := False; // "Desconectamos" la tabla destino del servidor
// if not ASource.Active then
// ASource.Open;
if not ASource.Active then
ASource.Open;
ASource.First;
DADataStreamer.WriteDataset(DABin, ASource, [woRows, woSchema], -1);
@ -459,7 +465,7 @@ begin
else
begin
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);
end;