- Nueva función 'LocalizarPosicion' en el controlador de detalles base (2º intento de subida).

git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@190 0c75b7a4-871f-7646-8a2f-f78d34cc349f
This commit is contained in:
David Arranz 2007-12-20 20:32:57 +00:00
parent 724b8806d6
commit 1c1a3c3d6d

View File

@ -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;