diff --git a/Source/Base/Base.dproj b/Source/Base/Base.dproj
index 1526858a..e5d79e49 100644
--- a/Source/Base/Base.dproj
+++ b/Source/Base/Base.dproj
@@ -58,47 +58,47 @@
MainSource
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/Base/Utiles/uDataTableUtils.pas b/Source/Base/Utiles/uDataTableUtils.pas
index a4ed8d0f..5e15e680 100644
--- a/Source/Base/Utiles/uDataTableUtils.pas
+++ b/Source/Base/Utiles/uDataTableUtils.pas
@@ -34,10 +34,10 @@ function CloneDataTable(const ASource : TDAMemDataTable;
procedure DuplicarRegistro(ASource : TDADataTable; ATarget : TDADataTable;
- Const WithKey: Boolean = False);
+ Const WithPKKey: Boolean = False; Const WithFKKey: Boolean = False);
procedure DuplicarRegistros(ASource : TDADataTable; ATarget : TDADataTable;
AModo : TModoDuplicarRegistros; APermitirRepetidos: Boolean = True;
- Const WithDeltas: Boolean = True; Const WithKey: Boolean = False);
+ Const WithDeltas: Boolean = True; Const WithPKKey: Boolean = False; Const WithFKKey: Boolean = False);
procedure DeleteAllTable(const ADataTable : TDADataTable);
@@ -511,7 +511,7 @@ begin
end;
end;
-procedure DuplicarRegistro(ASource : TDADataTable; ATarget : TDADataTable; Const WithKey: Boolean = False);
+procedure DuplicarRegistro(ASource : TDADataTable; ATarget : TDADataTable; Const WithPKKey: Boolean = False; Const WithFKKey: Boolean = False);
var
i, j: Integer;
ATargetField: TDAField;
@@ -529,7 +529,7 @@ begin
begin
case ATarget.MasterMappingMode of
//mmDataRequest: //Sin hacer;
- mmParams, mmWhere: begin
+ mmParams, mmWhere: begin
//Creamos la lista de campos foreing key
ADetailFields := TStringList.Create;
ADetailFields.Sorted := True;
@@ -558,19 +558,39 @@ begin
// Los campos AutoInc no se rellenan y tampoco los campos que
// formen parte de la relación maestro-detalle en el
// caso de que la tabla destino sea una tabla detalle.
- if not WithKey then
+ if not WithPKKey then
begin
//Si no es campo clave
- if not (ATargetField.InPrimaryKey) and
//Si no es autoinc (podria desaparecer pero no lo quitamos por si acaso
- (ATargetField.DataType <> datAutoInc) and
- //Si no hay campos foreing key o los hay pero el campo a copiar no es uno de ellos
- (not Assigned(ADetailFields) or not ADetailFields.Find(ATargetField.Name, j)) then
- //Copiamos el campo
- ATargetField.Value := ASourceField.Value;
+ if not (ATargetField.InPrimaryKey)
+ and (ATargetField.DataType <> datAutoInc) then
+ begin
+ //En el caso de no copiar las claves foraneas
+ //Si no hay campos foreing key o los hay pero el campo a copiar no es uno de ellos
+ if not WithFKKey then
+ begin
+ if (not Assigned(ADetailFields) or not ADetailFields.Find(ATargetField.Name, j)) then
+ //Copiamos el campo
+ ATargetField.Value := ASourceField.Value;
+ end
+ else
+ //Copiamos el campo
+ ATargetField.Value := ASourceField.Value;
+ end;
end
else
- ATargetField.Value := ASourceField.Value;
+ //En el caso de no copiar las claves foraneas
+ //Si no hay campos foreing key o los hay pero el campo a copiar no es uno de ellos
+ if not WithFKKey then
+ begin
+ //Si no hay campos foreing key o los hay pero el campo a copiar no es uno de ellos
+ if (not Assigned(ADetailFields) or not ADetailFields.Find(ATargetField.Name, j)) then
+ //Copiamos el campo
+ ATargetField.Value := ASourceField.Value;
+ end
+ else
+ //Copiamos el campo
+ ATargetField.Value := ASourceField.Value;
end;
end;
finally
@@ -582,7 +602,7 @@ end;
procedure DuplicarRegistros(ASource : TDADataTable; ATarget : TDADataTable;
AModo : TModoDuplicarRegistros; APermitirRepetidos: Boolean = True;
- Const WithDeltas: Boolean = True; Const WithKey: Boolean = False);
+ Const WithDeltas: Boolean = True; Const WithPKKey: Boolean = False; Const WithFKKey: Boolean = False);
begin
if not ASource.Active then
ASource.Open;
@@ -596,18 +616,18 @@ begin
DesconectarTabla(ATarget);
if AModo = mdrActual then
- DuplicarRegistro(ASource, ATarget, WithKey) //ATarget.CloneSelectedRecord(ASource, True)
+ DuplicarRegistro(ASource, ATarget, WithPKKey, WithFKKey) //ATarget.CloneSelectedRecord(ASource, True)
else begin
ASource.First;
while not ASource.EOF do
begin
if APermitirRepetidos then
- DuplicarRegistro(ASource, ATarget, WithKey)
+ DuplicarRegistro(ASource, ATarget, WithPKKey, WithFKKey)
else
begin
ATarget.First;
if not ATarget.Locate('ID', ASource.FieldByName('ID').AsVariant, []) then
- DuplicarRegistro(ASource, ATarget, WithKey);
+ DuplicarRegistro(ASource, ATarget, WithPKKey, WithFKKey);
end;
ASource.Next;