From a16ebef7f1351add6355078d8a74f879b5375229 Mon Sep 17 00:00:00 2001 From: roberto Date: Fri, 23 May 2008 14:43:59 +0000 Subject: [PATCH] Mejora de la funcion de copiar tablas para que se pueda elegir si copiar claves foraneas o no git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES2/trunk@222 f4e31baf-9722-1c47-927c-6f952f962d4b --- Source/Base/Base.dproj | 82 +++++++++++++------------- Source/Base/Utiles/uDataTableUtils.pas | 52 +++++++++++----- 2 files changed, 77 insertions(+), 57 deletions(-) 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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
fConfigurarConexion
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;