From 1c1a3c3d6d5e486436d6def1daddb164c8603672 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 20 Dec 2007 20:32:57 +0000 Subject: [PATCH] =?UTF-8?q?-=20Nueva=20funci=C3=B3n=20'LocalizarPosicion'?= =?UTF-8?q?=20en=20el=20controlador=20de=20detalles=20base=20(2=C2=BA=20in?= =?UTF-8?q?tento=20de=20subida).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@190 0c75b7a4-871f-7646-8a2f-f78d34cc349f --- .../Controladores/uControllerDetallesBase.pas | 72 +++++++++++++------ 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/Source/Base/Controladores/uControllerDetallesBase.pas b/Source/Base/Controladores/uControllerDetallesBase.pas index 1c415a07..45e5df75 100644 --- a/Source/Base/Controladores/uControllerDetallesBase.pas +++ b/Source/Base/Controladores/uControllerDetallesBase.pas @@ -9,7 +9,7 @@ const TIPO_DETALLE_TITULO = 'Titulo'; TIPO_DETALLE_SUBTOTAL = 'Subtotal'; TIPO_DETALLE_SALTO = 'Salto'; - TIPO_DETALLE_DESCUENTO = 'Descuento'; + TIPO_DETALLE_DESCUENTO = 'Descuento'; CTE_DESC_SALTO = 'SALTO DE PAGINA >>'; @@ -30,7 +30,7 @@ type procedure ActualizarTotales(ADataTable: IDAStronglyTypedDataTable); function DarTotalImporteTotal(ADataTable: IDAStronglyTypedDataTable): Double; - + function LocalizarPosicion(ADataTable: IDAStronglyTypedDataTable; const APosicion: Integer): Boolean; function DarListaTiposDetalle: TStringList; end; @@ -82,6 +82,7 @@ type procedure ActualizarTotales(ADataTable: IDAStronglyTypedDataTable); function DarTotalImporteTotal(ADataTable: IDAStronglyTypedDataTable): Double; function DarListaTiposDetalle: TStringList; virtual; + function LocalizarPosicion(ADataTable: IDAStronglyTypedDataTable; const APosicion: Integer): Boolean; end; @@ -89,7 +90,8 @@ implementation { TControllerDetallesBase } -uses cxControls, SysUtils, DB, uDAInterfaces; +uses + cxControls, SysUtils, DB, uDAInterfaces, Dialogs; procedure TControllerDetallesBase.ActualizarTotales(ADataTable: IDAStronglyTypedDataTable); begin @@ -153,6 +155,7 @@ begin ValidarCampos(DataTable); DataTable.DisableControls; + AuxPosicionIni := DataTable.FieldByName(CAMPO_POSICION).AsInteger; AuxPosicion := 0; AuxImporteAcumulado := 0; @@ -160,7 +163,7 @@ begin try DataTable.First; - while DataTable.Locate(CAMPO_POSICION, IntToStr(AuxPosicion), []) do + while DataTable.Locate(CAMPO_POSICION, AuxPosicion, []) do begin //SALTOS DE LINEA if (DataTable.FieldByName(CAMPO_TIPO).AsString = TIPO_DETALLE_SALTO) then @@ -206,7 +209,7 @@ begin finally //Dejamos el puntero en la misma posición que la que partió - DataTable.Locate(CAMPO_POSICION, IntToStr(AuxPosicionIni), []); + DataTable.Locate(CAMPO_POSICION, AuxPosicionIni, []); DataTable.EnableControls; end; @@ -284,14 +287,14 @@ end; function TControllerDetallesBase.DarListaTiposDetalle: TStringList; begin Result := TStringList.Create; - Result.Values[TIPO_DETALLE_CONCEPTO] := 'Concepto'; - Result.Values[TIPO_DETALLE_TITULO] := 'Título de capítulo'; - Result.Values[TIPO_DETALLE_SUBTOTAL] := 'Final de capítulo'; - Result.Values[TIPO_DETALLE_DESCUENTO] := 'Descuento de capítulo'; - Result.Values[TIPO_DETALLE_SALTO] := 'Salto de página'; + Result.Values[TIPO_DETALLE_CONCEPTO] := TIPO_DETALLE_CONCEPTO; + Result.Values[TIPO_DETALLE_TITULO] := TIPO_DETALLE_TITULO; + Result.Values[TIPO_DETALLE_SUBTOTAL] := TIPO_DETALLE_SUBTOTAL; + Result.Values[TIPO_DETALLE_DESCUENTO] := TIPO_DETALLE_DESCUENTO; + Result.Values[TIPO_DETALLE_SALTO] := TIPO_DETALLE_SALTO; end; -function TControllerDetallesBase.darTotalImporteTotal(ADataTable: IDAStronglyTypedDataTable): Double; +function TControllerDetallesBase.DarTotalImporteTotal(ADataTable: IDAStronglyTypedDataTable): Double; begin Result := CalcularTotales(False, ADataTable.DataTable); end; @@ -315,7 +318,7 @@ begin begin DataTable.First; DeletePosicion := POSICION[i]; - if DataTable.Locate(CAMPO_POSICION, IntToStr(DeletePosicion), []) then + if DataTable.Locate(CAMPO_POSICION, DeletePosicion, []) then DataTable.Delete; end; Renumerar(DataTable, DeletePosicion); @@ -402,12 +405,12 @@ begin posIni := DataTable.FieldByName(CAMPO_POSICION).AsInteger; DataTable.First; - if DataTable.Locate(CAMPO_POSICION, IntToStr(pPosicion), []) then + if DataTable.Locate(CAMPO_POSICION, pPosicion, []) then Result := DataTable.FieldByName(CAMPO_TIPO).AsString; //Volvemos a posicionar el puntero donde estaba DataTable.First; - if not DataTable.Locate(CAMPO_POSICION, IntToStr(posIni), []) then + if not DataTable.Locate(CAMPO_POSICION, posIni, []) then raise Exception.Create('La posición ' + IntToStr(posIni) + ' no existe (getTipo)'); end; finally @@ -415,6 +418,32 @@ begin end; end; +function TControllerDetallesBase.LocalizarPosicion( + ADataTable: IDAStronglyTypedDataTable; const APosicion: Integer): Boolean; +var + AField: TDAField; +begin + AField := ADataTable.DataTable.FindField(CAMPO_POSICION); + + if not Assigned(AField) then + raise Exception.Create('Campo ' + CAMPO_POSICION + ' no encontrado (LocalizarPosicion)'); + + with ADataTable.DataTable do + begin + DisableControls; + DisableEventHandlers; + ShowHourglassCursor; + try + First; + Result := Locate(CAMPO_POSICION, APosicion, []); + finally + HideHourglassCursor; + EnableEventHandlers; + EnableControls; + end; + end; +end; + procedure TControllerDetallesBase.Move(ADataTable: IDAStronglyTypedDataTable; Posicion: TIntegerArray; Posiciones: Integer); var i:Integer; @@ -458,7 +487,7 @@ begin //Buscamos el elemento con la posicion pasada por parametro DataTable.First; - if not DataTable.Locate(CAMPO_POSICION, IntToStr(Posicion), []) then + if not DataTable.Locate(CAMPO_POSICION, Posicion, []) then raise Exception.Create('Error, no se ha encontrado la POSICION [' + IntToStr(Posicion) + '] (mover)'); //Guardamos el id del elemento a cambiar de posicion y calculamos su nueva posicion @@ -466,14 +495,14 @@ begin AuxOrden := Posicion + NumPosiciones; DataTable.First; - if DataTable.Locate(CAMPO_POSICION, IntToStr(AuxOrden), []) then + if DataTable.Locate(CAMPO_POSICION, AuxOrden, []) then begin if not DataTable.Editing then DataTable.Edit; DataTable.FieldByName(CAMPO_POSICION).AsInteger := DataTable.FieldByName(CAMPO_POSICION).AsInteger - NumPosiciones; //Se hace dentro por si es el ultimo o el primero DataTable.First; - if not DataTable.Locate(CAMPO_ID, IntToStr(AuxID), []) then + if not DataTable.Locate(CAMPO_ID, AuxID, []) then raise Exception.Create('Error, no se ha encontrado el ID [' + IntToStr(AuxID) + '] (mover)'); if not DataTable.Editing then DataTable.Edit; @@ -484,7 +513,7 @@ begin //Colocamos el puntero en la posición en la que estaba DataTable.First; - DataTable.Locate(CAMPO_ID, IntToStr(AuxID), []); + DataTable.Locate(CAMPO_ID, AuxID, []); end; procedure TControllerDetallesBase.Renumerar(DataTable: TDADataTable; LocalizaPosicion: Integer); @@ -496,6 +525,7 @@ var AField: TDAField; begin AField := DataTable.FindField(CAMPO_POSICION); + if not Assigned(AField) then raise Exception.Create('Campo ' + CAMPO_POSICION + ' no encontrado (renumerar)'); @@ -504,11 +534,11 @@ begin for i:=0 to RecordCount-1 do begin First; - if not Locate(CAMPO_POSICION, IntToStr(i), []) then + if not Locate(CAMPO_POSICION, i, []) then begin j := i; First; - while not Locate(CAMPO_POSICION, IntToStr(j), []) do + while not Locate(CAMPO_POSICION, j, []) do begin Inc(j); First; @@ -521,7 +551,7 @@ begin end; //Posicionamos el puntero en la posición dada por parametro - if Locate(CAMPO_POSICION, IntToStr(LocalizaPosicion), []) then + Locate(CAMPO_POSICION, LocalizaPosicion, []); end; end;